diff --git a/awx/main/credential_plugins/aim.py b/awx/main/credential_plugins/aim.py index 74802e2f1c..05d367246d 100644 --- a/awx/main/credential_plugins/aim.py +++ b/awx/main/credential_plugins/aim.py @@ -4,7 +4,7 @@ import os import stat import tempfile import threading -from urllib.parse import quote, urljoin +from urllib.parse import quote, urlencode, urljoin from django.utils.translation import ugettext_lazy as _ import requests @@ -26,30 +26,36 @@ aim_inputs = { 'type': 'string', 'secret': True, 'multiline': True, - 'format': 'ssh_private_key', }, { 'id': 'client_cert', 'label': _('Client Certificate'), 'type': 'string', 'secret': True, 'multiline': True, - 'format': 'ssh_private_key', }, { 'id': 'verify', + 'label': _('Verify SSL Certificates'), 'type': 'boolean', 'default': True, - 'label': _('Verify SSL Certificates'), }], 'metadata': [{ - 'id': 'safe', - 'label': _('Safe'), + 'id': 'object_query', + 'label': _('Object Query'), 'type': 'string', + 'help_text': _('Lookup query for the object. Ex: "Safe=TestSafe;Object=testAccountName123"'), }, { - 'id': 'object', - 'label': _('Object'), + 'id': 'object_query_format', + 'label': _('Object Query Format'), 'type': 'string', + 'default': 'Exact', + 'choices': ['Exact', 'Regexp'] + }, { + 'id': 'reason', + 'label': _('Reason'), + 'type': 'string', + 'help_text': _('Object request reason. This is only needed if it is required by the object\'s policy.') }], - 'required': ['url', 'app_id', 'safe', 'object'], + 'required': ['url', 'app_id', 'query'], } @@ -73,14 +79,23 @@ def create_temporary_fifo(data): def aim_backend(**kwargs): url = kwargs['url'] - verify = kwargs['verify'] client_cert = kwargs.get('client_cert', None) client_key = kwargs.get('client_key', None) - app_id = quote(kwargs['app_id']) - safe = quote(kwargs['safe']) - object_ = quote(kwargs['object']) + verify = kwargs['verify'] + app_id = kwargs['app_id'] + object_query = kwargs['object_query'] + object_query_format = kwargs['object_query_format'] + reason = kwargs.get('reason', None) - request_qs = '?AppId={0}&Safe={1}&object={2}'.format(app_id, safe, object_) + query_params = { + 'AppId': app_id, + 'Query': object_query, + 'QueryFormat': object_query_format, + } + if reason: + query_params['reason'] = reason + + request_qs = '?' + urlencode(query_params, quote_via=quote) request_url = urljoin(url, '/'.join(['AIMWebService', 'api', 'Accounts'])) cert = None