Skip to content

Commit

Permalink
python: Introduce a new connection API that is a bit less stateful.
Browse files Browse the repository at this point in the history
  • Loading branch information
da-tanabe committed Feb 10, 2021
1 parent 18ff1c3 commit ce68dbe
Show file tree
Hide file tree
Showing 15 changed files with 1,924 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/dazl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .prim import FrozenDict as frozendict
from .pretty.table import write_acs

from .protocols.ledgerapi import connect, Connection

try:
# This method is undocumented, but is required to read large size of model files when using
Expand Down
62 changes: 62 additions & 0 deletions python/dazl/protocols/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from os import PathLike
from typing import Collection, Optional, Union

from ...prim import Party, TimeDeltaLike
from .access import AccessConfig, create_access
from .ssl import SSLConfig
from .url import URLConfig

__all__ = ["Config", "AccessConfig", "SSLConfig", "URLConfig"]


class Config:
@classmethod
def create(
cls,
url: str = None,
oauth_client_id: "Optional[str]" = None,
oauth_token: "Optional[str]" = None,
party: "Union[None, Party, Collection[Party]]" = None,
read_as: "Union[None, Party, Collection[Party]]" = None,
act_as: "Union[None, Party, Collection[Party]]" = None,
admin: "Optional[bool]" = False,
ca_file: "Optional[PathLike]" = None,
cert_file: "Optional[PathLike]" = None,
cert_key_file: "Optional[PathLike]" = None,
verify_ssl: "Optional[str]" = None,
connect_timeout: "Optional[TimeDeltaLike]" = None,
enable_http_proxy: "bool" = True,
ledger_id: "Optional[str]" = None,
application_name: "Optional[str]" = None,
) -> "Config":
url_config = URLConfig(
url=url,
connect_timeout=connect_timeout,
enable_http_proxy=enable_http_proxy,
)

access_config = create_access(
party=party,
ledger_id=ledger_id,
application_name=application_name,
read_as=read_as,
act_as=act_as,
admin=admin,
oauth_token=oauth_token,
)

ssl_config = SSLConfig(
ca_file=ca_file,
cert_file=cert_file,
cert_key_file=cert_key_file,
verify_ssl=verify_ssl,
)

return cls(access_config, ssl_config, url_config)

def __init__(self, access: "AccessConfig", ssl: "SSLConfig", url: "URLConfig"):
self.access = access
self.ssl = ssl
self.url = url
Loading

0 comments on commit ce68dbe

Please sign in to comment.