From e3bacbe4a034fe0a70ea3b8544fd79b113c9f308 Mon Sep 17 00:00:00 2001 From: Iman Tabrizian Date: Thu, 4 May 2023 17:22:03 -0400 Subject: [PATCH 1/3] Add BasicAuth plugin --- src/python/library/build_wheel.py | 2 + .../library/tritonclient/CMakeLists.txt | 1 + src/python/library/tritonclient/_auth.py | 40 +++++++++++++++++++ .../library/tritonclient/grpc/aio/__init__.py | 1 + .../tritonclient/grpc/aio/auth/__init__.py | 27 +++++++++++++ .../tritonclient/http/aio/auth/__init__.py | 27 +++++++++++++ .../tritonclient/http/auth/__init__.py | 27 +++++++++++++ 7 files changed, 125 insertions(+) create mode 100644 src/python/library/tritonclient/_auth.py create mode 100644 src/python/library/tritonclient/grpc/aio/auth/__init__.py create mode 100644 src/python/library/tritonclient/http/aio/auth/__init__.py create mode 100644 src/python/library/tritonclient/http/auth/__init__.py diff --git a/src/python/library/build_wheel.py b/src/python/library/build_wheel.py index c4cb02e11..8a529177c 100644 --- a/src/python/library/build_wheel.py +++ b/src/python/library/build_wheel.py @@ -111,6 +111,8 @@ def sed(pattern, replace, source, dest=None): os.path.join(FLAGS.whl_dir, 'tritonclient')) shutil.copy('tritonclient/_request.py', os.path.join(FLAGS.whl_dir, 'tritonclient')) + shutil.copy('tritonclient/_auth.py', + os.path.join(FLAGS.whl_dir, 'tritonclient')) # Needed for backwards-compatibility; remove when moving # completely to the new structure. diff --git a/src/python/library/tritonclient/CMakeLists.txt b/src/python/library/tritonclient/CMakeLists.txt index 7b20d7ae0..21263b6e9 100644 --- a/src/python/library/tritonclient/CMakeLists.txt +++ b/src/python/library/tritonclient/CMakeLists.txt @@ -38,5 +38,6 @@ file(COPY _client.py DESTINATION .) file(COPY _plugin.py DESTINATION .) file(COPY __init__.py DESTINATION .) file(COPY _request.py DESTINATION .) +file(COPY _auth.py DESTINATION .) add_subdirectory(utils) diff --git a/src/python/library/tritonclient/_auth.py b/src/python/library/tritonclient/_auth.py new file mode 100644 index 000000000..525dfc6ef --- /dev/null +++ b/src/python/library/tritonclient/_auth.py @@ -0,0 +1,40 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from ._plugin import InferenceServerClientPlugin +import base64 + + +class BasicAuth(InferenceServerClientPlugin): + """Basic Authentincation Plugin.""" + + def __init__(self, username, password): + username = username.encode('ascii') + password = password.encode('ascii') + self._auth_string = "Basic " + base64.b64encode(b":".join( + (username, password))).decode('ascii').strip() + + def __call__(self, request): + request.headers['Authorization'] = self._auth_string diff --git a/src/python/library/tritonclient/grpc/aio/__init__.py b/src/python/library/tritonclient/grpc/aio/__init__.py index b4a8567fd..41c8b9136 100644 --- a/src/python/library/tritonclient/grpc/aio/__init__.py +++ b/src/python/library/tritonclient/grpc/aio/__init__.py @@ -30,6 +30,7 @@ from ..._client import InferenceServerClientBase from ..._request import Request from ..._plugin import InferenceServerClientPlugin +from ... import _auth as auth class InferenceServerClient(InferenceServerClientBase): diff --git a/src/python/library/tritonclient/grpc/aio/auth/__init__.py b/src/python/library/tritonclient/grpc/aio/auth/__init__.py new file mode 100644 index 000000000..40004b1a7 --- /dev/null +++ b/src/python/library/tritonclient/grpc/aio/auth/__init__.py @@ -0,0 +1,27 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from ...._auth import BasicAuth \ No newline at end of file diff --git a/src/python/library/tritonclient/http/aio/auth/__init__.py b/src/python/library/tritonclient/http/aio/auth/__init__.py new file mode 100644 index 000000000..40004b1a7 --- /dev/null +++ b/src/python/library/tritonclient/http/aio/auth/__init__.py @@ -0,0 +1,27 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from ...._auth import BasicAuth \ No newline at end of file diff --git a/src/python/library/tritonclient/http/auth/__init__.py b/src/python/library/tritonclient/http/auth/__init__.py new file mode 100644 index 000000000..a69649620 --- /dev/null +++ b/src/python/library/tritonclient/http/auth/__init__.py @@ -0,0 +1,27 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from ..._auth import BasicAuth \ No newline at end of file From d3969a20845963e34fdd279229a1e73d46cc2189 Mon Sep 17 00:00:00 2001 From: Iman Tabrizian Date: Thu, 4 May 2023 20:46:32 -0400 Subject: [PATCH 2/3] Add basic auth support to HTTP/GRPC plugins --- src/python/library/tritonclient/_auth.py | 7 ++-- .../library/tritonclient/grpc/aio/__init__.py | 5 +-- .../tritonclient/grpc/aio/auth/__init__.py | 2 +- .../tritonclient/grpc/auth/__init__.py | 27 +++++++++++++++ .../tritonclient/grpc/auth/_basic_auth.py | 33 +++++++++++++++++++ .../tritonclient/http/aio/auth/__init__.py | 2 +- .../tritonclient/http/auth/__init__.py | 2 +- .../tritonclient/http/auth/_basic_auth.py | 32 ++++++++++++++++++ 8 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 src/python/library/tritonclient/grpc/auth/__init__.py create mode 100644 src/python/library/tritonclient/grpc/auth/_basic_auth.py create mode 100644 src/python/library/tritonclient/http/auth/_basic_auth.py diff --git a/src/python/library/tritonclient/_auth.py b/src/python/library/tritonclient/_auth.py index 525dfc6ef..0e2dd7aee 100644 --- a/src/python/library/tritonclient/_auth.py +++ b/src/python/library/tritonclient/_auth.py @@ -27,14 +27,15 @@ import base64 -class BasicAuth(InferenceServerClientPlugin): +class _BasicAuthBase(InferenceServerClientPlugin): """Basic Authentincation Plugin.""" - def __init__(self, username, password): + def __init__(self, header_name, username, password): username = username.encode('ascii') password = password.encode('ascii') + self._header_name = header_name self._auth_string = "Basic " + base64.b64encode(b":".join( (username, password))).decode('ascii').strip() def __call__(self, request): - request.headers['Authorization'] = self._auth_string + request.headers[self._header_name] = self._auth_string diff --git a/src/python/library/tritonclient/grpc/aio/__init__.py b/src/python/library/tritonclient/grpc/aio/__init__.py index 41c8b9136..aa54f8f77 100644 --- a/src/python/library/tritonclient/grpc/aio/__init__.py +++ b/src/python/library/tritonclient/grpc/aio/__init__.py @@ -129,10 +129,7 @@ async def is_server_live(self, headers=None): """Refer to tritonclient.grpc.InferenceServerClient """ - if headers is not None: - metadata = headers.items() - else: - metadata = () + metadata = self._get_metadata(headers) try: request = service_pb2.ServerLiveRequest() if self._verbose: diff --git a/src/python/library/tritonclient/grpc/aio/auth/__init__.py b/src/python/library/tritonclient/grpc/aio/auth/__init__.py index 40004b1a7..ab0ed32b8 100644 --- a/src/python/library/tritonclient/grpc/aio/auth/__init__.py +++ b/src/python/library/tritonclient/grpc/aio/auth/__init__.py @@ -24,4 +24,4 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ...._auth import BasicAuth \ No newline at end of file +from ...auth import BasicAuth diff --git a/src/python/library/tritonclient/grpc/auth/__init__.py b/src/python/library/tritonclient/grpc/auth/__init__.py new file mode 100644 index 000000000..bba1fa25e --- /dev/null +++ b/src/python/library/tritonclient/grpc/auth/__init__.py @@ -0,0 +1,27 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from ._basic_auth import BasicAuth diff --git a/src/python/library/tritonclient/grpc/auth/_basic_auth.py b/src/python/library/tritonclient/grpc/auth/_basic_auth.py new file mode 100644 index 000000000..74b9beb92 --- /dev/null +++ b/src/python/library/tritonclient/grpc/auth/_basic_auth.py @@ -0,0 +1,33 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from ..._auth import _BasicAuthBase + + +class BasicAuth(_BasicAuthBase): + + def __init__(self, username, password): + # GRPC uses lower-case headers + super().__init__('authorization', username, password) diff --git a/src/python/library/tritonclient/http/aio/auth/__init__.py b/src/python/library/tritonclient/http/aio/auth/__init__.py index 40004b1a7..ab0ed32b8 100644 --- a/src/python/library/tritonclient/http/aio/auth/__init__.py +++ b/src/python/library/tritonclient/http/aio/auth/__init__.py @@ -24,4 +24,4 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ...._auth import BasicAuth \ No newline at end of file +from ...auth import BasicAuth diff --git a/src/python/library/tritonclient/http/auth/__init__.py b/src/python/library/tritonclient/http/auth/__init__.py index a69649620..bba1fa25e 100644 --- a/src/python/library/tritonclient/http/auth/__init__.py +++ b/src/python/library/tritonclient/http/auth/__init__.py @@ -24,4 +24,4 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ..._auth import BasicAuth \ No newline at end of file +from ._basic_auth import BasicAuth diff --git a/src/python/library/tritonclient/http/auth/_basic_auth.py b/src/python/library/tritonclient/http/auth/_basic_auth.py new file mode 100644 index 000000000..2d7172c8f --- /dev/null +++ b/src/python/library/tritonclient/http/auth/_basic_auth.py @@ -0,0 +1,32 @@ +# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from ..._auth import _BasicAuthBase + + +class BasicAuth(_BasicAuthBase): + + def __init__(self, username, password): + super().__init__('Authorization', username, password) From 5da1765097bcc44e6e3c7d232d1381c3f38b9659 Mon Sep 17 00:00:00 2001 From: Iman Tabrizian Date: Fri, 5 May 2023 17:55:07 -0400 Subject: [PATCH 3/3] Review comment --- .../library/tritonclient/CMakeLists.txt | 2 +- src/python/library/tritonclient/_auth.py | 7 ++-- .../tritonclient/grpc/auth/__init__.py | 2 +- .../tritonclient/grpc/auth/_basic_auth.py | 33 ------------------- .../tritonclient/http/aio/auth/__init__.py | 2 +- .../tritonclient/http/auth/__init__.py | 2 +- .../tritonclient/http/auth/_basic_auth.py | 32 ------------------ 7 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 src/python/library/tritonclient/grpc/auth/_basic_auth.py delete mode 100644 src/python/library/tritonclient/http/auth/_basic_auth.py diff --git a/src/python/library/tritonclient/CMakeLists.txt b/src/python/library/tritonclient/CMakeLists.txt index 21263b6e9..9a9fdbed4 100644 --- a/src/python/library/tritonclient/CMakeLists.txt +++ b/src/python/library/tritonclient/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions diff --git a/src/python/library/tritonclient/_auth.py b/src/python/library/tritonclient/_auth.py index 0e2dd7aee..ec5391126 100644 --- a/src/python/library/tritonclient/_auth.py +++ b/src/python/library/tritonclient/_auth.py @@ -27,15 +27,14 @@ import base64 -class _BasicAuthBase(InferenceServerClientPlugin): +class BasicAuth(InferenceServerClientPlugin): """Basic Authentincation Plugin.""" - def __init__(self, header_name, username, password): + def __init__(self, username, password): username = username.encode('ascii') password = password.encode('ascii') - self._header_name = header_name self._auth_string = "Basic " + base64.b64encode(b":".join( (username, password))).decode('ascii').strip() def __call__(self, request): - request.headers[self._header_name] = self._auth_string + request.headers['authorization'] = self._auth_string diff --git a/src/python/library/tritonclient/grpc/auth/__init__.py b/src/python/library/tritonclient/grpc/auth/__init__.py index bba1fa25e..8ae240938 100644 --- a/src/python/library/tritonclient/grpc/auth/__init__.py +++ b/src/python/library/tritonclient/grpc/auth/__init__.py @@ -24,4 +24,4 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ._basic_auth import BasicAuth +from ..._auth import BasicAuth diff --git a/src/python/library/tritonclient/grpc/auth/_basic_auth.py b/src/python/library/tritonclient/grpc/auth/_basic_auth.py deleted file mode 100644 index 74b9beb92..000000000 --- a/src/python/library/tritonclient/grpc/auth/_basic_auth.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of NVIDIA CORPORATION nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ..._auth import _BasicAuthBase - - -class BasicAuth(_BasicAuthBase): - - def __init__(self, username, password): - # GRPC uses lower-case headers - super().__init__('authorization', username, password) diff --git a/src/python/library/tritonclient/http/aio/auth/__init__.py b/src/python/library/tritonclient/http/aio/auth/__init__.py index ab0ed32b8..687398f45 100644 --- a/src/python/library/tritonclient/http/aio/auth/__init__.py +++ b/src/python/library/tritonclient/http/aio/auth/__init__.py @@ -24,4 +24,4 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ...auth import BasicAuth +from ...._auth import BasicAuth diff --git a/src/python/library/tritonclient/http/auth/__init__.py b/src/python/library/tritonclient/http/auth/__init__.py index bba1fa25e..8ae240938 100644 --- a/src/python/library/tritonclient/http/auth/__init__.py +++ b/src/python/library/tritonclient/http/auth/__init__.py @@ -24,4 +24,4 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ._basic_auth import BasicAuth +from ..._auth import BasicAuth diff --git a/src/python/library/tritonclient/http/auth/_basic_auth.py b/src/python/library/tritonclient/http/auth/_basic_auth.py deleted file mode 100644 index 2d7172c8f..000000000 --- a/src/python/library/tritonclient/http/auth/_basic_auth.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of NVIDIA CORPORATION nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ..._auth import _BasicAuthBase - - -class BasicAuth(_BasicAuthBase): - - def __init__(self, username, password): - super().__init__('Authorization', username, password)