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 691a578
Show file tree
Hide file tree
Showing 16 changed files with 1,999 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
65 changes: 65 additions & 0 deletions python/dazl/protocols/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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,
read_as: "Union[None, Party, Collection[Party]]" = None,
act_as: "Union[None, Party, Collection[Party]]" = None,
party: "Union[None, Party, Collection[Party]]" = None,
admin: "Optional[bool]" = False,
ledger_id: "Optional[str]" = None,
application_name: "Optional[str]" = None,
oauth_token: "Optional[str]" = None,
ca: "Optional[bytes]" = None,
ca_file: "Optional[PathLike]" = None,
cert: "Optional[bytes]" = None,
cert_file: "Optional[PathLike]" = None,
cert_key: "Optional[bytes]" = None,
cert_key_file: "Optional[PathLike]" = None,
connect_timeout: "Optional[TimeDeltaLike]" = None,
enable_http_proxy: "bool" = True,
) -> "Config":
url_config = URLConfig(
url=url,
connect_timeout=connect_timeout,
enable_http_proxy=enable_http_proxy,
)

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

ssl_config = SSLConfig(
ca=ca,
ca_file=ca_file,
cert=cert,
cert_file=cert_file,
cert_key=cert_key,
cert_key_file=cert_key_file,
)

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 691a578

Please sign in to comment.