From 8e0c33ed1337e3614fe87d9d0c1eb64af90cc61a Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Thu, 20 Jul 2017 15:44:15 +0200 Subject: [PATCH] use ShaAttribute for gpg table columns --- app/models/gpg_key.rb | 5 +++++ app/models/gpg_signature.rb | 5 +++++ app/views/profiles/gpg_keys/_key.html.haml | 2 +- app/views/projects/commit/_signature_badge.html.haml | 2 +- db/migrate/20170222111732_create_gpg_keys.rb | 4 ++-- db/migrate/20170613154149_create_gpg_signatures.rb | 5 +++-- db/migrate/limits_to_mysql.rb | 4 ++++ db/schema.rb | 8 ++++---- 8 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 31a25f3e2f0..da2875a8851 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -1,6 +1,11 @@ class GpgKey < ActiveRecord::Base KEY_PREFIX = '-----BEGIN PGP PUBLIC KEY BLOCK-----'.freeze + include ShaAttribute + + sha_attribute :primary_keyid + sha_attribute :fingerprint + belongs_to :user has_many :gpg_signatures, dependent: :nullify diff --git a/app/models/gpg_signature.rb b/app/models/gpg_signature.rb index 0ef335bf8a9..9ac89f0bbbf 100644 --- a/app/models/gpg_signature.rb +++ b/app/models/gpg_signature.rb @@ -1,4 +1,9 @@ class GpgSignature < ActiveRecord::Base + include ShaAttribute + + sha_attribute :commit_sha + sha_attribute :gpg_key_primary_keyid + belongs_to :project belongs_to :gpg_key diff --git a/app/views/profiles/gpg_keys/_key.html.haml b/app/views/profiles/gpg_keys/_key.html.haml index b04981f90e3..d625aaea467 100644 --- a/app/views/profiles/gpg_keys/_key.html.haml +++ b/app/views/profiles/gpg_keys/_key.html.haml @@ -6,7 +6,7 @@ = render partial: 'email_with_badge', locals: { email: email, verified: verified } .description - %code= key.fingerprint + %code= key.fingerprint.upcase .pull-right %span.key-created-at created #{time_ago_with_tooltip(key.created_at)} diff --git a/app/views/projects/commit/_signature_badge.html.haml b/app/views/projects/commit/_signature_badge.html.haml index d6ece085f18..e79360a36e5 100644 --- a/app/views/projects/commit/_signature_badge.html.haml +++ b/app/views/projects/commit/_signature_badge.html.haml @@ -9,7 +9,7 @@ = content GPG Key ID: - %span.monospace= signature.gpg_key_primary_keyid + %span.monospace= signature.gpg_key_primary_keyid.upcase = link_to('Learn more about signing commits', help_page_path('workflow/gpg_signed_commits/index.md'), class: 'gpg-popover-help-link') diff --git a/db/migrate/20170222111732_create_gpg_keys.rb b/db/migrate/20170222111732_create_gpg_keys.rb index 55dc730e884..7591238311f 100644 --- a/db/migrate/20170222111732_create_gpg_keys.rb +++ b/db/migrate/20170222111732_create_gpg_keys.rb @@ -7,8 +7,8 @@ class CreateGpgKeys < ActiveRecord::Migration t.references :user, index: true, foreign_key: true - t.string :fingerprint - t.string :primary_keyid + t.binary :primary_keyid, limit: Gitlab::Database.mysql? ? 20 : nil + t.binary :fingerprint, limit: Gitlab::Database.mysql? ? 20 : nil t.text :key diff --git a/db/migrate/20170613154149_create_gpg_signatures.rb b/db/migrate/20170613154149_create_gpg_signatures.rb index 515c1413cf4..c5478551e11 100644 --- a/db/migrate/20170613154149_create_gpg_signatures.rb +++ b/db/migrate/20170613154149_create_gpg_signatures.rb @@ -10,8 +10,9 @@ class CreateGpgSignatures < ActiveRecord::Migration t.boolean :valid_signature - t.string :commit_sha - t.string :gpg_key_primary_keyid + t.binary :commit_sha, limit: Gitlab::Database.mysql? ? 20 : nil + t.binary :gpg_key_primary_keyid, limit: Gitlab::Database.mysql? ? 20 : nil + t.string :gpg_key_user_name t.string :gpg_key_user_email diff --git a/db/migrate/limits_to_mysql.rb b/db/migrate/limits_to_mysql.rb index be3501c4c2e..de1288e6410 100644 --- a/db/migrate/limits_to_mysql.rb +++ b/db/migrate/limits_to_mysql.rb @@ -8,5 +8,9 @@ class LimitsToMysql < ActiveRecord::Migration change_column :snippets, :content, :text, limit: 2147483647 change_column :notes, :st_diff, :text, limit: 2147483647 change_column :events, :data, :text, limit: 2147483647 + change_column :gpg_keys, :primary_keyid, :binary, limit: 20 + change_column :gpg_keys, :fingerprint, :binary, limit: 20 + change_column :gpg_signatures, :commit_sha, :binary, limit: 20 + change_column :gpg_signatures, :gpg_key_primary_keyid, :binary, limit: 20 end end diff --git a/db/schema.rb b/db/schema.rb index f413aaa41cd..68b5963ec14 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -544,8 +544,8 @@ ActiveRecord::Schema.define(version: 20170725145659) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "user_id" - t.string "fingerprint" - t.string "primary_keyid" + t.binary "primary_keyid" + t.binary "fingerprint" t.text "key" end @@ -558,8 +558,8 @@ ActiveRecord::Schema.define(version: 20170725145659) do t.integer "project_id" t.integer "gpg_key_id" t.boolean "valid_signature" - t.string "commit_sha" - t.string "gpg_key_primary_keyid" + t.binary "commit_sha" + t.binary "gpg_key_primary_keyid" t.string "gpg_key_user_name" t.string "gpg_key_user_email" end -- GitLab