diff options
Diffstat (limited to 'app/models/commit_signatures/gpg_signature.rb')
-rw-r--r-- | app/models/commit_signatures/gpg_signature.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/models/commit_signatures/gpg_signature.rb b/app/models/commit_signatures/gpg_signature.rb new file mode 100644 index 00000000000..1ce76b53da4 --- /dev/null +++ b/app/models/commit_signatures/gpg_signature.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true +module CommitSignatures + class GpgSignature < ApplicationRecord + include CommitSignature + + sha_attribute :gpg_key_primary_keyid + + belongs_to :gpg_key + belongs_to :gpg_key_subkey + + validates :gpg_key_primary_keyid, presence: true + + def self.with_key_and_subkeys(gpg_key) + subkey_ids = gpg_key.subkeys.pluck(:id) + + where( + arel_table[:gpg_key_id].eq(gpg_key.id).or( + arel_table[:gpg_key_subkey_id].in(subkey_ids) + ) + ) + end + + def gpg_key=(model) + case model + when GpgKey + super + when GpgKeySubkey + self.gpg_key_subkey = model + when NilClass + super + self.gpg_key_subkey = nil + 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 + + def gpg_commit + return unless commit + + Gitlab::Gpg::Commit.new(commit) + end + end +end |