Class: ReaperMan::Signer

Inherits:
Object
  • Object
show all
Includes:
Utils::Process
Defined in:
lib/reaper-man/signer.rb,
lib/reaper-man/signer/deb.rb,
lib/reaper-man/signer/rpm.rb,
lib/reaper-man/signer/rubygems.rb

Overview

File signer

Defined Under Namespace

Modules: Deb, Rpm, Rubygems

Constant Summary collapse

HELPER_COMMAND =

command to use for file signing

File.join(
  File.expand_path(File.dirname(__FILE__)),
  "util-scripts/auto-helper"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Process

#child_process_command, #mixlib_shellout_command, #shellout

Constructor Details

#initialize(args = {}) ⇒ Signer

Create new instance

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :signing_key (String)
  • :signing_chunk_size (String) — default: defaults to 1
  • :signing_type (String) — default: defaults to 'origin'
  • :key_password (String) — default: defaults to `ENV['REAPER_KEY_PASSWORD']`
  • :package_system (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/reaper-man/signer.rb', line 32

def initialize(args = {})
  args = args.to_smash
  @key_id = args[:signing_key]
  @sign_chunk_size = args.fetch(:signing_chunk_size, 1)
  @sign_type = args.fetch(:signing_type, "origin")
  @key_password = args.fetch(:key_password, ENV["REAPER_KEY_PASSWORD"])
  @package_system = args[:package_system]
  case package_system.to_sym
  when :deb, :apt
    extend Deb
  when :rpm, :yum
    extend Rpm
  when :gem, :rubygems
    extend Rubygems
  else
    raise TypeError.new "Unknown packaging type requested (#{package_system})"
  end
end

Instance Attribute Details

#key_idObject (readonly)

Returns the value of attribute key_id.



12
13
14
# File 'lib/reaper-man/signer.rb', line 12

def key_id
  @key_id
end

#key_passwordObject (readonly)

Returns the value of attribute key_password.



16
17
18
# File 'lib/reaper-man/signer.rb', line 16

def key_password
  @key_password
end

#package_systemObject (readonly)

Returns the value of attribute package_system.



15
16
17
# File 'lib/reaper-man/signer.rb', line 15

def package_system
  @package_system
end

#sign_chunk_sizeObject (readonly)

Returns the value of attribute sign_chunk_size.



13
14
15
# File 'lib/reaper-man/signer.rb', line 13

def sign_chunk_size
  @sign_chunk_size
end

#sign_typeObject (readonly)

Returns the value of attribute sign_type.



14
15
16
# File 'lib/reaper-man/signer.rb', line 14

def sign_type
  @sign_type
end

Instance Method Details

#file(src, dst = nil, sign_opts = nil) ⇒ String

Sign the file

Parameters:

  • src (String)

    path to source file

  • dst (String) (defaults to: nil)

    path for destination file

Returns:

  • (String)

    destination file path



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/reaper-man/signer.rb', line 56

def file(src, dst = nil, sign_opts = nil)
  opts = sign_opts ? [sign_opts].flatten.compact : ["--detach-sign", "--armor"]
  dst ||= src.sub(/#{Regexp.escape(File.extname(src))}$/, ".gpg")
  opts << "--output '#{dst}'"
  cmd = (["gpg --default-key #{key_id}"] + opts + [src]).join(" ")
  if key_password
    shellout(
      "#{HELPER_COMMAND} #{cmd}",
      :environment => {
        "REAPER_KEY_PASSWORD" => key_password,
      },
    )
  else
    shellout(cmd)
  end
  dst
end