Class: Kettle::Dev::ReleaseSecrets::OnePassword

Inherits:
Provider
  • Object
show all
Defined in:
lib/kettle/dev/release_secrets.rb

Constant Summary collapse

PROVIDER_NAMES =
%w[1password onepassword op].freeze
DEFAULTS =
{
  "cli" => "op",
  "item" => "Rubygems",
  "gem_signing_passphrase_field" => "GEM-SIGN-PASSPHRASE",
  "rubygems_otp_field" => "one-time password"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ OnePassword

Returns a new instance of OnePassword.



38
39
40
41
42
# File 'lib/kettle/dev/release_secrets.rb', line 38

def initialize(config)
  @config = DEFAULTS.merge(config || {})
  @gem_signing_passphrase = nil
  @gem_signing_passphrase_loaded = false
end

Class Method Details

.configured?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/kettle/dev/release_secrets.rb', line 34

def self.configured?(name)
  PROVIDER_NAMES.include?(name.to_s.downcase)
end

Instance Method Details

#gem_signing_passphraseObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kettle/dev/release_secrets.rb', line 44

def gem_signing_passphrase
  return @gem_signing_passphrase if @gem_signing_passphrase_loaded

  return cached_gem_signing_passphrase if cached_gem_signing_passphrase?

  reference = string_config("gem_signing_passphrase_reference")
  value = if reference.empty?
    item_field("gem_signing_passphrase_field")
  else
    read_reference(reference)
  end

  @gem_signing_passphrase = value
  @gem_signing_passphrase_loaded = true
  value
end

#keepalive!(elapsed: nil) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/kettle/dev/release_secrets.rb', line 72

def keepalive!(elapsed: nil)
  argv = [op_cli, "account", "get"]
   = string_config("account")
  argv.concat(["--account", ]) unless .empty?
  run_op(argv, purpose: "authorization keepalive", elapsed: elapsed)
  true
end

#rubygems_otpObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/kettle/dev/release_secrets.rb', line 61

def rubygems_otp
  reference = string_config("rubygems_otp_reference")
  return read_reference(reference) unless reference.empty?

  item = required_config("item")
  argv = [op_cli, "item", "get", item, "--otp"]
   = string_config("account")
  argv.concat(["--account", ]) unless .empty?
  run_op(argv, purpose: "RubyGems OTP")
end