Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade azure-mgmt-keyvault to 10.0.0 #959

Merged
merged 10 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions plugins/modules/azure_rm_keyvault.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.polling import LROPoller
from azure.core.exceptions import ResourceNotFoundError
from azure.mgmt.keyvault import KeyVaultManagementClient
from msrest.polling import LROPoller
from msrest.serialization import Model
except ImportError:
# This is handled in azure_rm_common
Expand Down Expand Up @@ -343,6 +343,7 @@ def exec_module(self, **kwargs):

self.mgmt_client = self.get_mgmt_svc_client(KeyVaultManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version="2019-09-01")

resource_group = self.get_resource_group(self.resource_group)
Expand Down Expand Up @@ -484,13 +485,13 @@ def create_update_keyvault(self):
self.log("Creating / Updating the Key Vault instance {0}".format(self.vault_name))

try:
response = self.mgmt_client.vaults.create_or_update(resource_group_name=self.resource_group,
vault_name=self.vault_name,
parameters=self.parameters)
response = self.mgmt_client.vaults.begin_create_or_update(resource_group_name=self.resource_group,
vault_name=self.vault_name,
parameters=self.parameters)
if isinstance(response, LROPoller):
response = self.get_poller_result(response)

except CloudError as exc:
except Exception as exc:
self.log('Error attempting to create the Key Vault instance.')
self.fail("Error creating the Key Vault instance: {0}".format(str(exc)))
return response.as_dict()
Expand All @@ -505,7 +506,7 @@ def delete_keyvault(self):
try:
response = self.mgmt_client.vaults.delete(resource_group_name=self.resource_group,
vault_name=self.vault_name)
except CloudError as e:
except Exception as e:
self.log('Error attempting to delete the Key Vault instance.')
self.fail("Error deleting the Key Vault instance: {0}".format(str(e)))

Expand All @@ -525,7 +526,7 @@ def get_keyvault(self):
found = True
self.log("Response : {0}".format(response))
self.log("Key Vault instance : {0} found".format(response.name))
except CloudError as e:
except ResourceNotFoundError as e:
self.log('Did not find the Key Vault instance.')
if found is True:
return response.as_dict()
Expand Down
11 changes: 6 additions & 5 deletions plugins/modules/azure_rm_keyvault_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@

try:
from azure.mgmt.keyvault import KeyVaultManagementClient
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -226,7 +226,7 @@ def keyvault_to_dict(vault):
) for policy in vault.properties.access_policies] if vault.properties.access_policies else None,
sku=dict(
family=vault.properties.sku.family,
name=vault.properties.sku.name.name
name=vault.properties.sku.name
)
)

Expand Down Expand Up @@ -261,6 +261,7 @@ def exec_module(self, **kwargs):

self._client = self.get_mgmt_svc_client(KeyVaultManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version="2019-09-01")

if self.name:
Expand Down Expand Up @@ -291,7 +292,7 @@ def get_by_name(self):

if response and self.has_tags(response.tags, self.tags):
results.append(keyvault_to_dict(response))
except CloudError as e:
except ResourceNotFoundError as e:
self.log("Did not find the key vault {0}: {1}".format(self.name, str(e)))
return results

Expand All @@ -312,7 +313,7 @@ def list_by_resource_group(self):
for item in response:
if self.has_tags(item.tags, self.tags):
results.append(keyvault_to_dict(item))
except CloudError as e:
except Exception as e:
self.log("Did not find key vaults in resource group {0} : {1}.".format(self.resource_group, str(e)))
return results

Expand All @@ -334,7 +335,7 @@ def list(self):
if self.has_tags(item.tags, self.tags):
source_id = item.id.split('/')
results.append(keyvault_to_dict(self._client.vaults.get(source_id[4], source_id[8])))
except CloudError as e:
except Exception as e:
self.log("Did not find key vault in current subscription {0}.".format(str(e)))
return results

Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ azure-mgmt-containerservice==20.0.0
azure-mgmt-datalake-store==1.0.0
azure-mgmt-datafactory==2.0.0
azure-mgmt-dns==8.0.0
azure-mgmt-keyvault==2.2.0
azure-mgmt-marketplaceordering==0.1.0
azure-mgmt-monitor==3.0.0
azure-mgmt-managedservices==6.0.0
Expand All @@ -39,6 +38,7 @@ azure-storage-blob==12.11.0
msrest==0.6.21
msrestazure==0.6.4
azure-keyvault==1.0.0a1
azure-mgmt-keyvault==10.0.0
azure-graphrbac==0.61.1
azure-mgmt-cosmosdb==0.15.0
azure-mgmt-hdinsight==9.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
vault_tenant: "{{ tenant_id }}"
sku:
name: standard
family: A
access_policies:
- tenant_id: "{{ tenant_id }}"
object_id: "{{ object_id }}"
Expand Down