diff --git a/app/models/vault/key.rb b/app/models/vault/key.rb index 516fa07..37eee92 100644 --- a/app/models/vault/key.rb +++ b/app/models/vault/key.rb @@ -24,23 +24,44 @@ def decrypt! def self.import(file) CSV.foreach(file.path, headers:true) do |row| rhash = row.to_hash + decryptb = Encryptor::decrypt(rhash['body']) + + key = Vault::Key.where("name = ?", rhash['name']).first + + unless key + begin + Vault::Key.create( + project_id: rhash['project_id'], + name: rhash['name'], + body: decryptb, + login: rhash['login'], + type: rhash['type'], + file: rhash['file'], + url: rhash['url'], + comment: rhash['comment'], + whitelist: rhash['comment'] + ).update_column(:id, rhash['id']) + rescue - decryptb = Encryptor::decrypt(rhash['body']) - begin - Vault::Key.create( - project_id: rhash['project_id'], - name: rhash['name'], - body: decryptb, - login: rhash['login'], - type: rhash['type'], - file: rhash['file'], - url: rhash['url'], - comment: rhash['comment'], - whitelist: rhash['comment'] - ).update_column(:id, rhash['id']) - rescue - - end + end + else + begin + Vault::Key.update( + key.id, + project_id: rhash['project_id'], + name: rhash['name'], + body: decryptb, + login: rhash['login'], + type: rhash['type'], + file: rhash['file'], + url: rhash['url'], + comment: rhash['comment'], + whitelist: rhash['comment'] + ) + rescue + + end + end end end @@ -54,4 +75,4 @@ def whitelisted?(user,project) class Vault::KeysVaultTags < ActiveRecord::Base end -end \ No newline at end of file +end