Module: Pkg::Util::Gpg

Defined in:
lib/packaging/util/gpg.rb

Class Method Summary collapse

Class Method Details

.keyObject

Please note that this method is not used in determining what key is used to sign the debian repos. That is defined in the freight config that lives on our internal repo staging host. The debian conf/distribution files that are generated with this repo use the default gpg key to reflect that.



8
9
10
11
12
13
14
# File 'lib/packaging/util/gpg.rb', line 8

def key
  if Pkg::Config.gpg_key.nil? || Pkg::Config.gpg_key.empty?
    fail '`gpg_key` configuration variable is unset. Cannot continue.'
  end

  Pkg::Config.gpg_key
end

.keychainObject



16
17
18
19
20
21
22
# File 'lib/packaging/util/gpg.rb', line 16

def keychain
  if @keychain.nil?
    @keychain = Pkg::Util::Tool.find_tool('keychain')
  else
    @keychain
  end
end

.kill_keychainObject



33
34
35
36
37
# File 'lib/packaging/util/gpg.rb', line 33

def kill_keychain
  return unless keychain

  Pkg::Util::Execution.capture3("#{keychain} -k mine")[0]
end

.load_keychainObject



24
25
26
27
28
29
30
31
# File 'lib/packaging/util/gpg.rb', line 24

def load_keychain
  return if @keychain_loaded
  return if ENV['RPM_GPG_AGENT']

  kill_keychain
  start_keychain
  @keychain_loaded = true
end

.sign_file(file) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/packaging/util/gpg.rb', line 50

def sign_file(file)
  gpg ||= Pkg::Util::Tool.find_tool('gpg')

  unless gpg
    fail "No gpg available. Cannot sign #{file}."
  end

  if File.exist? "#{file}.asc"
    warn "Signature on #{file} already exists, skipping."
    return true
  end

  use_tty = if ENV['RPM_GPG_AGENT']
              '--no-tty --use-agent'
            else
              ''
            end

  signing_command = "#{gpg} #{use_tty} --armor --detach-sign -u #{key} #{file}"
  puts "GPG signing with \"#{signing_command}\""
  Pkg::Util::Execution.capture3(signing_command)
  puts 'GPG signing succeeded.'
end

.start_keychainObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/packaging/util/gpg.rb', line 39

def start_keychain
  unless keychain
    fail "Keychain is not installed, it is required to autosign using gpg."
  end

  keychain_output, = Pkg::Util::Execution.capture3("#{keychain} -q --agents gpg --eval #{key}")
  keychain_output.chomp!

  ENV['GPG_AGENT_INFO'] = keychain_output.match(/GPG_AGENT_INFO=([^;]*)/)[1]
end