mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 03:40:42 -03:30
parent
32de723c6d
commit
0b6c43dac0
@ -43,7 +43,6 @@ class V1CredentialFilterBackend(BaseFilterBackend):
|
||||
from awx.api.versioning import get_request_version
|
||||
if get_request_version(request) == 1:
|
||||
queryset = queryset.filter(credential_type__managed_by_tower=True)
|
||||
queryset = queryset.filter(~Q(credential_type__kind='insights'))
|
||||
return queryset
|
||||
|
||||
|
||||
|
||||
@ -59,6 +59,7 @@ class V1Credential(object):
|
||||
('azure', 'Microsoft Azure Classic (deprecated)'),
|
||||
('azure_rm', 'Microsoft Azure Resource Manager'),
|
||||
('openstack', 'OpenStack'),
|
||||
('insights', 'Insights'),
|
||||
]
|
||||
FIELDS = {
|
||||
'kind': models.CharField(
|
||||
@ -480,7 +481,7 @@ class CredentialType(CommonModelNameNotUnique):
|
||||
requirements['kind'] = 'vault'
|
||||
else:
|
||||
requirements['kind'] = 'ssh'
|
||||
elif kind in ('net', 'scm'):
|
||||
elif kind in ('net', 'scm', 'insights'):
|
||||
requirements['kind'] = kind
|
||||
elif kind in kind_choices:
|
||||
requirements.update(dict(
|
||||
|
||||
@ -68,7 +68,7 @@ def test_filter_by_v1_kind_with_vault(get, admin, organization):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_insights_credentials_not_in_v1_api_list(get, admin, organization):
|
||||
def test_insights_credentials_in_v1_api_list(get, admin, organization):
|
||||
credential_type = CredentialType.defaults['insights']()
|
||||
credential_type.save()
|
||||
cred = Credential(
|
||||
@ -87,7 +87,34 @@ def test_insights_credentials_not_in_v1_api_list(get, admin, organization):
|
||||
admin
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.data['count'] == 0
|
||||
assert response.data['count'] == 1
|
||||
cred = response.data['results'][0]
|
||||
assert cred['kind'] == 'insights'
|
||||
assert cred['username'] == 'joe'
|
||||
assert cred['password'] == '$encrypted$'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_create_insights_credentials_in_v1(get, post, admin, organization):
|
||||
credential_type = CredentialType.defaults['insights']()
|
||||
credential_type.save()
|
||||
|
||||
response = post(
|
||||
reverse('api:credential_list', kwargs={'version': 'v1'}),
|
||||
{
|
||||
'name': 'Best Credential Ever',
|
||||
'organization': organization.id,
|
||||
'kind': 'insights',
|
||||
'username': 'joe',
|
||||
'password': 'secret'
|
||||
},
|
||||
admin
|
||||
)
|
||||
assert response.status_code == 201
|
||||
cred = Credential.objects.get(pk=response.data['id'])
|
||||
assert cred.username == 'joe'
|
||||
assert decrypt_field(cred, 'password') == 'secret'
|
||||
assert cred.credential_type == credential_type
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user