Class: GpgKey

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

Constant Summary collapse

KEY_PREFIX =
'-----BEGIN PGP PUBLIC KEY BLOCK-----'
KEY_SUFFIX =
'-----END PGP PUBLIC KEY BLOCK-----'

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, without_order

Instance Method Details

#emails_with_verified_statusObject


73
74
75
76
77
78
79
80
# File 'app/models/gpg_key.rb', line 73

def emails_with_verified_status
  user_infos.map do ||
    [
      [:email],
      user.verified_email?([:email])
    ]
  end.to_h
end

#fingerprintObject


51
52
53
# File 'app/models/gpg_key.rb', line 51

def fingerprint
  super&.upcase
end

#key=(value) ⇒ Object


55
56
57
# File 'app/models/gpg_key.rb', line 55

def key=(value)
  super(value&.strip)
end

#keyidsObject


59
60
61
# File 'app/models/gpg_key.rb', line 59

def keyids
  [keyid].concat(subkeys.map(&:keyid))
end

#primary_keyidObject Also known as: keyid


46
47
48
# File 'app/models/gpg_key.rb', line 46

def primary_keyid
  super&.upcase
end

#revokeObject


94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/gpg_key.rb', line 94

def revoke
  GpgSignature
    .with_key_and_subkeys(self)
    .where.not(verification_status: GpgSignature.verification_statuses[:unknown_key])
    .update_all(
      gpg_key_id: nil,
      gpg_key_subkey_id: nil,
      verification_status: GpgSignature.verification_statuses[:unknown_key],
      updated_at: Time.zone.now
    )

  destroy
end

#update_invalid_gpg_signaturesObject


90
91
92
# File 'app/models/gpg_key.rb', line 90

def update_invalid_gpg_signatures
  InvalidGpgSignatureUpdateWorker.perform_async(self.id)
end

#user_infosObject


63
64
65
# File 'app/models/gpg_key.rb', line 63

def user_infos
  @user_infos ||= Gitlab::Gpg.user_infos_from_key(key)
end

#verified?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'app/models/gpg_key.rb', line 82

def verified?
  emails_with_verified_status.values.any?
end

#verified_and_belongs_to_email?(email) ⇒ Boolean

Returns:

  • (Boolean)

86
87
88
# File 'app/models/gpg_key.rb', line 86

def verified_and_belongs_to_email?(email)
  emails_with_verified_status.fetch(email.downcase, false)
end

#verified_user_infosObject


67
68
69
70
71
# File 'app/models/gpg_key.rb', line 67

def verified_user_infos
  user_infos.select do ||
    user.verified_email?([:email])
  end
end