diff options
| author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
|---|---|---|
| committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
| commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
| tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/azure/profiles | |
| parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
| download | gn-ai-master.tar.gz | |
Diffstat (limited to '.venv/lib/python3.12/site-packages/azure/profiles')
| -rw-r--r-- | .venv/lib/python3.12/site-packages/azure/profiles/__init__.py | 282 | ||||
| -rw-r--r-- | .venv/lib/python3.12/site-packages/azure/profiles/multiapiclient.py | 91 |
2 files changed, 373 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/azure/profiles/__init__.py b/.venv/lib/python3.12/site-packages/azure/profiles/__init__.py new file mode 100644 index 00000000..6e97f269 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/azure/profiles/__init__.py @@ -0,0 +1,282 @@ +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- +from enum import Enum + +class ProfileDefinition(object): + """Allow to define a custom Profile definition. + + Note:: + + The dict format taken as input is yet to be confirmed and should + *not* be considered as stable in the current implementation. + + :param dict profile_dict: A profile dictionnary + :param str label: A label for pretty printing + """ + def __init__(self, profile_dict, label=None): + self._profile_dict = profile_dict + self._label = label + + @property + def label(self): + """The label associated to this profile definition. + """ + return self._label + + def __repr__(self): + return self._label if self._label else self._profile_dict.__repr__() + + def get_profile_dict(self): + """Return the current profile dict. + + This is internal information, and content should not be considered stable. + """ + return self._profile_dict + + +class DefaultProfile(object): + """Store a default profile. + + :var ProfileDefinition profile: The default profile as class attribute + """ + profile = None + + def use(self, profile): + """Define a new default profile.""" + if not isinstance(profile, (KnownProfiles, ProfileDefinition)): + raise ValueError("Can only set as default a ProfileDefinition or a KnownProfiles") + type(self).profile = profile + + def definition(self): + return type(self).profile + +class KnownProfiles(Enum): + """This defines known Azure Profiles. + + There is two meta-profiles: + + - latest : will always use latest available api-version on each package + - default : mutable, will define profile automatically for all packages + + If you change default, this changes all created packages on the fly to + this profile. This can be used to switch a complete set of API Version + without re-creating all clients. + """ + + # default - This is a meta-profile and point to another profile + default = DefaultProfile() + # latest - This is a meta-profile and does not contain definitions + latest = ProfileDefinition(None, "latest") + v2017_03_09_profile = ProfileDefinition( + { + "azure.keyvault.KeyVaultClient":{ + None: "2016-10-01" + }, + "azure.mgmt.authorization.AuthorizationManagementClient": { + None: "2015-07-01" + }, + "azure.mgmt.compute.ComputeManagementClient": { + None: "2016-03-30" + }, + "azure.mgmt.keyvault.KeyVaultManagementClient":{ + None: "2016-10-01" + }, + "azure.mgmt.network.NetworkManagementClient": { + None: "2015-06-15" + }, + "azure.mgmt.storage.StorageManagementClient": { + None: "2016-01-01" + }, + "azure.mgmt.resource.policy.PolicyClient": { + None: "2015-10-01-preview" + }, + "azure.mgmt.resource.locks.ManagementLockClient": { + None: "2015-01-01" + }, + "azure.mgmt.resource.links.ManagementLinkClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.resources.ResourceManagementClient": { + None: "2016-02-01" + }, + "azure.mgmt.resource.subscriptions.SubscriptionClient": { + None: "2016-06-01" + } + }, + "2017-03-09-profile" + ) + v2018_03_01_hybrid = ProfileDefinition( + { + "azure.keyvault.KeyVaultClient":{ + None: "2016-10-01" + }, + "azure.mgmt.authorization.AuthorizationManagementClient": { + None: "2015-07-01" + }, + "azure.mgmt.compute.ComputeManagementClient": { + None: "2017-03-30" + }, + "azure.mgmt.keyvault.KeyVaultManagementClient":{ + None: "2016-10-01" + }, + "azure.mgmt.network.NetworkManagementClient": { + None: "2017-10-01" + }, + "azure.mgmt.storage.StorageManagementClient": { + None: "2016-01-01" + }, + "azure.mgmt.resource.policy.PolicyClient": { + None: "2016-12-01" + }, + "azure.mgmt.resource.locks.ManagementLockClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.links.ManagementLinkClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.resources.ResourceManagementClient": { + None: "2018-02-01" + }, + "azure.mgmt.resource.subscriptions.SubscriptionClient": { + None: "2016-06-01" + }, + "azure.mgmt.dns.DnsManagementClient": { + None: "2016-04-01" + } + }, + "2018-03-01-hybrid" + ) + v2019_03_01_hybrid = ProfileDefinition( + { + "azure.keyvault.KeyVaultClient": { + None: "2016-10-01" + }, + "azure.mgmt.authorization.AuthorizationManagementClient": { + None: "2015-07-01" + }, + "azure.mgmt.compute.ComputeManagementClient": { + None: "2017-12-01", + 'resource_skus': '2017-09-01', + 'disks': '2017-03-30', + 'snapshots': '2017-03-30' + }, + "azure.mgmt.keyvault.KeyVaultManagementClient":{ + None: "2016-10-01" + }, + "azure.mgmt.monitor.MonitorManagementClient": { + 'metric_definitions': '2018-01-01', + 'metrics': '2018-01-01', + 'diagnostic_settings': '2017-05-01-preview', + 'diagnostic_settings_category': '2017-05-01-preview', + 'event_categories': '2015-04-01', + 'operations': '2015-04-01', + }, + "azure.mgmt.network.NetworkManagementClient": { + None: "2017-10-01" + }, + "azure.mgmt.storage.StorageManagementClient": { + None: "2017-10-01" + }, + "azure.mgmt.resource.policy.PolicyClient": { + None: "2016-12-01" + }, + "azure.mgmt.resource.locks.ManagementLockClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.links.ManagementLinkClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.resources.ResourceManagementClient": { + None: "2018-05-01" + }, + "azure.mgmt.resource.subscriptions.SubscriptionClient": { + None: "2016-06-01" + }, + "azure.mgmt.dns.DnsManagementClient": { + None: "2016-04-01" + } + }, + "2019-03-01-hybrid" + ) + v2020_09_01_hybrid = ProfileDefinition( + { + "azure.keyvault.KeyVaultClient": { + None: "2016-10-01" + }, + "azure.mgmt.authorization.AuthorizationManagementClient": { + None: "2016-09-01" + }, + "azure.mgmt.compute.ComputeManagementClient": { + None: "2020-06-01", + 'resource_skus': '2019-04-01', + 'disks': '2019-07-01', + 'snapshots': '2019-07-01' + }, + "azure.mgmt.keyvault.KeyVaultManagementClient":{ + None: "2019-09-01" + }, + "azure.mgmt.monitor.MonitorManagementClient": { + 'metric_definitions': '2018-01-01', + 'metrics': '2018-01-01', + 'diagnostic_settings': '2017-05-01-preview', + 'diagnostic_settings_category': '2017-05-01-preview', + 'event_categories': '2015-04-01', + 'operations': '2015-04-01', + }, + "azure.mgmt.network.NetworkManagementClient": { + None: "2018-11-01" + }, + "azure.mgmt.storage.StorageManagementClient": { + None: "2019-06-01" + }, + "azure.mgmt.resource.policy.PolicyClient": { + None: "2016-12-01" + }, + "azure.mgmt.resource.locks.ManagementLockClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.links.ManagementLinkClient": { + None: "2016-09-01" + }, + "azure.mgmt.resource.resources.ResourceManagementClient": { + None: "2019-10-01" + }, + "azure.mgmt.resource.subscriptions.SubscriptionClient": { + None: "2016-06-01" + }, + "azure.mgmt.dns.DnsManagementClient": { + None: "2016-04-01" + } + }, + "2020-09-01-hybrid" + ) + + + def __init__(self, profile_definition): + self._profile_definition = profile_definition + + def use(self, profile): + if self is not type(self).default: + raise ValueError("use can only be used for `default` profile") + self.value.use(profile) + + def definition(self): + if self is not type(self).default: + raise ValueError("use can only be used for `default` profile") + return self.value.definition() + + @classmethod + def from_name(cls, profile_name): + if profile_name == "default": + return cls.default + for profile in cls: + if isinstance(profile.value, ProfileDefinition) and profile.value.label == profile_name: + return profile + raise ValueError("No profile called {}".format(profile_name)) + + +# Default profile is floating "latest" +KnownProfiles.default.use(KnownProfiles.latest) diff --git a/.venv/lib/python3.12/site-packages/azure/profiles/multiapiclient.py b/.venv/lib/python3.12/site-packages/azure/profiles/multiapiclient.py new file mode 100644 index 00000000..e967b1cf --- /dev/null +++ b/.venv/lib/python3.12/site-packages/azure/profiles/multiapiclient.py @@ -0,0 +1,91 @@ +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- +from . import KnownProfiles, ProfileDefinition + +class InvalidMultiApiClientError(Exception): + """If the mixin is not used with a compatible class. + """ + pass + +class MultiApiClientMixin(object): + """Mixin that contains multi-api version profile management. + + To use this mixin, a client must define two class attributes: + - LATEST_PROFILE : a ProfileDefinition correspond to latest profile + - _PROFILE_TAG : a tag that filter a full profile for this particular client + + This should not be used directly and will only provide private methods. + """ + + def __init__(self, *args, **kwargs): + # Consume "api_version" and "profile", to avoid sending them to base class + api_version = kwargs.pop("api_version", None) + profile = kwargs.pop("profile", KnownProfiles.default) + + # Can't do "super" call here all the time, or I would break old client with: + # TypeError: object.__init__() takes no parameters + # So I try to detect if I correctly use this class as a Mixin, or the messed-up + # approach like before. If I think it's the messed-up old approach, + # don't call super + if args or "creds" in kwargs or "config" in kwargs: + super(MultiApiClientMixin, self).__init__(*args, **kwargs) + + try: + type(self).LATEST_PROFILE + except AttributeError: + raise InvalidMultiApiClientError("To use this mixin, main client MUST define LATEST_PROFILE class attribute") + + try: + type(self)._PROFILE_TAG + except AttributeError: + raise InvalidMultiApiClientError("To use this mixin, main client MUST define _PROFILE_TAG class attribute") + + if api_version and profile is not KnownProfiles.default: + raise ValueError("Cannot use api-version and profile parameters at the same time") + + if api_version: + self.profile = ProfileDefinition({ + self._PROFILE_TAG: { + None: api_version + }}, + self._PROFILE_TAG + " " + api_version + ) + elif isinstance(profile, dict): + self.profile = ProfileDefinition({ + self._PROFILE_TAG: profile, + }, + self._PROFILE_TAG + " dict" + ) + if api_version: + self.profile._profile_dict[self._PROFILE_TAG][None] = api_version + else: + self.profile = profile + + def _get_api_version(self, operation_group_name): + current_profile = self.profile + if self.profile is KnownProfiles.default: + current_profile = KnownProfiles.default.value.definition() + + if current_profile is KnownProfiles.latest: + current_profile = self.LATEST_PROFILE + elif isinstance(current_profile, KnownProfiles): + current_profile = current_profile.value + elif isinstance(current_profile, ProfileDefinition): + pass # I expect that + else: + raise ValueError("Cannot determine a ProfileDefinition from {}".format(self.profile)) + + local_profile_dict = current_profile.get_profile_dict() + if self._PROFILE_TAG not in local_profile_dict: + raise ValueError("This profile doesn't define {}".format(self._PROFILE_TAG)) + + local_profile = local_profile_dict[self._PROFILE_TAG] + if operation_group_name in local_profile: + return local_profile[operation_group_name] + try: + return local_profile[None] + except KeyError: + raise ValueError("This profile definition does not contain a default API version") |
