mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-01 12:21:48 -05:00
add api for testing credential plugins
This commit is contained in:
@@ -1419,6 +1419,32 @@ class CredentialCopy(CopyAPIView):
|
||||
copy_return_serializer_class = serializers.CredentialSerializer
|
||||
|
||||
|
||||
class CredentialExternalTest(SubDetailAPIView):
|
||||
"""
|
||||
Test updates to the input values of an external credential before
|
||||
saving them.
|
||||
"""
|
||||
|
||||
view_name = _('External Credential Test')
|
||||
|
||||
model = models.Credential
|
||||
serializer_class = serializers.EmptySerializer
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
test_inputs = {}
|
||||
for field_name, value in request.data.get('inputs', {}).items():
|
||||
if value == '$encrypted$':
|
||||
test_inputs[field_name] = obj.get_input(field_name)
|
||||
else:
|
||||
test_inputs[field_name] = value
|
||||
try:
|
||||
obj.credential_type.plugin.backend(None, **test_inputs)
|
||||
return Response({}, status=status.HTTP_202_ACCEPTED)
|
||||
except Exception as exc:
|
||||
return Response({'inputs': str(exc)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class CredentialInputSourceDetail(RetrieveUpdateDestroyAPIView):
|
||||
|
||||
view_name = _("Credential Input Source Detail")
|
||||
@@ -1446,6 +1472,27 @@ class CredentialInputSourceSubList(SubListCreateAttachDetachAPIView):
|
||||
parent_key = 'target_credential'
|
||||
|
||||
|
||||
class CredentialTypeExternalTest(SubDetailAPIView):
|
||||
"""
|
||||
Test a complete set of input values for an external credential before
|
||||
saving it.
|
||||
"""
|
||||
|
||||
view_name = _('External Credential Type Test')
|
||||
|
||||
model = models.CredentialType
|
||||
serializer_class = serializers.EmptySerializer
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
test_inputs = request.data.get('inputs', {})
|
||||
try:
|
||||
obj.plugin.backend(None, **test_inputs)
|
||||
return Response({}, status=status.HTTP_202_ACCEPTED)
|
||||
except Exception as exc:
|
||||
return Response({'inputs': str(exc)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class HostRelatedSearchMixin(object):
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user