summaryrefslogtreecommitdiff
path: root/app/models/gpg_key.rb
diff options
context:
space:
mode:
authorRubén Dávila <ruben@gitlab.com>2017-09-27 12:28:50 -0500
committerRubén Dávila <ruben@gitlab.com>2017-10-05 08:25:27 -0500
commitd0572d9aad2c434a040f11956a4c3feac1afdcf8 (patch)
tree9d3620b23483910815915c995d3f01b659660021 /app/models/gpg_key.rb
parent328f4a505bcd2e7b38f907a24df437f8c35bc3af (diff)
downloadgitlab-ce-d0572d9aad2c434a040f11956a4c3feac1afdcf8.tar.gz
Refactor the extraction and generation of GPG subkeys
Diffstat (limited to 'app/models/gpg_key.rb')
-rw-r--r--app/models/gpg_key.rb19
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