diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-09-27 20:28:50 +0300 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2017-10-05 16:25:27 +0300 |
commit | d0572d9aad2c434a040f11956a4c3feac1afdcf8 (patch) | |
tree | 9d3620b23483910815915c995d3f01b659660021 /app/models | |
parent | 328f4a505bcd2e7b38f907a24df437f8c35bc3af (diff) |
Refactor the extraction and generation of GPG subkeys
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/gpg_key.rb | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 110ff4ee59c..ed09b44027c 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -20,8 +20,7 @@ class GpgKey < ActiveRecord::Base format: { with: /\A#{KEY_PREFIX}((?!#{KEY_PREFIX})(?!#{KEY_SUFFIX}).)+#{KEY_SUFFIX}\Z/m, message: "is invalid. A valid public GPG key begins with '#{KEY_PREFIX}' and ends with '#{KEY_SUFFIX}'" - }, - unless: :parent_id? + } validates :fingerprint, presence: true, @@ -37,9 +36,9 @@ class GpgKey < ActiveRecord::Base # the error about the fingerprint unless: -> { errors.has_key?(:key) } - before_validation :extract_fingerprint, :extract_primary_keyid, unless: :parent_id? + before_validation :extract_fingerprint, :extract_primary_keyid after_commit :update_invalid_gpg_signatures, on: :create - after_save :generate_subkeys, unless: :parent_id? + after_create :generate_subkeys def primary_keyid super&.upcase @@ -49,10 +48,6 @@ class GpgKey < ActiveRecord::Base super&.upcase end - def key - parent_id? ? parent.key : super - end - def key=(value) super(value&.strip) end @@ -119,13 +114,7 @@ class GpgKey < ActiveRecord::Base gpg_subkeys = Gitlab::Gpg.subkeys_from_key(key) gpg_subkeys[primary_keyid].each do |subkey_data| - unless subkeys.where(fingerprint: subkey_data[:fingerprint]).exists? - subkeys.create!( - user: user, - primary_keyid: subkey_data[:keyid], - fingerprint: subkey_data[:fingerprint] - ) - end + subkeys.create!(keyid: subkey_data[:keyid], fingerprint: subkey_data[:fingerprint]) end end end |