From f1b37ff53a5a2174123984f1127e528d39e8acfc Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Mon, 23 Apr 2018 10:19:07 -0400 Subject: [PATCH] Fix order become methods render and migration query --- awx/api/serializers.py | 11 ++++++++++- awx/main/constants.py | 5 +++-- awx/main/migrations/_credentialtypes.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 0c887da968..955abb9b74 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -38,7 +38,13 @@ from rest_framework.utils.serializer_helpers import ReturnList from polymorphic.models import PolymorphicModel # AWX -from awx.main.constants import SCHEDULEABLE_PROVIDERS, ANSI_SGR_PATTERN, ACTIVE_STATES, TOKEN_CENSOR +from awx.main.constants import ( + SCHEDULEABLE_PROVIDERS, + ANSI_SGR_PATTERN, + ACTIVE_STATES, + TOKEN_CENSOR, + CHOICES_PRIVILEGE_ESCALATION_METHODS, +) from awx.main.models import * # noqa from awx.main.models.base import NEW_JOB_TYPE_CHOICES from awx.main.access import get_user_capabilities @@ -2494,6 +2500,9 @@ class CredentialTypeSerializer(BaseSerializer): field['label'] = _(field['label']) if 'help_text' in field: field['help_text'] = _(field['help_text']) + if field['type'] == 'become_method': + field.pop('type') + field['choices'] = map(operator.itemgetter(0), CHOICES_PRIVILEGE_ESCALATION_METHODS) return value def filter_field_metadata(self, fields, method): diff --git a/awx/main/constants.py b/awx/main/constants.py index e966d4b72a..e7c8a943fc 100644 --- a/awx/main/constants.py +++ b/awx/main/constants.py @@ -14,9 +14,10 @@ __all__ = [ CLOUD_PROVIDERS = ('azure_rm', 'ec2', 'gce', 'vmware', 'openstack', 'rhv', 'satellite6', 'cloudforms', 'tower') SCHEDULEABLE_PROVIDERS = CLOUD_PROVIDERS + ('custom', 'scm',) PRIVILEGE_ESCALATION_METHODS = [ - ('enable', _('Enable')), ('doas', _('Doas')), ('sudo', _('Sudo')), ('su', _('Su')), ('pbrun', _('Pbrun')), ('pfexec', _('Pfexec')), - ('dzdo', _('DZDO')), ('pmrun', _('Pmrun')), ('runas', _('Runas'))] + ('dzdo', _('DZDO')), ('pmrun', _('Pmrun')), ('runas', _('Runas')), + ('enable', _('Enable')), ('doas', _('Doas')), +] CHOICES_PRIVILEGE_ESCALATION_METHODS = [('', _('None'))] + PRIVILEGE_ESCALATION_METHODS ANSI_SGR_PATTERN = re.compile(r'\x1b\[[0-9;]*m') CAN_CANCEL = ('new', 'pending', 'waiting', 'running') diff --git a/awx/main/migrations/_credentialtypes.py b/awx/main/migrations/_credentialtypes.py index 6d71776d6b..fbf812e8c2 100644 --- a/awx/main/migrations/_credentialtypes.py +++ b/awx/main/migrations/_credentialtypes.py @@ -200,6 +200,6 @@ def add_azure_cloud_environment_field(apps, schema_editor): def remove_become_methods(apps, schema_editor): - become_credtype = CredentialType.objects.get(kind='ssh').first() + become_credtype = CredentialType.objects.filter(kind='ssh', managed_by_tower=True).first() become_credtype.inputs = CredentialType.defaults.get('ssh')().inputs become_credtype.save()