diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_shared/models.py b/sdk/communication/azure-communication-administration/azure/communication/administration/_shared/models.py index 841fae6ae07f..2e64b18dc068 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_shared/models.py +++ b/sdk/communication/azure-communication-administration/azure/communication/administration/_shared/models.py @@ -2,6 +2,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: skip-file + +from enum import Enum, EnumMeta +from six import with_metaclass + +import msrest class CommunicationUserIdentifier(object): """ @@ -17,13 +23,14 @@ def __init__(self, identifier): class PhoneNumberIdentifier(object): """ Represents a phone number. - :ivar value: Value for a phone number. - :vartype value: str - :param value: Value to initialize PhoneNumberIdentifier. - :type value: str + :param phone_number: The phone number in E.164 format. + :type phone_number: str + :param identifier: The full id of the phone number. + :type identifier: str """ - def __init__(self, phone_number): + def __init__(self, phone_number, identifier=None): self.phone_number = phone_number + self.identifier = identifier class UnknownIdentifier(object): """ @@ -38,18 +45,102 @@ class UnknownIdentifier(object): def __init__(self, identifier): self.identifier = identifier +class CommunicationIdentifierModel(msrest.serialization.Model): + """Communication Identifier Model. + + All required parameters must be populated in order to send to Azure. + + :param kind: Required. Kind of Communication Identifier. + :type kind: CommunicationIdentifierKind + :param id: Full id of the identifier. + :type id: str + :param phone_number: phone number in case the identifier is a phone number. + :type phone_number: str + :param is_anonymous: True if the identifier is anonymous. + :type is_anonymous: bool + :param microsoft_teams_user_id: Microsoft Teams user id. + :type microsoft_teams_user_id: str + :param communication_cloud_environment: Cloud environment that the user belongs to. + :type communication_cloud_environment: CommunicationCloudEnvironment + """ + + _validation = { + 'kind': {'required': True}, + } + + _attribute_map = { + 'kind': {'key': 'kind', 'type': 'str'}, + 'id': {'key': 'id', 'type': 'str'}, + 'phone_number': {'key': 'phoneNumber', 'type': 'str'}, + 'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'}, + 'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'}, + 'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentifierModel, self).__init__(**kwargs) + self.kind = kwargs['kind'] + self.id = kwargs.get('id', None) + self.phone_number = kwargs.get('phone_number', None) + self.is_anonymous = kwargs.get('is_anonymous', None) + self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None) + self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None) + +class _CaseInsensitiveEnumMeta(EnumMeta): + def __getitem__(cls, name): + return super().__getitem__(name.upper()) + + def __getattr__(cls, name): + """Return the enum member matching `name` + We use __getattr__ instead of descriptors or inserting into the enum + class' __dict__ in order to support `name` and `value` being both + properties for enum members (which live in the class' __dict__) and + enum members themselves. + """ + try: + return cls._member_map_[name.upper()] + except KeyError: + raise AttributeError(name) + +class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """Communication Identifier Kind. + """ + Unknown = "UNKNOWN" + CommunicationUser = "COMMUNICATIONUSER" + PhoneNumber = "PHONENUMBER" + CallingApplication = "CALLINGAPPLICATION" + MicrosoftTeamsUser = "MICROSOFTTEAMSUSER" + +class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """ + The cloud enviornment that the identifier belongs to + """ + + Public = "PUBLIC" + Dod = "DOD" + Gcch = "GCCH" + class MicrosoftTeamsUserIdentifier(object): """ Represents an identifier for a Microsoft Teams user. - :ivar user_id: the string identifier representing the identity + :ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user. :vartype user_id: str :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. :type user_id: str + :ivar identifier: The full id of the Microsoft Teams User identifier. + :vartype identifier: str + :ivar cloud: Cloud environment that this identifier belongs to + :vartype cloud: CommunicationCloudEnvironment :ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link :vartype is_anonymous: bool :param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier. :type is_anonymous: bool """ - def __init__(self, user_id, is_anonymous=False): + def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False): + self.identifier = identifier self.user_id = user_id self.is_anonymous = is_anonymous + self.cloud = cloud \ No newline at end of file diff --git a/sdk/communication/azure-communication-administration/dev_requirements.txt b/sdk/communication/azure-communication-administration/dev_requirements.txt index 20a3358cbdde..178278b41eb5 100644 --- a/sdk/communication/azure-communication-administration/dev_requirements.txt +++ b/sdk/communication/azure-communication-administration/dev_requirements.txt @@ -1,5 +1,4 @@ -e ../../../tools/azure-sdk-tools --e ../../../tools/azure-devtools -e ../../identity/azure-identity ../../core/azure-core ../azure-communication-nspkg diff --git a/sdk/communication/azure-communication-administration/setup.py b/sdk/communication/azure-communication-administration/setup.py index 6bdbf874652c..077feec7d8f3 100644 --- a/sdk/communication/azure-communication-administration/setup.py +++ b/sdk/communication/azure-communication-administration/setup.py @@ -64,7 +64,7 @@ ]), install_requires=[ "msrest>=0.6.0", - "azure-core<2.0.0,>=1.6.0", + "azure-core<2.0.0,>=1.9.0", ], extras_require={ ":python_version<'3.0'": ['azure-communication-nspkg'], diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/communication_identifier_serializer.py b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/communication_identifier_serializer.py index add39d24e222..39a81e5d2a64 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/communication_identifier_serializer.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/communication_identifier_serializer.py @@ -19,10 +19,12 @@ class CommunicationUserIdentifierSerializer(object): def serialize(cls, communicationIdentifier): """ Serialize the Communication identifier into CommunicationIdentifierModel - :param identifier: Communication service identifier - :type identifier: Union[CommunicationUserIdentifier, CommunicationPhoneNumberIdentifier] + :param identifier: Identifier object + :type identifier: Union[CommunicationUserIdentifier, + PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier, UnknownIdentifier] :return: CommunicationIdentifierModel :rtype: ~azure.communication.chat.CommunicationIdentifierModel + :raises Union[TypeError, ValueError] """ if isinstance(communicationIdentifier, CommunicationUserIdentifier): return CommunicationIdentifierModel( @@ -32,18 +34,24 @@ def serialize(cls, communicationIdentifier): if isinstance(communicationIdentifier, PhoneNumberIdentifier): return CommunicationIdentifierModel( kind=CommunicationIdentifierKind.PhoneNumber, - id=communicationIdentifier.phone_number + id=communicationIdentifier.identifier, + phone_number=communicationIdentifier.phone_number ) if isinstance(communicationIdentifier, MicrosoftTeamsUserIdentifier): return CommunicationIdentifierModel( kind=CommunicationIdentifierKind.MicrosoftTeamsUser, - id=communicationIdentifier.user_id + id=communicationIdentifier.identifier, + microsoft_teams_user_id=communicationIdentifier.user_id, + communication_cloud_environment=communicationIdentifier.cloud ) - return CommunicationIdentifierModel( - kind=CommunicationIdentifierKind.Unknown, - id=communicationIdentifier.identifier - ) + if isinstance(communicationIdentifier, UnknownIdentifier): + return CommunicationIdentifierModel( + kind=CommunicationIdentifierKind.Unknown, + id=communicationIdentifier.identifier + ) + + raise TypeError("Unsupported identifier type " + communicationIdentifier.__class__.__name__) @classmethod def deserialize(cls, identifierModel): @@ -58,26 +66,27 @@ def deserialize(cls, identifierModel): """ identifier, kind = identifierModel.id, identifierModel.kind + if not identifier: + raise ValueError("Identifier must have a valid id") if kind == CommunicationIdentifierKind.CommunicationUser: - if not identifier: - raise ValueError("CommunictionUser must have a valid id") return CommunicationUserIdentifier(id) if kind == CommunicationIdentifierKind.PhoneNumber: if not identifierModel.phone_number: raise ValueError("PhoneNumberIdentifier must have a valid attribute - phone_number") - return PhoneNumberIdentifier(identifierModel.phone_number) + return PhoneNumberIdentifier(identifierModel.phone_number, identifier=identifier) if kind == CommunicationIdentifierKind.MicrosoftTeamsUser: if identifierModel.is_anonymous not in [True, False]: raise ValueError("MicrosoftTeamsUser must have a valid attribute - is_anonymous") if not identifierModel.microsoft_teams_user_id: raise ValueError("MicrosoftTeamsUser must have a valid attribute - microsoft_teams_user_id") + if not identifierModel.communication_cloud_environment: + raise ValueError("MicrosoftTeamsUser must have a valid attribute - communication_cloud_environment") return MicrosoftTeamsUserIdentifier( identifierModel.microsoft_teams_user_id, - is_anonymous=identifierModel.is_anonymous + identifier=identifier, + is_anonymous=identifierModel.is_anonymous, + cloud=identifierModel.communication_cloud_environment ) - if not identifier: - raise ValueError("UnknownIdentifier must have a valid id") - return UnknownIdentifier(identifier) diff --git a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py index a0c957a766d3..e92bd5b83583 100644 --- a/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py +++ b/sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py @@ -23,13 +23,14 @@ def __init__(self, identifier): class PhoneNumberIdentifier(object): """ Represents a phone number. - :ivar value: Value for a phone number. - :vartype value: str - :param value: Value to initialize PhoneNumberIdentifier. - :type value: str + :param phone_number: The phone number in E.164 format. + :type phone_number: str + :param identifier: The full id of the phone number. + :type identifier: str """ - def __init__(self, phone_number): + def __init__(self, phone_number, identifier=None): self.phone_number = phone_number + self.identifier = identifier class UnknownIdentifier(object): """ @@ -44,22 +45,6 @@ class UnknownIdentifier(object): def __init__(self, identifier): self.identifier = identifier -class MicrosoftTeamsUserIdentifier(object): - """ - Represents an identifier for a Microsoft Teams user. - :ivar user_id: the string identifier representing the identity - :vartype user_id: str - :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. - :type user_id: str - :ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link - :vartype is_anonymous: bool - :param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier. - :type is_anonymous: bool - """ - def __init__(self, user_id, is_anonymous=False): - self.user_id = user_id - self.is_anonymous = is_anonymous - class CommunicationIdentifierModel(msrest.serialization.Model): """Communication Identifier Model. @@ -67,14 +52,16 @@ class CommunicationIdentifierModel(msrest.serialization.Model): :param kind: Required. Kind of Communication Identifier. :type kind: CommunicationIdentifierKind - :param id: identifies the Communication Identitity. + :param id: Full id of the identifier. :type id: str - :param phone_number: phone number in case the identity is phone number. + :param phone_number: phone number in case the identifier is a phone number. :type phone_number: str - :param is_anonymous: is the Microsoft Teams user is anaynimous. + :param is_anonymous: True if the identifier is anonymous. :type is_anonymous: bool :param microsoft_teams_user_id: Microsoft Teams user id. :type microsoft_teams_user_id: str + :param communication_cloud_environment: Cloud environment that the user belongs to. + :type communication_cloud_environment: CommunicationCloudEnvironment """ _validation = { @@ -87,6 +74,7 @@ class CommunicationIdentifierModel(msrest.serialization.Model): 'phone_number': {'key': 'phoneNumber', 'type': 'str'}, 'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'}, 'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'}, + 'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'}, } def __init__( @@ -99,7 +87,7 @@ def __init__( self.phone_number = kwargs.get('phone_number', None) self.is_anonymous = kwargs.get('is_anonymous', None) self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None) - + self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None) class _CaseInsensitiveEnumMeta(EnumMeta): def __getitem__(cls, name): @@ -121,7 +109,38 @@ class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, """Communication Identifier Kind. """ Unknown = "UNKNOWN" - CommunicationUser = "COMMUNICATIONuSER" - PhoneNumber = "PHONEnUMBER" + CommunicationUser = "COMMUNICATIONUSER" + PhoneNumber = "PHONENUMBER" CallingApplication = "CALLINGAPPLICATION" - MicrosoftTeamsUser = "MICROSOFTTEAMSuSER" + MicrosoftTeamsUser = "MICROSOFTTEAMSUSER" + +class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """ + The cloud enviornment that the identifier belongs to + """ + + Public = "PUBLIC" + Dod = "DOD" + Gcch = "GCCH" + +class MicrosoftTeamsUserIdentifier(object): + """ + Represents an identifier for a Microsoft Teams user. + :ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user. + :vartype user_id: str + :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. + :type user_id: str + :ivar identifier: The full id of the Microsoft Teams User identifier. + :vartype identifier: str + :ivar cloud: Cloud environment that this identifier belongs to + :vartype cloud: CommunicationCloudEnvironment + :ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link + :vartype is_anonymous: bool + :param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier. + :type is_anonymous: bool + """ + def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False): + self.identifier = identifier + self.user_id = user_id + self.is_anonymous = is_anonymous + self.cloud = cloud diff --git a/sdk/communication/azure-communication-chat/dev_requirements.txt b/sdk/communication/azure-communication-chat/dev_requirements.txt index b88483d99721..48afd604de5b 100644 --- a/sdk/communication/azure-communication-chat/dev_requirements.txt +++ b/sdk/communication/azure-communication-chat/dev_requirements.txt @@ -1,4 +1,3 @@ --e ../../../tools/azure-devtools -e ../../../tools/azure-sdk-tools ../azure-communication-nspkg -e ../azure-communication-identity diff --git a/sdk/communication/azure-communication-chat/setup.py b/sdk/communication/azure-communication-chat/setup.py index e7e02001af20..9bc0b5bf374f 100644 --- a/sdk/communication/azure-communication-chat/setup.py +++ b/sdk/communication/azure-communication-chat/setup.py @@ -59,7 +59,7 @@ 'azure.communication' ]), install_requires=[ - 'azure-core<2.0.0,>=1.6.0', + 'azure-core<2.0.0,>=1.9.0', 'msrest>=0.6.0', 'six>=1.6' ], diff --git a/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identity_serializer.py b/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identity_serializer.py index 1f661c3833a9..3c8ff5de2721 100644 --- a/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identity_serializer.py +++ b/sdk/communication/azure-communication-chat/tests/_shared/test_communication_identity_serializer.py @@ -9,6 +9,7 @@ CommunicationIdentifierKind, CommunicationIdentifierModel, CommunicationUserIdentifier, + CommunicationCloudEnvironment, UnknownIdentifier, PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier @@ -16,7 +17,7 @@ class CommunicationUserIdentifierSerializerTest(unittest.TestCase): - def test_missing_property_desrializer_throws(self): + def test_missing_property_deserializer_throws(self): models_with_missing_property = [ CommunicationIdentifierModel( kind=CommunicationIdentifierKind.Unknown @@ -25,18 +26,33 @@ def test_missing_property_desrializer_throws(self): kind=CommunicationIdentifierKind.CommunicationUser ), # missing id CommunicationIdentifierModel( - # phone_number="phonenumber", + id="someid", kind=CommunicationIdentifierKind.PhoneNumber ), # missing phone number CommunicationIdentifierModel( - # id="an id", + id="someid", microsoft_teams_user_id="teamsid", - kind=CommunicationIdentifierKind.MicrosoftTeamsUser + kind=CommunicationIdentifierKind.MicrosoftTeamsUser, + cloud=CommunicationCloudEnvironment.Public ), # missing is_anonymous CommunicationIdentifierModel( + id="some id", + is_anonymous=True, + kind=CommunicationIdentifierKind.MicrosoftTeamsUser, + cloud=CommunicationCloudEnvironment.Public + ), # missing microsoft_teams_user_id + CommunicationIdentifierModel( + microsoft_teams_user_id="teamsid", is_anonymous=True, + kind=CommunicationIdentifierKind.MicrosoftTeamsUser, + cloud=CommunicationCloudEnvironment.Public + ), # missing id + CommunicationIdentifierModel( + id="someid", + is_anonymous=True, + microsoft_teams_user_id="teamsid", kind=CommunicationIdentifierKind.MicrosoftTeamsUser - ) # missing microsoft_teams_user_id, + ) # missing cloud, ] for model in models_with_missing_property: @@ -90,42 +106,79 @@ def test_serialize_phone_number(self): ) assert phone_number_identifier_model.kind is CommunicationIdentifierKind.PhoneNumber - assert phone_number_identifier_model.id is "phonenumber" + assert phone_number_identifier_model.phone_number is "phonenumber" def test_deserialize_phone_number(self): phone_number_identifier_actual = CommunicationUserIdentifierSerializer.deserialize( CommunicationIdentifierModel( + id="someid", kind=CommunicationIdentifierKind.PhoneNumber, phone_number="phonenumber" ) ) - phone_number_identifier_expected = PhoneNumberIdentifier("phonenumber") + phone_number_identifier_expected = PhoneNumberIdentifier("phonenumber", identifier="someid") assert isinstance(phone_number_identifier_actual, PhoneNumberIdentifier) assert phone_number_identifier_actual.phone_number == phone_number_identifier_expected.phone_number + assert phone_number_identifier_actual.identifier == phone_number_identifier_expected.identifier def test_serialize_teams_user(self): teams_user_identifier_model = CommunicationUserIdentifierSerializer.serialize( - MicrosoftTeamsUserIdentifier("teamsid") + MicrosoftTeamsUserIdentifier( + "teamsid", + cloud=CommunicationCloudEnvironment.Public, + identifier="someid" + ) ) assert teams_user_identifier_model.kind is CommunicationIdentifierKind.MicrosoftTeamsUser - assert teams_user_identifier_model.id is "teamsid" + assert teams_user_identifier_model.microsoft_teams_user_id is "teamsid" + assert teams_user_identifier_model.communication_cloud_environment is CommunicationCloudEnvironment.Public + assert teams_user_identifier_model.id is "someid" def test_deserialize_teams_user(self): teams_user_identifier_actual = CommunicationUserIdentifierSerializer.deserialize( CommunicationIdentifierModel( + id="someid", kind=CommunicationIdentifierKind.MicrosoftTeamsUser, microsoft_teams_user_id="teamsid", - is_anonymous=True + is_anonymous=True, + communication_cloud_environment="PUBLIC" ) ) - teams_user_identifier_expected = MicrosoftTeamsUserIdentifier("teamsid", is_anonymous=True) + teams_user_identifier_expected = MicrosoftTeamsUserIdentifier( + "teamsid", + identifier="someid", + cloud=CommunicationCloudEnvironment.Public, + is_anonymous=True + ) assert isinstance(teams_user_identifier_actual, MicrosoftTeamsUserIdentifier) + assert teams_user_identifier_actual.identifier == teams_user_identifier_expected.identifier assert teams_user_identifier_actual.user_id == teams_user_identifier_expected.user_id - + assert teams_user_identifier_actual.is_anonymous== teams_user_identifier_expected.is_anonymous + assert teams_user_identifier_actual.cloud == teams_user_identifier_expected.cloud + + def test_serialize_foreign_throws(self): + foreign_obj = "Foreign object" + self.assertRaises( + TypeError, + lambda : CommunicationUserIdentifierSerializer.serialize(foreign_obj) + ) + + def test_deserialize_unknown_kind(self): + unknown_identifier = CommunicationUserIdentifierSerializer.deserialize( + CommunicationIdentifierModel( + kind="foreign", + id="an id" + ) + ) + + assert isinstance(unknown_identifier, UnknownIdentifier) + assert unknown_identifier.identifier == "an id" + + if __name__ == "__main__": unittest.main() \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py index 51260e07d2d9..2e64b18dc068 100644 --- a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py @@ -2,6 +2,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: skip-file + +from enum import Enum, EnumMeta +from six import with_metaclass + +import msrest class CommunicationUserIdentifier(object): """ @@ -17,13 +23,14 @@ def __init__(self, identifier): class PhoneNumberIdentifier(object): """ Represents a phone number. - :ivar value: Value for a phone number. - :vartype value: str - :param value: Value to initialize PhoneNumberIdentifier. - :type value: str + :param phone_number: The phone number in E.164 format. + :type phone_number: str + :param identifier: The full id of the phone number. + :type identifier: str """ - def __init__(self, value): - self.value = value + def __init__(self, phone_number, identifier=None): + self.phone_number = phone_number + self.identifier = identifier class UnknownIdentifier(object): """ @@ -38,18 +45,102 @@ class UnknownIdentifier(object): def __init__(self, identifier): self.identifier = identifier +class CommunicationIdentifierModel(msrest.serialization.Model): + """Communication Identifier Model. + + All required parameters must be populated in order to send to Azure. + + :param kind: Required. Kind of Communication Identifier. + :type kind: CommunicationIdentifierKind + :param id: Full id of the identifier. + :type id: str + :param phone_number: phone number in case the identifier is a phone number. + :type phone_number: str + :param is_anonymous: True if the identifier is anonymous. + :type is_anonymous: bool + :param microsoft_teams_user_id: Microsoft Teams user id. + :type microsoft_teams_user_id: str + :param communication_cloud_environment: Cloud environment that the user belongs to. + :type communication_cloud_environment: CommunicationCloudEnvironment + """ + + _validation = { + 'kind': {'required': True}, + } + + _attribute_map = { + 'kind': {'key': 'kind', 'type': 'str'}, + 'id': {'key': 'id', 'type': 'str'}, + 'phone_number': {'key': 'phoneNumber', 'type': 'str'}, + 'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'}, + 'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'}, + 'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentifierModel, self).__init__(**kwargs) + self.kind = kwargs['kind'] + self.id = kwargs.get('id', None) + self.phone_number = kwargs.get('phone_number', None) + self.is_anonymous = kwargs.get('is_anonymous', None) + self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None) + self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None) + +class _CaseInsensitiveEnumMeta(EnumMeta): + def __getitem__(cls, name): + return super().__getitem__(name.upper()) + + def __getattr__(cls, name): + """Return the enum member matching `name` + We use __getattr__ instead of descriptors or inserting into the enum + class' __dict__ in order to support `name` and `value` being both + properties for enum members (which live in the class' __dict__) and + enum members themselves. + """ + try: + return cls._member_map_[name.upper()] + except KeyError: + raise AttributeError(name) + +class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """Communication Identifier Kind. + """ + Unknown = "UNKNOWN" + CommunicationUser = "COMMUNICATIONUSER" + PhoneNumber = "PHONENUMBER" + CallingApplication = "CALLINGAPPLICATION" + MicrosoftTeamsUser = "MICROSOFTTEAMSUSER" + +class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """ + The cloud enviornment that the identifier belongs to + """ + + Public = "PUBLIC" + Dod = "DOD" + Gcch = "GCCH" + class MicrosoftTeamsUserIdentifier(object): """ Represents an identifier for a Microsoft Teams user. - :ivar user_id: the string identifier representing the identity + :ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user. :vartype user_id: str :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. :type user_id: str + :ivar identifier: The full id of the Microsoft Teams User identifier. + :vartype identifier: str + :ivar cloud: Cloud environment that this identifier belongs to + :vartype cloud: CommunicationCloudEnvironment :ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link :vartype is_anonymous: bool :param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier. :type is_anonymous: bool """ - def __init__(self, user_id, is_anonymous=False): + def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False): + self.identifier = identifier self.user_id = user_id self.is_anonymous = is_anonymous + self.cloud = cloud \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/dev_requirements.txt b/sdk/communication/azure-communication-identity/dev_requirements.txt index 6feae79262c7..b2a89e90a458 100644 --- a/sdk/communication/azure-communication-identity/dev_requirements.txt +++ b/sdk/communication/azure-communication-identity/dev_requirements.txt @@ -1,5 +1,4 @@ -e ../../../tools/azure-sdk-tools --e ../../../tools/azure-devtools -e ../../identity/azure-identity ../../core/azure-core ../azure-communication-nspkg diff --git a/sdk/communication/azure-communication-identity/setup.py b/sdk/communication/azure-communication-identity/setup.py index 9efe558e6239..777e5c09b19e 100644 --- a/sdk/communication/azure-communication-identity/setup.py +++ b/sdk/communication/azure-communication-identity/setup.py @@ -64,7 +64,7 @@ ]), install_requires=[ 'msrest>=0.5.0', - "azure-core<2.0.0,>=1.2.2" + 'azure-core<2.0.0,>=1.9.0' ], extras_require={ ":python_version<'3.0'": ['azure-communication-nspkg'], diff --git a/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py b/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py index f3d8bd56146b..2e64b18dc068 100644 --- a/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py +++ b/sdk/communication/azure-communication-sms/azure/communication/sms/_shared/models.py @@ -2,6 +2,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: skip-file + +from enum import Enum, EnumMeta +from six import with_metaclass + +import msrest class CommunicationUserIdentifier(object): """ @@ -17,13 +23,14 @@ def __init__(self, identifier): class PhoneNumberIdentifier(object): """ Represents a phone number. - :ivar value: Value for a phone number. - :vartype value: str - :param value: Value to initialize PhoneNumberIdentifier. - :type value: str + :param phone_number: The phone number in E.164 format. + :type phone_number: str + :param identifier: The full id of the phone number. + :type identifier: str """ - def __init__(self, phone_number): + def __init__(self, phone_number, identifier=None): self.phone_number = phone_number + self.identifier = identifier class UnknownIdentifier(object): """ @@ -37,3 +44,103 @@ class UnknownIdentifier(object): """ def __init__(self, identifier): self.identifier = identifier + +class CommunicationIdentifierModel(msrest.serialization.Model): + """Communication Identifier Model. + + All required parameters must be populated in order to send to Azure. + + :param kind: Required. Kind of Communication Identifier. + :type kind: CommunicationIdentifierKind + :param id: Full id of the identifier. + :type id: str + :param phone_number: phone number in case the identifier is a phone number. + :type phone_number: str + :param is_anonymous: True if the identifier is anonymous. + :type is_anonymous: bool + :param microsoft_teams_user_id: Microsoft Teams user id. + :type microsoft_teams_user_id: str + :param communication_cloud_environment: Cloud environment that the user belongs to. + :type communication_cloud_environment: CommunicationCloudEnvironment + """ + + _validation = { + 'kind': {'required': True}, + } + + _attribute_map = { + 'kind': {'key': 'kind', 'type': 'str'}, + 'id': {'key': 'id', 'type': 'str'}, + 'phone_number': {'key': 'phoneNumber', 'type': 'str'}, + 'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'}, + 'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'}, + 'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentifierModel, self).__init__(**kwargs) + self.kind = kwargs['kind'] + self.id = kwargs.get('id', None) + self.phone_number = kwargs.get('phone_number', None) + self.is_anonymous = kwargs.get('is_anonymous', None) + self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None) + self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None) + +class _CaseInsensitiveEnumMeta(EnumMeta): + def __getitem__(cls, name): + return super().__getitem__(name.upper()) + + def __getattr__(cls, name): + """Return the enum member matching `name` + We use __getattr__ instead of descriptors or inserting into the enum + class' __dict__ in order to support `name` and `value` being both + properties for enum members (which live in the class' __dict__) and + enum members themselves. + """ + try: + return cls._member_map_[name.upper()] + except KeyError: + raise AttributeError(name) + +class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """Communication Identifier Kind. + """ + Unknown = "UNKNOWN" + CommunicationUser = "COMMUNICATIONUSER" + PhoneNumber = "PHONENUMBER" + CallingApplication = "CALLINGAPPLICATION" + MicrosoftTeamsUser = "MICROSOFTTEAMSUSER" + +class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """ + The cloud enviornment that the identifier belongs to + """ + + Public = "PUBLIC" + Dod = "DOD" + Gcch = "GCCH" + +class MicrosoftTeamsUserIdentifier(object): + """ + Represents an identifier for a Microsoft Teams user. + :ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user. + :vartype user_id: str + :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. + :type user_id: str + :ivar identifier: The full id of the Microsoft Teams User identifier. + :vartype identifier: str + :ivar cloud: Cloud environment that this identifier belongs to + :vartype cloud: CommunicationCloudEnvironment + :ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link + :vartype is_anonymous: bool + :param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier. + :type is_anonymous: bool + """ + def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False): + self.identifier = identifier + self.user_id = user_id + self.is_anonymous = is_anonymous + self.cloud = cloud \ No newline at end of file diff --git a/sdk/communication/azure-communication-sms/setup.py b/sdk/communication/azure-communication-sms/setup.py index 9c9c3a1e30b5..baba27727a8c 100644 --- a/sdk/communication/azure-communication-sms/setup.py +++ b/sdk/communication/azure-communication-sms/setup.py @@ -63,7 +63,7 @@ 'azure.communication' ]), install_requires=[ - 'azure-core<2.0.0,>=1.6.0', + 'azure-core<2.0.0,>=1.9.0', 'msrest>=0.6.0', 'six>=1.6' ], diff --git a/sdk/communication/azure-mgmt-communication/setup.py b/sdk/communication/azure-mgmt-communication/setup.py index 078bb85da2ab..6245604908ee 100644 --- a/sdk/communication/azure-mgmt-communication/setup.py +++ b/sdk/communication/azure-mgmt-communication/setup.py @@ -84,7 +84,8 @@ 'msrest>=0.5.0', 'msrestazure>=0.4.32,<2.0.0', 'azure-common~=1.1', - "azure-core<2.0.0,>=1.2.2" + 'azure-core>=1.9.0,<2.0.0', + 'azure-mgmt-core>=1.2.0,<2.0.0', ], extras_require={ ":python_version<'3.0'": ['azure-mgmt-nspkg'], diff --git a/shared_requirements.txt b/shared_requirements.txt index a433cdff4533..e2f7142b8db2 100644 --- a/shared_requirements.txt +++ b/shared_requirements.txt @@ -177,9 +177,11 @@ opentelemetry-sdk==0.16b1 #override azure-communication-chat msrest>=0.6.0 #override azure-communication-sms msrest>=0.6.0 #override azure-communication-administration msrest>=0.6.0 -#override azure-communication-chat azure-core<2.0.0,>=1.6.0 -#override azure-communication-sms azure-core<2.0.0,>=1.6.0 -#override azure-communication-administration azure-core<2.0.0,>=1.6.0 +#override azure-communication-chat azure-core<2.0.0,>=1.9.0 +#override azure-communication-sms azure-core<2.0.0,>=1.9.0 +#override azure-communication-administration azure-core<2.0.0,>=1.9.0 +#override azure-communication-identity azure-core<2.0.0,>=1.9.0 +#override azure-mgmt-communication azure-core<2.0.0,>=1.9.0 #override azure-ai-metricsadvisor azure-core<2.0.0,>=1.6.0 #override azure-ai-metricsadvisor msrest>=0.6.12 #override azure-opentelemetry-exporter-azuremonitor azure-core<2.0.0,>=1.6.0