Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #745 from AlanCoding/vault_credential_too
Browse files Browse the repository at this point in the history
Apply deprecated vault_credential field to JTs
  • Loading branch information
AlanCoding authored Jan 14, 2020
2 parents b2d525b + b3d49ce commit 487a1b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/source/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release History
===============

3.3.8 (2020-01-14)
------------------

- Process deprecated vault_credential parameter with extra request

3.3.7 (2019-10-25)
------------------

Expand Down
2 changes: 1 addition & 1 deletion tower_cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


VERSION = '3.3.7'
VERSION = '3.3.8'
# This is the release number for the RPM builds
RELEASE = 1
CUR_API_VERSION = 'v2'
Expand Down
20 changes: 14 additions & 6 deletions tower_cli/resources/job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from tower_cli.exceptions import NotFound


OLD_CRED_FIELDS = ['credential', 'vault_credential']


class Resource(models.SurveyResource):
"""A resource for job templates."""
cli_help = 'Manage job templates.'
Expand Down Expand Up @@ -124,15 +127,20 @@ def write(self, pk=None, *args, **kwargs):
if (kwargs.get('create_on_missing', False) and
(not kwargs.get('job_type', None))):
kwargs['job_type'] = 'run'
mcred = kwargs.get('credential', None)
old_creds = {}
for cred_field in OLD_CRED_FIELDS:
if cred_field in kwargs:
old_creds[cred_field] = kwargs[cred_field]
ret = super(Resource, self).write(pk=pk, **kwargs)
cred_ids = [c['id'] for c in ret.get('summary_fields', {}).get('credentials', [])]
if mcred and mcred not in cred_ids:
new_pk = ret['id']
for cred_field, cred_id in old_creds.items():
if cred_id is None or cred_id in cred_ids:
continue
jt_pk = ret['id']
debug.log('Processing deprecated credential field via another request.', header='details')
self._assoc('credentials', new_pk, mcred)
ret = self.read(new_pk)
ret['id'] = new_pk
self._assoc('credentials', jt_pk, cred_id)
ret = self.read(jt_pk)
ret['id'] = jt_pk
ret['changed'] = True
return ret

Expand Down

0 comments on commit 487a1b9

Please sign in to comment.