1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #4021 from ryanpetrello/dotted-vault-id

support vault IDs that include dot characters

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
softwarefactory-project-zuul[bot] 2019-06-06 18:34:24 +00:00 committed by GitHub
commit 9253ab28c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -1467,7 +1467,8 @@ class RunJob(BaseTask):
if k == 'vault_password': if k == 'vault_password':
args.append('--ask-vault-pass') args.append('--ask-vault-pass')
else: else:
vault_id = k.split('.')[1] # split only on the first dot in case the vault ID itself contains a dot
vault_id = k.split('.', 1)[1]
args.append('--vault-id') args.append('--vault-id')
args.append('{}@prompt'.format(vault_id)) args.append('{}@prompt'.format(vault_id))
@ -1533,7 +1534,8 @@ class RunJob(BaseTask):
d[r'Vault password:\s*?$'] = 'vault_password' d[r'Vault password:\s*?$'] = 'vault_password'
for k, v in passwords.items(): for k, v in passwords.items():
if k.startswith('vault_password.'): if k.startswith('vault_password.'):
vault_id = k.split('.')[1] # split only on the first dot in case the vault ID itself contains a dot
vault_id = k.split('.', 1)[1]
d[r'Vault password \({}\):\s*?$'.format(vault_id)] = k d[r'Vault password \({}\):\s*?$'.format(vault_id)] = k
return d return d

View File

@ -872,7 +872,7 @@ class TestJobCredentials(TestJobExecution):
def test_multi_vault_password(self, private_data_dir, job): def test_multi_vault_password(self, private_data_dir, job):
task = tasks.RunJob() task = tasks.RunJob()
vault = CredentialType.defaults['vault']() vault = CredentialType.defaults['vault']()
for i, label in enumerate(['dev', 'prod']): for i, label in enumerate(['dev', 'prod', 'dotted.name']):
credential = Credential( credential = Credential(
pk=i, pk=i,
credential_type=vault, credential_type=vault,
@ -892,10 +892,12 @@ class TestJobCredentials(TestJobExecution):
) )
assert vault_passwords['Vault password \(prod\):\\s*?$'] == 'pass@prod' # noqa assert vault_passwords['Vault password \(prod\):\\s*?$'] == 'pass@prod' # noqa
assert vault_passwords['Vault password \(dev\):\\s*?$'] == 'pass@dev' # noqa assert vault_passwords['Vault password \(dev\):\\s*?$'] == 'pass@dev' # noqa
assert vault_passwords['Vault password \(dotted.name\):\\s*?$'] == 'pass@dotted.name' # noqa
assert vault_passwords['Vault password:\\s*?$'] == '' # noqa assert vault_passwords['Vault password:\\s*?$'] == '' # noqa
assert '--ask-vault-pass' not in ' '.join(args) assert '--ask-vault-pass' not in ' '.join(args)
assert '--vault-id dev@prompt' in ' '.join(args) assert '--vault-id dev@prompt' in ' '.join(args)
assert '--vault-id prod@prompt' in ' '.join(args) assert '--vault-id prod@prompt' in ' '.join(args)
assert '--vault-id dotted.name@prompt' in ' '.join(args)
def test_multi_vault_id_conflict(self, job): def test_multi_vault_id_conflict(self, job):
task = tasks.RunJob() task = tasks.RunJob()