Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New import feature: update existing keys by name instead of create ne… #53

Merged
merged 1 commit into from Dec 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 38 additions & 17 deletions app/models/vault/key.rb
Expand Up @@ -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

Expand All @@ -54,4 +75,4 @@ def whitelisted?(user,project)
class Vault::KeysVaultTags < ActiveRecord::Base
end

end
end