Class: GpgSignature

Inherits:
ApplicationRecord show all
Includes:
ShaAttribute
Defined in:
app/models/gpg_signature.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, with_fast_statement_timeout, without_order

Class Method Details

.safe_create!(attributes) ⇒ Object


38
39
40
41
# File 'app/models/gpg_signature.rb', line 38

def self.safe_create!(attributes)
  create_with(attributes)
    .safe_find_or_create_by!(commit_sha: attributes[:commit_sha])
end

.unsigned_commit_shas(commit_shas) ⇒ Object

Find commits that are lacking a signature in the database at present


44
45
46
47
48
49
50
# File 'app/models/gpg_signature.rb', line 44

def self.unsigned_commit_shas(commit_shas)
  return [] if commit_shas.empty?

  signed = GpgSignature.where(commit_sha: commit_shas).pluck(:commit_sha)

  commit_shas - signed
end

.with_key_and_subkeys(gpg_key) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'app/models/gpg_signature.rb', line 28

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

Instance Method Details

#commitObject


76
77
78
# File 'app/models/gpg_signature.rb', line 76

def commit
  project.commit(commit_sha)
end

#gpg_commitObject


80
81
82
83
84
# File 'app/models/gpg_signature.rb', line 80

def gpg_commit
  return unless commit

  Gitlab::Gpg::Commit.new(commit)
end

#gpg_keyObject


64
65
66
67
68
69
70
# File 'app/models/gpg_signature.rb', line 64

def gpg_key
  if gpg_key_id
    super
  elsif gpg_key_subkey_id
    gpg_key_subkey
  end
end

#gpg_key=(model) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/gpg_signature.rb', line 52

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

#gpg_key_primary_keyidObject


72
73
74
# File 'app/models/gpg_signature.rb', line 72

def gpg_key_primary_keyid
  super&.upcase
end