From 5e97e7026ebb0819ca79352bcdab384d19950c62 Mon Sep 17 00:00:00 2001 From: Sergey Machulskis Date: Sat, 30 Sep 2023 12:43:41 +0700 Subject: [PATCH 1/2] Update config interface --- cybsi/cloud/client.py | 3 +-- cybsi/cloud/client_config.py | 23 ++++++++++++++-------- examples/add_collection_object.py | 6 +----- examples/add_collection_object_async.py | 5 +---- examples/auth_api_keys_chained.py | 6 +----- examples/auth_generate_api_key.py | 5 +---- examples/auth_resources_chained.py | 6 +----- examples/client_advanced_config.py | 8 +------- examples/delete_collection_object.py | 6 +----- examples/get_collection_objects_chained.py | 6 +----- examples/get_collection_objects_changes.py | 5 +---- examples/pagination_manual.py | 5 +---- examples/push_collection_objects.py | 5 +---- examples/register_object_schema.py | 5 +---- 14 files changed, 28 insertions(+), 66 deletions(-) diff --git a/cybsi/cloud/client.py b/cybsi/cloud/client.py index 892837a..aa0b1a3 100644 --- a/cybsi/cloud/client.py +++ b/cybsi/cloud/client.py @@ -31,9 +31,8 @@ class Client: config: Client config. Usage: >>> from cybsi.cloud import Config, Client - >>> api_url = "https://cybsi.cloud/" >>> api_key = "8Nqjk6V4Q_et_Rf5EPu4SeWy4nKbVPKPzKJESYdRd7E" - >>> config = Config(api_url, api_key) + >>> config = Config(api_key) >>> client = Client(config) >>> >>> collections = client.iocean.collections.filter() diff --git a/cybsi/cloud/client_config.py b/cybsi/cloud/client_config.py index 8f68bfe..86d4678 100644 --- a/cybsi/cloud/client_config.py +++ b/cybsi/cloud/client_config.py @@ -1,4 +1,3 @@ -from dataclasses import dataclass from typing import Optional, Union import httpx @@ -131,13 +130,12 @@ def _as_httpx_timeouts(self) -> httpx.Timeout: DEFAULT_LIMITS = Limits(max_connections=100, max_keepalive_connections=20) -@dataclass class Config: """:class:`Client` config. Args: - api_url: Base API URL. api_key: Cybsi Cloud API key. + api_url: Base API URL. ssl_verify: Enable SSL certificate verification. timeouts: Timeout configuration. Default configuration is 60 sec on all operations. @@ -145,8 +143,17 @@ class Config: Default configuration is max_connections=100, max_keepalive_connections=20. """ - api_url: str - api_key: str - ssl_verify: bool = True - timeouts: Timeouts = DEFAULT_TIMEOUTS - limits: Limits = DEFAULT_LIMITS + def __init__( + self, + *, + api_key: str, + api_url: str = "https://cybsi.cloud", + ssl_verify: bool = True, + timeouts: Timeouts = DEFAULT_TIMEOUTS, + limits: Limits = DEFAULT_LIMITS, + ): + self.api_key = api_key + self.api_url = api_url + self.ssl_verify = ssl_verify + self.timeouts = timeouts + self.limits = limits diff --git a/examples/add_collection_object.py b/examples/add_collection_object.py index 8c808e6..0bfa24f 100644 --- a/examples/add_collection_object.py +++ b/examples/add_collection_object.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 -import os - from cybsi.cloud import Client, Config from cybsi.cloud.error import ( ConflictError, @@ -11,9 +9,7 @@ from cybsi.cloud.iocean.objects import ObjectKeyType, ObjectType if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") client = Client(config) collection_id = "example-collection" diff --git a/examples/add_collection_object_async.py b/examples/add_collection_object_async.py index 6c41805..deab7c5 100644 --- a/examples/add_collection_object_async.py +++ b/examples/add_collection_object_async.py @@ -1,15 +1,12 @@ #!/usr/bin/env python3 import asyncio -import os from cybsi.cloud import AsyncClient, Config from cybsi.cloud.iocean.objects import ObjectKeyType, ObjectType async def main(): - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") collection_id = "example-collection" object_files = ( diff --git a/examples/auth_api_keys_chained.py b/examples/auth_api_keys_chained.py index db8afe4..e1f741a 100644 --- a/examples/auth_api_keys_chained.py +++ b/examples/auth_api_keys_chained.py @@ -1,13 +1,9 @@ #!/usr/bin/env python3 -import os - from cybsi.cloud import Client, Config from cybsi.cloud.pagination import chain_pages if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") with Client(config) as client: start_page = client.auth.api_keys.filter() diff --git a/examples/auth_generate_api_key.py b/examples/auth_generate_api_key.py index c5ec0b3..6d02ab3 100644 --- a/examples/auth_generate_api_key.py +++ b/examples/auth_generate_api_key.py @@ -1,14 +1,11 @@ #!/usr/bin/env python3 -import os from datetime import datetime, timedelta from cybsi.cloud import Client, Config from cybsi.cloud.auth import APIKeyForm, ResourceAction, ResourcePermissionForm if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") with Client(config) as client: permissions = [ diff --git a/examples/auth_resources_chained.py b/examples/auth_resources_chained.py index 3990895..bfae630 100644 --- a/examples/auth_resources_chained.py +++ b/examples/auth_resources_chained.py @@ -1,13 +1,9 @@ #!/usr/bin/env python3 -import os - from cybsi.cloud import Client, Config from cybsi.cloud.pagination import chain_pages if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") with Client(config) as client: start_page = client.auth.resources.filter() diff --git a/examples/client_advanced_config.py b/examples/client_advanced_config.py index aee758d..e5c35f3 100644 --- a/examples/client_advanced_config.py +++ b/examples/client_advanced_config.py @@ -1,17 +1,11 @@ -import os - from cybsi.cloud import Client, Config, Limits, Timeouts if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - # Set custom timeouts and limits of HTTP client limits = Limits(max_connections=100, max_keepalive_connections=20) timeouts = Timeouts(default=3.0) - config = Config( - api_url, api_key, ssl_verify=False, timeouts=timeouts, limits=limits + api_key="the cryptic string", ssl_verify=False, timeouts=timeouts, limits=limits ) client = Client(config) # then use client as usual diff --git a/examples/delete_collection_object.py b/examples/delete_collection_object.py index 50fa569..fa1e073 100644 --- a/examples/delete_collection_object.py +++ b/examples/delete_collection_object.py @@ -1,13 +1,9 @@ #!/usr/bin/env python3 -import os - from cybsi.cloud import Client, Config from cybsi.cloud.iocean.objects import ObjectKeyType if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") client = Client(config) collection_id = "example-collection" diff --git a/examples/get_collection_objects_chained.py b/examples/get_collection_objects_chained.py index b650847..2463025 100644 --- a/examples/get_collection_objects_chained.py +++ b/examples/get_collection_objects_chained.py @@ -1,13 +1,9 @@ #!/usr/bin/env python3 -import os - from cybsi.cloud import Client, Config from cybsi.cloud.pagination import chain_pages if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") with Client(config) as client: collection_id = "example-collection" diff --git a/examples/get_collection_objects_changes.py b/examples/get_collection_objects_changes.py index c903f30..4353e16 100644 --- a/examples/get_collection_objects_changes.py +++ b/examples/get_collection_objects_changes.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import os import time from typing import Iterable, Optional @@ -9,9 +8,7 @@ def main(): - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") with Client(config) as client: collection_id = "example-collection" diff --git a/examples/pagination_manual.py b/examples/pagination_manual.py index 6041e45..b88bf1c 100644 --- a/examples/pagination_manual.py +++ b/examples/pagination_manual.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import os from typing import Optional from cybsi.cloud import Client, Config @@ -7,9 +6,7 @@ from cybsi.cloud.pagination import Page if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") with Client(config) as client: page: Optional[Page[CollectionCommonView]] = client.iocean.collections.filter() diff --git a/examples/push_collection_objects.py b/examples/push_collection_objects.py index 10fbf98..2c9e3fa 100644 --- a/examples/push_collection_objects.py +++ b/examples/push_collection_objects.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import asyncio -import os from hashlib import md5 from cybsi.cloud import AsyncClient, Config @@ -8,9 +7,7 @@ async def main(): - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") collection_id = "example-collection" async with AsyncClient(config) as client: diff --git a/examples/register_object_schema.py b/examples/register_object_schema.py index 3189bf9..3ba2842 100644 --- a/examples/register_object_schema.py +++ b/examples/register_object_schema.py @@ -1,14 +1,11 @@ #!/usr/bin/env python3 import json -import os from cybsi.cloud import Client, Config from cybsi.cloud.error import ConflictError if __name__ == "__main__": - api_url = os.environ.get("CLOUD_BASE_URL", "https://cybsi.cloud") - api_key = os.environ.get("CLOUD_API_KEY", "api_key") - config = Config(api_url, api_key) + config = Config(api_key="the cryptic string") client = Client(config) jsonSchema = """ From be689557eabe0e9a1ce046534d90f7a7aa557dfb Mon Sep 17 00:00:00 2001 From: Sergey Machulskis Date: Sat, 30 Sep 2023 12:44:38 +0700 Subject: [PATCH 2/2] Bump to 1.0.4 --- HISTORY.md | 4 ++++ cybsi/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 67d0454..54619dd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ Release History =============== +1.0.4 (2023-09-29) +------------------ + +- Simplify client configuration 1.0.3 (2023-09-27) ------------------ diff --git a/cybsi/__version__.py b/cybsi/__version__.py index 842f7e1..52f70fb 100644 --- a/cybsi/__version__.py +++ b/cybsi/__version__.py @@ -1,4 +1,4 @@ -__version__ = "1.0.3" +__version__ = "1.0.4" __title__ = "cybsi-cloud-sdk" __description__ = "Cybsi Cloud development kit" __license__ = "Apache License 2.0" diff --git a/pyproject.toml b/pyproject.toml index 90e77f9..88aa25e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cybsi-cloud-sdk" -version = "1.0.3" +version = "1.0.4" description = "Cybsi Cloud development kit" authors = ["Cybsi Cloud developers"] license = "Apache License 2.0" @@ -41,7 +41,7 @@ extend_skip = ["__init__.py"] [tool.tbump] [tool.tbump.version] -current = "1.0.3" +current = "1.0.4" regex = ''' ^