This is an automated email from the ASF dual-hosted git repository. bossenti pushed a commit to branch 1259-verify-authentication-on-startup-of-python-client in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 4067743d4ffccd1d46f52b55362f2755773e8428 Author: bossenti <[email protected]> AuthorDate: Mon Feb 27 21:47:07 2023 +0100 feature(#1259): implement version endpoint Signed-off-by: bossenti <[email protected]> --- streampipes-client-python/setup.py | 2 +- .../streampipes/client/client.py | 7 +- .../streampipes/endpoint/api/__init__.py | 2 + .../streampipes/endpoint/api/version.py | 130 +++++++++++++++++++++ .../streampipes/model/container/__init__.py | 2 + .../streampipes/model/container/versions.py | 55 +++++++++ .../streampipes/model/resource/__init__.py | 2 + .../model/resource/{__init__.py => version.py} | 33 ++++-- 8 files changed, 222 insertions(+), 11 deletions(-) diff --git a/streampipes-client-python/setup.py b/streampipes-client-python/setup.py index e135fd33f..cdfef0415 100644 --- a/streampipes-client-python/setup.py +++ b/streampipes-client-python/setup.py @@ -101,7 +101,7 @@ setuptools.setup( classifiers=[ # Trove classifiers # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Information Technology", diff --git a/streampipes-client-python/streampipes/client/client.py b/streampipes-client-python/streampipes/client/client.py index 471696c1d..65b972aff 100644 --- a/streampipes-client-python/streampipes/client/client.py +++ b/streampipes-client-python/streampipes/client/client.py @@ -29,7 +29,11 @@ from typing import Dict, Optional from requests import Session from streampipes.client.config import StreamPipesClientConfig -from streampipes.endpoint.api import DataLakeMeasureEndpoint, DataStreamEndpoint +from streampipes.endpoint.api import ( + DataLakeMeasureEndpoint, + DataStreamEndpoint, + VersionEndpoint, +) from streampipes.endpoint.endpoint import APIEndpoint logger = logging.getLogger(__name__) @@ -105,6 +109,7 @@ class StreamPipesClient: # name of the endpoint needs to be consistent with the Java client self.dataLakeMeasureApi = DataLakeMeasureEndpoint(parent_client=self) self.dataStreamApi = DataStreamEndpoint(parent_client=self) + self.versionApi = VersionEndpoint(parent_client=self) @staticmethod def _set_up_logging(logging_level: int) -> None: diff --git a/streampipes-client-python/streampipes/endpoint/api/__init__.py b/streampipes-client-python/streampipes/endpoint/api/__init__.py index 3d4e6e9cd..28bcf688a 100644 --- a/streampipes-client-python/streampipes/endpoint/api/__init__.py +++ b/streampipes-client-python/streampipes/endpoint/api/__init__.py @@ -17,8 +17,10 @@ from .data_lake_measure import DataLakeMeasureEndpoint from .data_stream import DataStreamEndpoint +from .version import VersionEndpoint __all__ = [ "DataLakeMeasureEndpoint", "DataStreamEndpoint", + "VersionEndpoint", ] diff --git a/streampipes-client-python/streampipes/endpoint/api/version.py b/streampipes-client-python/streampipes/endpoint/api/version.py new file mode 100644 index 000000000..aa1fe0cf3 --- /dev/null +++ b/streampipes-client-python/streampipes/endpoint/api/version.py @@ -0,0 +1,130 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +Specific implementation of the StreamPipes API's version endpoint. +""" + +__all__ = [ + "VersionEndpoint", +] + +from typing import Tuple, Type + +from streampipes.endpoint import APIEndpoint +from streampipes.model.container import Versions +from streampipes.model.container.resource_container import ResourceContainer +from streampipes.model.resource.resource import Resource + + +class VersionEndpoint(APIEndpoint): + """Implementation of the Versions endpoint. + + This endpoint provides metadata about the StreamPipes version of the connected instance. + It only allows to apply the `get()` method with an empty string as identifier. + + Parameters + ---------- + parent_client: StreamPipesClient + The instance of [StreamPipesClient][streampipes.client.StreamPipesClient] the endpoint is attached to. + + Examples + -------- + + >>> from streampipes.client import StreamPipesClient + >>> from streampipes.client.config import StreamPipesClientConfig + >>> from streampipes.client.credential_provider import StreamPipesApiKeyCredentials + + >>> client_config = StreamPipesClientConfig( + ... credential_provider=StreamPipesApiKeyCredentials(username="test-user", api_key="api-key"), + ... host_address="localhost", + ... port=8082, + ... https_disabled=True + ... ) + + >>> client = StreamPipesClient.create(client_config=client_config) + + >>> client.versionApi.get(identifier="").to_dict(use_source_names=False) + {'backend_version': '0.92.0-SNAPSHOT'} + """ + + @property + def _container_cls(self) -> Type[ResourceContainer]: + """Defines the model container class the endpoint refers to. + + Returns + ------- + [Versions][streampipes.model.container.Versions] + """ + + return Versions + + @property + def _relative_api_path(self) -> Tuple[str, ...]: + """Defines the relative api path to the DataStream endpoint. + + Each path within the URL is defined as an own string. + + Returns + ------- + api_path: Tuple[str, ...] + a tuple of strings of which every represents a path value of the endpoint's API URL. + """ + + return "api", "v2", "info", "versions" + + def all(self) -> ResourceContainer: + """Usually, this method returns information about all resources provided by this endpoint. + However, this endpoint does not support this kind of operation. + + Raises + ------ + NotImplementedError + this endpoint does not return multiple entries, therefore this method is not available + + """ + raise NotImplementedError("The `all()` method is not supported by this endpoint.") + + def get(self, identifier: str, **kwargs) -> Resource: + """Queries the resource from the API endpoint. + + For this endpoint only one resource is available. + + Parameters + ---------- + identifier: str + Not supported by this endpoint, is set to an empty string. + + Returns + ------- + versions: Version + The specified resource as an instance of the corresponding model class([Version][streampipes.model.resource.Version]). # noqa: 501 + """ + + return super().get(identifier="") + + def post(self, resource: Resource) -> None: + """Usually, this method allows to create via this endpoint. + Since the data represented by this endpoint is immutable, it does not support this kind of operation. + + Raises + ------ + NotImplementedError + this endpoint does not allow for POST requests, therefore this method is not available + + """ + raise NotImplementedError("The `post()` method is not supported by this endpoint.") diff --git a/streampipes-client-python/streampipes/model/container/__init__.py b/streampipes-client-python/streampipes/model/container/__init__.py index 53b0ded93..59d688ce8 100644 --- a/streampipes-client-python/streampipes/model/container/__init__.py +++ b/streampipes-client-python/streampipes/model/container/__init__.py @@ -17,8 +17,10 @@ from .data_lake_measures import DataLakeMeasures from .data_streams import DataStreams +from .versions import Versions __all__ = [ "DataLakeMeasures", "DataStreams", + "Versions", ] diff --git a/streampipes-client-python/streampipes/model/container/versions.py b/streampipes-client-python/streampipes/model/container/versions.py new file mode 100644 index 000000000..f2e952fb3 --- /dev/null +++ b/streampipes-client-python/streampipes/model/container/versions.py @@ -0,0 +1,55 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +""" +Implementation of a resource container for the versions endpoint. +""" + +__all__ = [ + "Versions", +] + +from typing import Type + +from streampipes.model.container.resource_container import ResourceContainer +from streampipes.model.resource import Version +from streampipes.model.resource.resource import Resource + + +class Versions(ResourceContainer): + """Implementation of the resource container for the versions endpoint. + + This resource container is a collection of versions returned by the StreamPipes API. + It is capable of parsing the response content directly into a list of queried `Version`. + Furthermore, the resource container makes them accessible in a pythonic manner. + + Parameters + ---------- + resources: List[Version] + A list of resources ([Version][streampipes.model.resource.Version]) to be contained in the `ResourceContainer`. + + """ + + @classmethod + def _resource_cls(cls) -> Type[Resource]: + """Returns the class of the resource that are bundled. + + Returns + ------- + [Version][streampipes.model.resource.Version] + """ + return Version diff --git a/streampipes-client-python/streampipes/model/resource/__init__.py b/streampipes-client-python/streampipes/model/resource/__init__.py index c6f0cddba..d0d2e0a5e 100644 --- a/streampipes-client-python/streampipes/model/resource/__init__.py +++ b/streampipes-client-python/streampipes/model/resource/__init__.py @@ -19,10 +19,12 @@ from .data_lake_measure import DataLakeMeasure from .data_lake_series import DataLakeSeries from .data_stream import DataStream from .function_definition import FunctionDefinition +from .version import Version __all__ = [ "DataLakeMeasure", "DataLakeSeries", "DataStream", "FunctionDefinition", + "Version", ] diff --git a/streampipes-client-python/streampipes/model/resource/__init__.py b/streampipes-client-python/streampipes/model/resource/version.py similarity index 55% copy from streampipes-client-python/streampipes/model/resource/__init__.py copy to streampipes-client-python/streampipes/model/resource/version.py index c6f0cddba..c0405caec 100644 --- a/streampipes-client-python/streampipes/model/resource/__init__.py +++ b/streampipes-client-python/streampipes/model/resource/version.py @@ -15,14 +15,29 @@ # limitations under the License. # -from .data_lake_measure import DataLakeMeasure -from .data_lake_series import DataLakeSeries -from .data_stream import DataStream -from .function_definition import FunctionDefinition - __all__ = [ - "DataLakeMeasure", - "DataLakeSeries", - "DataStream", - "FunctionDefinition", + "Version", ] + +from typing import Dict + +from pydantic import StrictStr +from streampipes.model.resource.resource import Resource + + +class Version(Resource): + """Metadata about the version of the connected StreamPipes server. + + Attributes + ---------- + backend_version: str + version of the StreamPipes backend the client is connected to + """ + + def convert_to_pandas_representation(self) -> Dict: + """Returns the dictionary representation of the version metadata + to be used when creating a pandas Dataframe. + """ + return self.to_dict(use_source_names=False) + + backend_version: StrictStr
