Skip to content

Commit

Permalink
Merge pull request #14 from cyberstudio/update-config-interface
Browse files Browse the repository at this point in the history
Update config interface
  • Loading branch information
neexee authored Sep 30, 2023
2 parents 31b872d + be68955 commit ad5f006
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 69 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release History
===============
1.0.4 (2023-09-29)
------------------

- Simplify client configuration

1.0.3 (2023-09-27)
------------------
Expand Down
2 changes: 1 addition & 1 deletion cybsi/__version__.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 1 addition & 2 deletions cybsi/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 15 additions & 8 deletions cybsi/cloud/client_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dataclasses import dataclass
from typing import Optional, Union

import httpx
Expand Down Expand Up @@ -131,22 +130,30 @@ 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.
limits: Configuration for limits to various client behaviors.
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
6 changes: 1 addition & 5 deletions examples/add_collection_object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
import os

from cybsi.cloud import Client, Config
from cybsi.cloud.error import (
ConflictError,
Expand All @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions examples/add_collection_object_async.py
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down
6 changes: 1 addition & 5 deletions examples/auth_api_keys_chained.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
5 changes: 1 addition & 4 deletions examples/auth_generate_api_key.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
6 changes: 1 addition & 5 deletions examples/auth_resources_chained.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 1 addition & 7 deletions examples/client_advanced_config.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions examples/delete_collection_object.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 1 addition & 5 deletions examples/get_collection_objects_chained.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 1 addition & 4 deletions examples/get_collection_objects_changes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
import os
import time
from typing import Iterable, Optional

Expand All @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions examples/pagination_manual.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env python3
import os
from typing import Optional

from cybsi.cloud import Client, Config
from cybsi.cloud.iocean import CollectionCommonView
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()
Expand Down
5 changes: 1 addition & 4 deletions examples/push_collection_objects.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env python3
import asyncio
import os
from hashlib import md5

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"
async with AsyncClient(config) as client:
Expand Down
5 changes: 1 addition & 4 deletions examples/register_object_schema.py
Original file line number Diff line number Diff line change
@@ -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 = """
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -41,7 +41,7 @@ extend_skip = ["__init__.py"]
[tool.tbump]

[tool.tbump.version]
current = "1.0.3"
current = "1.0.4"

regex = '''
^
Expand Down

0 comments on commit ad5f006

Please sign in to comment.