summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-07-13 15:22:15 +0200
committerAlexis Reigel <mail@koffeinfrei.org>2017-07-27 15:44:39 +0200
commitcd01e82873b3cd471203dbf557c71571fd683d16 (patch)
tree08372f91287ec4c9a14d95044a0eff7fbe8e78c3 /lib
parent506836a695ae40ff200add21c639f3d13aaee9e9 (diff)
downloadgitlab-ce-cd01e82873b3cd471203dbf557c71571fd683d16.tar.gz
store gpg user name and email on the signature
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/gpg.rb6
-rw-r--r--lib/gitlab/gpg/commit.rb21
2 files changed, 19 insertions, 8 deletions
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index 582347019e5..e1d1724295a 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -32,11 +32,13 @@ module Gitlab
end
end
- def emails_from_key(key)
+ def user_infos_from_key(key)
using_tmp_keychain do
fingerprints = CurrentKeyChain.fingerprints_from_key(key)
- GPGME::Key.find(:public, fingerprints).flat_map { |raw_key| raw_key.uids.map(&:email) }
+ GPGME::Key.find(:public, fingerprints).flat_map do |raw_key|
+ raw_key.uids.map { |uid| { name: uid.name, email: uid.email } }
+ end
end
end
diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb
index 50e8d71bb13..55428b85207 100644
--- a/lib/gitlab/gpg/commit.rb
+++ b/lib/gitlab/gpg/commit.rb
@@ -26,10 +26,7 @@ module Gitlab
def update_signature!(cached_signature)
using_keychain do |gpg_key|
- cached_signature.update_attributes!(
- valid_signature: gpg_signature_valid_signature_value(gpg_key),
- gpg_key: gpg_key
- )
+ cached_signature.update_attributes!(attributes(gpg_key))
end
end
@@ -59,18 +56,30 @@ module Gitlab
end
def create_cached_signature!(gpg_key)
- GpgSignature.create!(
+ GpgSignature.create!(attributes(gpg_key))
+ end
+
+ def attributes(gpg_key)
+ user_infos = user_infos(gpg_key)
+
+ {
commit_sha: commit.sha,
project: commit.project,
gpg_key: gpg_key,
gpg_key_primary_keyid: gpg_key&.primary_keyid || verified_signature.fingerprint,
+ gpg_key_user_name: user_infos[:name],
+ gpg_key_user_email: user_infos[:email],
valid_signature: gpg_signature_valid_signature_value(gpg_key)
- )
+ }
end
def gpg_signature_valid_signature_value(gpg_key)
!!(gpg_key && gpg_key.verified? && verified_signature.valid?)
end
+
+ def user_infos(gpg_key)
+ gpg_key&.verified_user_infos&.first || gpg_key&.user_infos&.first || {}
+ end
end
end
end