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

Added content type parameter to azure_rm_keyvaultsecret #317

Merged
merged 3 commits into from
Jan 14, 2021
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
14 changes: 10 additions & 4 deletions plugins/modules/azure_rm_keyvaultsecret.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
description:
- URI of the keyvault endpoint.
required: true
content_type:
description:
- Type of the secret value such as a password.
type: str
secret_name:
description:
- Name of the keyvault secret.
Expand Down Expand Up @@ -101,7 +105,8 @@ def __init__(self):
secret_name=dict(type='str', required=True),
secret_value=dict(type='str', no_log=True),
keyvault_uri=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['present', 'absent'])
state=dict(type='str', default='present', choices=['present', 'absent']),
content_type=dict(type='str')
)

required_if = [
Expand All @@ -120,6 +125,7 @@ def __init__(self):
self.data_creds = None
self.client = None
self.tags = None
self.content_type = None

super(AzureRMKeyVaultSecret, self).__init__(self.module_arg_spec,
supports_check_mode=True,
Expand Down Expand Up @@ -157,7 +163,7 @@ def exec_module(self, **kwargs):
if not self.check_mode:
# Create secret
if self.state == 'present' and changed:
results['secret_id'] = self.create_update_secret(self.secret_name, self.secret_value, self.tags)
results['secret_id'] = self.create_update_secret(self.secret_name, self.secret_value, self.tags, self.content_type)
self.results['state'] = results
self.results['state']['status'] = 'Created'
# Delete secret
Expand Down Expand Up @@ -210,9 +216,9 @@ def get_secret(self, name, version=''):
return dict(secret_id=secret_id.id, secret_value=secret_bundle.value)
return None

def create_update_secret(self, name, secret, tags):
def create_update_secret(self, name, secret, tags, content_type):
''' Creates/Updates a secret '''
secret_bundle = self.client.set_secret(self.keyvault_uri, name, secret, tags)
secret_bundle = self.client.set_secret(self.keyvault_uri, name, secret, tags=tags, content_type=content_type)
secret_id = KeyVaultId.parse_secret_id(secret_bundle.id)
return secret_id.id

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/azure_rm_keyvaultsecret_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
returned: always
type: dict
sample: {"delete": "on-exit"}
type:
content_type:
Fred-sun marked this conversation as resolved.
Show resolved Hide resolved
description:
- Content type (optional)
returned: always
Expand Down Expand Up @@ -187,7 +187,7 @@ def secretbundle_to_dict(bundle):
recovery_level=bundle.attributes.recovery_level),
sid=bundle.id,
version=KeyVaultId.parse_secret_id(bundle.id).version,
type=bundle.content_type,
content_type=bundle.content_type,
secret=bundle.value)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
keyvault_uri: https://vault{{ rpfx }}.vault.azure.net
secret_name: testsecret
secret_value: 'mysecret'
content_type: 'Content Type Secret'
tags:
testing: test
delete: on-exit
Expand All @@ -76,6 +77,7 @@
- facts['secrets'][0]['secret']
- facts['secrets'][0]['tags']
- facts['secrets'][0]['version']
- facts['secrets'][0]['content_type'] == 'Content Type Secret'

- name: delete a kevyault secret
azure_rm_keyvaultsecret:
Expand Down