mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
prefetch related source credentials in tasks.py
This commit is contained in:
committed by
Jake McDermott
parent
42f4956a7f
commit
81a509424a
@@ -819,7 +819,7 @@ class BaseTask(object):
|
|||||||
private_data_files['credentials'][credential] = path
|
private_data_files['credentials'][credential] = path
|
||||||
for credential, data in private_data.get('certificates', {}).items():
|
for credential, data in private_data.get('certificates', {}).items():
|
||||||
name = 'credential_%d-cert.pub' % credential.pk
|
name = 'credential_%d-cert.pub' % credential.pk
|
||||||
path = os.path.join(kwargs['private_data_dir'], name)
|
path = os.path.join(private_data_dir, name)
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
@@ -1290,7 +1290,7 @@ class RunJob(BaseTask):
|
|||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
private_data = {'credentials': {}}
|
private_data = {'credentials': {}}
|
||||||
for credential in job.credentials.all():
|
for credential in job.credentials.prefetch_related('input_sources__source_credential').all():
|
||||||
# If we were sent SSH credentials, decrypt them and send them
|
# If we were sent SSH credentials, decrypt them and send them
|
||||||
# back (they will be written to a temporary file).
|
# back (they will be written to a temporary file).
|
||||||
if credential.has_input('ssh_key_data'):
|
if credential.has_input('ssh_key_data'):
|
||||||
@@ -1521,7 +1521,7 @@ class RunJob(BaseTask):
|
|||||||
return self._write_extra_vars_file(private_data_dir, extra_vars, safe_dict)
|
return self._write_extra_vars_file(private_data_dir, extra_vars, safe_dict)
|
||||||
|
|
||||||
def build_credentials_list(self, job):
|
def build_credentials_list(self, job):
|
||||||
return job.credentials.all()
|
return job.credentials.prefetch_related('input_sources__source_credential').all()
|
||||||
|
|
||||||
def get_password_prompts(self, passwords={}):
|
def get_password_prompts(self, passwords={}):
|
||||||
d = super(RunJob, self).get_password_prompts(passwords)
|
d = super(RunJob, self).get_password_prompts(passwords)
|
||||||
|
|||||||
@@ -700,7 +700,8 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
__iter__ = lambda *args: iter(job._credentials),
|
__iter__ = lambda *args: iter(job._credentials),
|
||||||
first = lambda: job._credentials[0]
|
first = lambda: job._credentials[0]
|
||||||
),
|
),
|
||||||
'spec_set': ['all', 'add', 'filter']
|
'prefetch_related': lambda _: credentials_mock,
|
||||||
|
'spec_set': ['all', 'add', 'filter', 'prefetch_related'],
|
||||||
})
|
})
|
||||||
|
|
||||||
with mock.patch.object(UnifiedJob, 'credentials', credentials_mock):
|
with mock.patch.object(UnifiedJob, 'credentials', credentials_mock):
|
||||||
|
|||||||
Reference in New Issue
Block a user