Commit 2577cc99 authored by Rubén Dávila's avatar Rubén Dávila

Address some feedback from last code review

parent 8be06f20
......@@ -23,8 +23,13 @@ class GpgSignature < ActiveRecord::Base
def gpg_key=(model)
case model
when GpgKey then super
when GpgKeySubkey then self.gpg_key_subkey = model
when GpgKey
super
when GpgKeySubkey
self.gpg_key_subkey = model
when NilClass
super
self.gpg_key_subkey = nil
end
end
......
......@@ -3,11 +3,11 @@ class CreateGpgKeySubkeys < ActiveRecord::Migration
def up
create_table :gpg_key_subkeys do |t|
t.references :gpg_key, null: false, index: true, foreign_key: { on_delete: :cascade }
t.binary :keyid
t.binary :fingerprint
t.references :gpg_key, null: false, index: true, foreign_key: { on_delete: :cascade }
t.index :keyid, unique: true, length: Gitlab::Database.mysql? ? 20 : nil
t.index :fingerprint, unique: true, length: Gitlab::Database.mysql? ? 20 : nil
end
......
......@@ -28,8 +28,10 @@ class CreateGpgKeySubkeysForExistingGpgKeys < ActiveRecord::Migration
end
def up
GpgKey.each_batch do |batch|
GpgKey.with_subkeys.each_batch do |batch|
batch.each do |gpg_key|
return if gpg_key.subkeys.any?
create_subkeys(gpg_key) && update_signatures(gpg_key)
end
end
......
......@@ -580,9 +580,9 @@ ActiveRecord::Schema.define(version: 20171004121444) do
add_index "forked_project_links", ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true, using: :btree
create_table "gpg_key_subkeys", force: :cascade do |t|
t.integer "gpg_key_id", null: false
t.binary "keyid"
t.binary "fingerprint"
t.integer "gpg_key_id", null: false
end
add_index "gpg_key_subkeys", ["fingerprint"], name: "index_gpg_key_subkeys_on_fingerprint", unique: true, using: :btree
......
......@@ -43,6 +43,8 @@ module Gitlab
# key belonging to the keyid.
# This way we can add the key to the temporary keychain and extract
# the proper signature.
# NOTE: the invoked method is #fingerprint but it's only returning
# 16 characters (the format used by keyid) instead of 40.
gpg_key = find_gpg_key(verified_signature.fingerprint)
if gpg_key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment