diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-06-15 13:37:03 +0200 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 15:42:53 +0200 |
commit | 502e31bec9af080bcb483b0d57c8b52aeb507f93 (patch) | |
tree | ecf432badf0fc68c10b0cb78ac0153ec75e6c0d0 /lib/gitlab/gpg | |
parent | 5d5fd4babe4cb75c7f8f9f18cc86c63a0fa58d16 (diff) | |
download | gitlab-ce-502e31bec9af080bcb483b0d57c8b52aeb507f93.tar.gz |
memoize verified_signature call
Diffstat (limited to 'lib/gitlab/gpg')
-rw-r--r-- | lib/gitlab/gpg/commit.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb index 8d2e6269618..8bc430db715 100644 --- a/lib/gitlab/gpg/commit.rb +++ b/lib/gitlab/gpg/commit.rb @@ -19,6 +19,19 @@ module Gitlab cached_signature = GpgSignature.find_by(commit_sha: commit.sha) return cached_signature if cached_signature.present? + using_keychain do |gpg_key| + if gpg_key + Gitlab::Gpg::CurrentKeyChain.add(gpg_key.key) + @verified_signature = nil + end + + create_cached_signature!(gpg_key) + end + end + + private + + def using_keychain Gitlab::Gpg.using_tmp_keychain do # first we need to get the keyid from the signature to query the gpg # key belonging to the keyid. @@ -30,27 +43,23 @@ module Gitlab Gitlab::Gpg::CurrentKeyChain.add(gpg_key.key) end - create_cached_signature!(gpg_key) + yield gpg_key end end - private - def verified_signature - GPGME::Crypto.new.verify(@signature_text, signed_text: @signed_text) do |verified_signature| + @verified_signature ||= GPGME::Crypto.new.verify(@signature_text, signed_text: @signed_text) do |verified_signature| return verified_signature end end def create_cached_signature!(gpg_key) - verified_signature_result = verified_signature - GpgSignature.create!( commit_sha: commit.sha, project: commit.project, gpg_key: gpg_key, - gpg_key_primary_keyid: gpg_key&.primary_keyid || verified_signature_result.fingerprint, - valid_signature: !!(gpg_key && gpg_key.verified? && verified_signature_result.valid?) + gpg_key_primary_keyid: gpg_key&.primary_keyid || verified_signature.fingerprint, + valid_signature: !!(gpg_key && gpg_key.verified? && verified_signature.valid?) ) end end |