1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fix bulk creation of Secrets via API

This commit is contained in:
Jeremy Stretch
2018-01-02 17:07:21 -05:00
parent e5c13d2d72
commit 9c27d18d6c
3 changed files with 23 additions and 22 deletions

View File

@@ -50,8 +50,15 @@ class WritableSecretSerializer(serializers.ModelSerializer):
def validate(self, data):
# Encrypt plaintext data using the master key provided from the view context
if data.get('plaintext'):
s = Secret(plaintext=data['plaintext'])
s.encrypt(self.context['master_key'])
data['ciphertext'] = s.ciphertext
data['hash'] = s.hash
# Validate uniqueness of name if one has been provided.
if data.get('name', None):
if data.get('name'):
validator = UniqueTogetherValidator(queryset=Secret.objects.all(), fields=('device', 'role', 'name'))
validator.set_context(self)
validator(data)