From aee0a117a889461ce8ced6fcf73207fe017f1d99 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 20 Dec 2021 13:37:47 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-6-stable-ee --- app/models/commit_signatures/gpg_signature.rb | 53 ++++++++++++++++++++++ .../commit_signatures/x509_commit_signature.rb | 16 +++++++ 2 files changed, 69 insertions(+) create mode 100644 app/models/commit_signatures/gpg_signature.rb create mode 100644 app/models/commit_signatures/x509_commit_signature.rb (limited to 'app/models/commit_signatures') 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 diff --git a/app/models/commit_signatures/x509_commit_signature.rb b/app/models/commit_signatures/x509_commit_signature.rb new file mode 100644 index 00000000000..2cbb331dd7e --- /dev/null +++ b/app/models/commit_signatures/x509_commit_signature.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +module CommitSignatures + class X509CommitSignature < ApplicationRecord + include CommitSignature + + belongs_to :x509_certificate, class_name: 'X509Certificate', foreign_key: 'x509_certificate_id', optional: false + + validates :x509_certificate_id, presence: true + + def x509_commit + return unless commit + + Gitlab::X509::Commit.new(commit) + end + end +end -- cgit v1.2.3