Skip to content

Commit

Permalink
Merge pull request #334 from digital-asset/python-fix-typing-rules
Browse files Browse the repository at this point in the history
python: Fix a few broken typing rules.
  • Loading branch information
da-tanabe authored Mar 16, 2022
2 parents ddbae30 + 12ba0bc commit 112a6ac
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.7.0
7.7.1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "dazl"
version = "7.7.0"
version = "7.7.1"
description = "high-level Ledger API client for Daml ledgers"
license = "Apache-2.0"
authors = ["Davin K. Tanabe <davin.tanabe@digitalasset.com>"]
Expand Down
7 changes: 7 additions & 0 deletions python/dazl/ledger/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ from .api_types import (
ExerciseResponse,
ParticipantMeteringReport,
PartyInfo,
Right,
SubmitResponse,
User,
)
Expand Down Expand Up @@ -306,7 +307,13 @@ class Connection(PackageService, Protocol):
read_as: Union[None, Party, Collection[Party]] = None,
) -> QueryStream: ...
def get_user(self, user_id: Optional[str] = None) -> Union[User, Awaitable[User]]: ...
def create_user(
self, user: User, rights: Optional[Sequence[Right]] = ...
) -> Union[User, Awaitable[User]]: ...
def list_users(self) -> Union[Sequence[User], Awaitable[Sequence[User]]]: ...
def list_user_rights(
self, user_id: "Optional[str]" = None
) -> Union[Sequence[Right], Awaitable[Sequence[Right]]]: ...
def allocate_party(
self, *, identifier_hint: str = None, display_name: str = None
) -> Union[PartyInfo, Awaitable[PartyInfo]]: ...
Expand Down
6 changes: 6 additions & 0 deletions python/dazl/ledger/aio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ from ..api_types import (
ExerciseResponse,
ParticipantMeteringReport,
PartyInfo,
Right,
SubmitResponse,
User,
)
from .pkgloader import PackageLoader

Expand Down Expand Up @@ -192,6 +194,10 @@ class Connection(_Connection, PackageService, Protocol):
offset: Optional[str] = None,
read_as: Union[None, Party, Collection[Party]] = None,
) -> QueryStream: ...
async def get_user(self, user_id: Optional[str] = None) -> User: ...
async def create_user(self, user: User, rights: Optional[Sequence[Right]] = ...) -> User: ...
async def list_users(self) -> Sequence[User]: ...
async def list_user_rights(self, user_id: Optional[str] = None) -> Sequence[Right]: ...
async def allocate_party(
self, *, identifier_hint: Optional[str] = None, display_name: Optional[str] = None
) -> PartyInfo: ...
Expand Down
6 changes: 4 additions & 2 deletions python/dazl/ledger/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,6 @@ def __repr__(self):
class User:
"""
Full information about a ``User``.
Note: This is part of a Daml 2.x pre-release API and is subject to change.
"""

__slots__ = ("id", "primary_party")
Expand All @@ -616,6 +614,10 @@ def __init__(self, id: str, primary_party: Party):


class Right(abc.ABC):
"""
Information about an individual right for a :class:`User`.
"""

def __setattr__(self, key, value):
"""
Overridden to make Right objects read-only.
Expand Down
3 changes: 3 additions & 0 deletions python/dazl/ledger/blocking/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ from ..api_types import (
ExerciseResponse,
ParticipantMeteringReport,
PartyInfo,
Right,
User,
)
from .pkgloader import PackageLoader
Expand Down Expand Up @@ -142,7 +143,9 @@ class Connection(_Connection, PackageService, Protocol):
read_as: Union[None, Party, Collection[Party]] = None,
) -> QueryStream: ...
def get_user(self, user_id: Optional[str] = None) -> User: ...
def create_user(self, user: User, rights: Optional[Sequence[Right]] = ...) -> User: ...
def list_users(self) -> Sequence[User]: ...
def list_user_rights(self, user_id: Optional[str] = None) -> Sequence[Right]: ...
def allocate_party(
self, *, identifier_hint: Optional[str] = None, display_name: Optional[str] = None
) -> PartyInfo: ...
Expand Down
2 changes: 2 additions & 0 deletions python/dazl/ledger/config/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def token(self, value: str) -> None:
self._application_name = v1_claims.get("applicationId", None)
self._token_version = 1
else:
self._ledger_id = None
self._application_name = None
self._token_version = 2

def _set(self, *, read_as: Collection[Party], act_as: Collection[Party], admin: bool):
Expand Down
22 changes: 12 additions & 10 deletions python/dazl/ledger/grpc/conn_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ async def open(self) -> None:
Does final validation of the token, including possibly fetching the ledger ID if it is not
yet known.
"""
if not self._config.access.ledger_id:
# most calls require a ledger ID; if it wasn't supplied as part of our token or we were
# never given a token in the first place, fetch the ledger ID from the destination
stub = lapipb.LedgerIdentityServiceStub(self._channel)
response = await stub.GetLedgerIdentity(lapipb.GetLedgerIdentityRequest())
if isinstance(self._config.access, PropertyBasedAccessConfig):
self._logger.info("Connected to gRPC Ledger API, ledger ID: %s", response.ledger_id)
self._config.access.ledger_id = response.ledger_id
else:
raise ValueError("when using token-based access, the token must contain ledger ID")
if self._config.access.token_version == 2:
# Daml 2.0 tokens do not contain party information, so an extra call to the server is
# required in order to resolve our current set of rights
Expand All @@ -127,6 +117,18 @@ async def open(self) -> None:
read_as=read_as, act_as=act_as, admin=admin
)

elif not self._config.access.ledger_id:
# most calls to Daml 1.x ledgers require a ledger ID; if it wasn't supplied as part of
# our token or we were never given a token in the first place, fetch the ledger ID from
# the destination
stub = lapipb.LedgerIdentityServiceStub(self._channel)
response = await stub.GetLedgerIdentity(lapipb.GetLedgerIdentityRequest())
if isinstance(self._config.access, PropertyBasedAccessConfig):
self._logger.info("Connected to gRPC Ledger API, ledger ID: %s", response.ledger_id)
self._config.access.ledger_id = response.ledger_id
else:
raise ValueError("when using token-based access, the token must contain ledger ID")

async def close(self) -> None:
"""
Close the underlying channel. Once the channel is closed, future command submissions,
Expand Down

0 comments on commit 112a6ac

Please sign in to comment.