mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-13 03:21:49 -05:00
Merge pull request #6968 from ryanpetrello/fix-6959
fix a few issues in credential type kind validation
This commit is contained in:
@@ -17,7 +17,7 @@ from rest_framework.relations import RelatedField, ManyRelatedField
|
||||
from rest_framework.request import clone_request
|
||||
|
||||
# Ansible Tower
|
||||
from awx.main.models import InventorySource, NotificationTemplate
|
||||
from awx.main.models import InventorySource, NotificationTemplate, CredentialType
|
||||
|
||||
|
||||
class Metadata(metadata.SimpleMetadata):
|
||||
@@ -149,6 +149,16 @@ class Metadata(metadata.SimpleMetadata):
|
||||
if field == 'type' and hasattr(serializer, 'get_type_choices'):
|
||||
meta['choices'] = serializer.get_type_choices()
|
||||
|
||||
# API-created/modified CredentialType kinds are limited to
|
||||
# `cloud` and `network`
|
||||
if method != 'GET' and \
|
||||
hasattr(serializer, 'Meta') and \
|
||||
getattr(serializer.Meta, 'model', None) is CredentialType:
|
||||
actions[method]['kind']['choices'] = filter(
|
||||
lambda choice: choice[0] in ('cloud', 'net'),
|
||||
actions[method]['kind']['choices']
|
||||
)
|
||||
|
||||
# For GET method, remove meta attributes that aren't relevant
|
||||
# when reading a field and remove write-only fields.
|
||||
if method == 'GET':
|
||||
|
||||
@@ -1904,9 +1904,9 @@ class CredentialTypeSerializer(BaseSerializer):
|
||||
)
|
||||
ret = super(CredentialTypeSerializer, self).validate(attrs)
|
||||
|
||||
if 'kind' in attrs and attrs['kind'] not in ('cloud', 'network'):
|
||||
if 'kind' in attrs and attrs['kind'] not in ('cloud', 'net'):
|
||||
raise serializers.ValidationError({
|
||||
"kind": _("Must be 'cloud' or 'network', not %s") % attrs['kind']
|
||||
"kind": _("Must be 'cloud' or 'net', not %s") % attrs['kind']
|
||||
})
|
||||
|
||||
fields = attrs.get('inputs', {}).get('fields', [])
|
||||
|
||||
Reference in New Issue
Block a user