Added option to overwrite existing stored credentials.
Added an option to django_orm.Storage locked_put method to allow for overwriting an existing credential record rather than the creation of a new one.
This commit is contained in:
@@ -116,14 +116,19 @@ class Storage(BaseStorage):
|
||||
credential.set_store(self)
|
||||
return credential
|
||||
|
||||
def locked_put(self, credentials):
|
||||
def locked_put(self, credentials, overwrite=False):
|
||||
"""Write a Credentials to the datastore.
|
||||
|
||||
Args:
|
||||
credentials: Credentials, the credentials to store.
|
||||
"""
|
||||
args = {self.key_name: self.key_value}
|
||||
entity = self.model_class(**args)
|
||||
|
||||
if overwrite:
|
||||
entity, is_new = self.model_class.objects.get_or_create(**args)
|
||||
else:
|
||||
entity = self.model_class(**args)
|
||||
|
||||
setattr(entity, self.property_name, credentials)
|
||||
entity.save()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user