mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
Introduce a new CredentialTemplate model
Credentials now have a required CredentialType, which defines inputs (i.e., username, password) and injectors (i.e., assign the username to SOME_ENV_VARIABLE at job runtime) This commit only implements the model changes necessary to support the new inputs model, and includes code for the credential serializer that allows backwards-compatible support for /api/v1/credentials/; tasks.py still needs to be updated to actually respect CredentialType injectors. This change *will* break the UI for credentials (because it needs to be updated to use the new v2 endpoint). see: #5877 see: #5876 see: #5805
This commit is contained in:
@@ -229,10 +229,8 @@ class PasswordFieldsModel(BaseModel):
|
||||
setattr(self, field, '')
|
||||
else:
|
||||
ask = self._password_field_allows_ask(field)
|
||||
encrypted = encrypt_field(self, field, ask)
|
||||
setattr(self, field, encrypted)
|
||||
if field not in update_fields:
|
||||
update_fields.append(field)
|
||||
self.encrypt_field(field, ask)
|
||||
self.mark_field_for_save(update_fields, field)
|
||||
super(PasswordFieldsModel, self).save(*args, **kwargs)
|
||||
# After saving a new instance for the first time, set the password
|
||||
# fields and save again.
|
||||
@@ -241,9 +239,17 @@ class PasswordFieldsModel(BaseModel):
|
||||
for field in self.PASSWORD_FIELDS:
|
||||
saved_value = getattr(self, '_saved_%s' % field, '')
|
||||
setattr(self, field, saved_value)
|
||||
update_fields.append(field)
|
||||
self.mark_field_for_save(update_fields, field)
|
||||
self.save(update_fields=update_fields)
|
||||
|
||||
def encrypt_field(self, field, ask):
|
||||
encrypted = encrypt_field(self, field, ask)
|
||||
setattr(self, field, encrypted)
|
||||
|
||||
def mark_field_for_save(self, update_fields, field):
|
||||
if field not in update_fields:
|
||||
update_fields.append(field)
|
||||
|
||||
|
||||
class PrimordialModel(CreatedModifiedModel):
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user