From 086ae8f9add9c9e1897368b0b148cbf4cc602991 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Mon, 27 Apr 2015 13:31:57 -0400 Subject: [PATCH] allow credential_id to job template launch. Funnel credential_id into credential. --- awx/api/views.py | 3 +++ awx/main/tests/jobs/jobs_monolithic.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/awx/api/views.py b/awx/api/views.py index 1a684c4e5e..3c87ba613f 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -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) diff --git a/awx/main/tests/jobs/jobs_monolithic.py b/awx/main/tests/jobs/jobs_monolithic.py index 65d0e7aa66..b4c6c554f6 100644 --- a/awx/main/tests/jobs/jobs_monolithic.py +++ b/awx/main/tests/jobs/jobs_monolithic.py @@ -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):