Skip to content

Commit

Permalink
Updated sync identity client based on latest swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
lsundaralingam committed Jan 19, 2021
1 parent 65e3f3a commit cf291c1
Showing 1 changed file with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ._identity._generated._communication_identity_client\
import CommunicationIdentityClient as CommunicationIdentityClientGen
from ._identity._generated.models import CommunicationIdentityToken
from ._identity._generated.models import CommunicationIdentityAccessToken
from ._shared.utils import parse_connection_str, get_authentication_policy
from ._shared.models import CommunicationUser
from ._version import SDK_MONIKER
Expand Down Expand Up @@ -82,13 +82,35 @@ def create_user(self, **kwargs):
# type: (...) -> CommunicationUser
"""create a single Communication user
return: CommunicationUser
rtype: ~azure.communication.administration.CommunicationUser
:return: CommunicationUser
:rtype: ~azure.communication.administration.CommunicationUser
"""
return self._identity_service_client.communication_identity.create(
return self._identity_service_client.communication_identity.create_identity(
cls=lambda pr, u, e: CommunicationUser(u.id),
**kwargs)

@distributed_trace
def create_user_with_token(
self,
scopes, # type: List[Union[str, "_model.CommunicationIdentityTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> Tuple[CommunicationUser, CommunicationIdentityAccessToken]
"""create a single Communication user with an identity token.
:param scopes:
List of scopes to be added to the token.
:type scopes: list[str or
~azure.communication.administration.models.CommunicationIdentityTokenScope]
:return: A CommunicationUser and a CommunicationIdentityToken tuple.
:rtype: tuple of (~azure.communication.administration.CommunicationUser,
~azure.communication.administration.CommunicationIdentityToken)
"""
return self._identity_service_client.communication_identity.create_identity(
cls=lambda pr, u, e: CommunicationUser(u.id),
create_token_with_scopes=scopes,
**kwargs)

@distributed_trace
def delete_user(
self,
Expand All @@ -104,28 +126,29 @@ def delete_user(
:return: None
:rtype: None
"""
self._identity_service_client.communication_identity.delete(
self._identity_service_client.communication_identity.delete_identity(
communication_user.identifier, **kwargs)

@distributed_trace
def issue_token(
self,
user, # type: CommunicationUser
scopes, # type: List[str]
scopes, # List[Union[str, "_model.CommunicationIdentityTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> CommunicationIdentityToken
# type: (...) -> CommunicationIdentityAccessToken
"""Generates a new token for an identity.
:param user: Azure Communication User
:type user: ~azure.communication.administration.CommunicationUser
:param scopes:
List of scopes to be added to the token.
:type scopes: list[str]
:return: CommunicationIdentityToken
:rtype: ~azure.communication.administration.CommunicationIdentityToken
:type scopes: list[str or
~azure.communication.administration.models.CommunicationIdentityTokenScope]
:return: CommunicationIdentityAccessToken
:rtype: ~azure.communication.administration.CommunicationIdentityAccessToken
"""
return self._identity_service_client.communication_identity.issue_token(
return self._identity_service_client.communication_identity.issue_access_token(
user.identifier,
scopes,
**kwargs)
Expand All @@ -134,20 +157,16 @@ def issue_token(
def revoke_tokens(
self,
user, # type: CommunicationUser
issued_before=None, # type: Optional[datetime.datetime]
**kwargs # type: Any
):
# type: (...) -> None
"""Schedule revocation of all tokens of an identity.
:param user: Azure Communication User.
:type user: ~azure.communication.administration.CommunicationUser.
:param issued_before: All tokens that are issued prior to this time should get revoked.
:type issued_before: ~datetime.datetime.
:return: None
:rtype: None
"""
return self._identity_service_client.communication_identity.update(
return self._identity_service_client.communication_identity.revoke_access_tokens(
user.identifier if user else None,
tokens_valid_from=issued_before,
**kwargs)

0 comments on commit cf291c1

Please sign in to comment.