diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-09-28 03:45:19 +0300 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2017-10-05 16:25:27 +0300 |
commit | 9b4990a4d71b057f0fec14399cd1f2a421901963 (patch) | |
tree | e6e522b10f17325d0a8fcc86a2020210f285086b /app/models | |
parent | a41e7e0105e238161ba697ebf26d8554ae59d295 (diff) |
Associate GgpSignature with GpgKeySubkey if comes from a subkey
Additionally we're delegating missing method calls on GpgKeySubkey to
GpgKey since most of the info required when verifying a signature is
found on GpgKey which is the parent of GpgKeySubkey
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/gpg_key.rb | 11 | ||||
-rw-r--r-- | app/models/gpg_key_subkey.rb | 15 | ||||
-rw-r--r-- | app/models/gpg_signature.rb | 16 |
3 files changed, 31 insertions, 11 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 6d3537b6fcf..ed09b44027c 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -40,17 +40,6 @@ class GpgKey < ActiveRecord::Base after_commit :update_invalid_gpg_signatures, on: :create after_create :generate_subkeys - def self.find_with_subkeys(fingerprint) - keys_table = arel_table - subkeys_table = GpgKeySubkey.arel_table - - condition = keys_table[:primary_keyid].eq(fingerprint).or( - subkeys_table[:keyid].eq(fingerprint) - ) - - joins(:subkeys).where(condition).first - end - def primary_keyid super&.upcase end diff --git a/app/models/gpg_key_subkey.rb b/app/models/gpg_key_subkey.rb index 4f967f1e47c..8222e5606aa 100644 --- a/app/models/gpg_key_subkey.rb +++ b/app/models/gpg_key_subkey.rb @@ -1,3 +1,18 @@ class GpgKeySubkey < ActiveRecord::Base + include ShaAttribute + + sha_attribute :keyid + sha_attribute :fingerprint + belongs_to :gpg_key + + def method_missing(m, *a, &b) + return super unless gpg_key.respond_to?(m) + + gpg_key.public_send(m, *a, &b) # rubocop:disable GitlabSecurity/PublicSend + end + + def respond_to_missing?(method, include_private = false) + gpg_key.respond_to?(method, include_private) || super + end end diff --git a/app/models/gpg_signature.rb b/app/models/gpg_signature.rb index 1f047a32c84..c7f75288407 100644 --- a/app/models/gpg_signature.rb +++ b/app/models/gpg_signature.rb @@ -15,11 +15,27 @@ class GpgSignature < ActiveRecord::Base belongs_to :project belongs_to :gpg_key + belongs_to :gpg_key_subkey validates :commit_sha, presence: true validates :project_id, presence: true validates :gpg_key_primary_keyid, presence: true + def gpg_key=(model) + case model + when GpgKey then super + when GpgKeySubkey then write_attribute(:gpg_key_subkey_id, model.id) + end + end + + def gpg_key + if gpg_key_id + super + elsif gpg_key_subkey_id + gpg_key_subkey + end + end + def gpg_key_primary_keyid super&.upcase end |