mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 13:11:19 -03:30
allow credential_id to job template launch. Funnel credential_id into credential.
This commit is contained in:
parent
d0f05ac2cd
commit
086ae8f9ad
@ -1445,6 +1445,9 @@ class JobTemplateLaunch(RetrieveAPIView, GenericAPIView):
|
||||
if not request.user.can_access(self.model, 'start', obj):
|
||||
raise PermissionDenied()
|
||||
|
||||
if 'credential' not in request.DATA and 'credential_id' in request.DATA:
|
||||
request.DATA['credential'] = request.DATA['credential_id']
|
||||
|
||||
serializer = self.serializer_class(data=request.DATA, context={'obj': obj})
|
||||
if not serializer.is_valid():
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -482,24 +482,37 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
|
||||
# Invalid auth can't trigger the launch endpoint
|
||||
self.check_invalid_auth(launch_url, {}, methods=('post',))
|
||||
|
||||
# Implicit, attached credentials
|
||||
with self.current_user(self.user_sue):
|
||||
response = self.post(launch_url, {}, expect=202)
|
||||
j = Job.objects.get(pk=response['job'])
|
||||
self.assertTrue(j.status == 'new')
|
||||
|
||||
# Explicit, override credentials
|
||||
with self.current_user(self.user_sue):
|
||||
response = self.post(launch_url, {'credential': self.cred_doug.pk}, expect=202)
|
||||
j = Job.objects.get(pk=response['job'])
|
||||
self.assertTrue(j.status == 'new')
|
||||
self.assertEqual(j.credential.pk, self.cred_doug.pk)
|
||||
|
||||
# Explicit, override credentials
|
||||
with self.current_user(self.user_sue):
|
||||
response = self.post(launch_url, {'credential_id': self.cred_doug.pk}, expect=202)
|
||||
j = Job.objects.get(pk=response['job'])
|
||||
self.assertTrue(j.status == 'new')
|
||||
self.assertEqual(j.credential.pk, self.cred_doug.pk)
|
||||
|
||||
# Can't launch a job template without a credential defined (or if we
|
||||
# pass an invalid/inactive credential value).
|
||||
with self.current_user(self.user_sue):
|
||||
response = self.post(no_launch_url, {}, expect=400)
|
||||
response = self.post(no_launch_url, {'credential': 0}, expect=400)
|
||||
response = self.post(no_launch_url, {'credential_id': 0}, expect=400)
|
||||
response = self.post(no_launch_url, {'credential': 'one'}, expect=400)
|
||||
response = self.post(no_launch_url, {'credential_id': 'one'}, expect=400)
|
||||
self.cred_doug.mark_inactive()
|
||||
response = self.post(no_launch_url, {'credential': self.cred_doug.pk}, expect=400)
|
||||
response = self.post(no_launch_url, {'credential_id': self.cred_doug.pk}, expect=400)
|
||||
|
||||
# Job Templates without projects can not be launched
|
||||
with self.current_user(self.user_sue):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user