Module: Muchkeys::CLI::MuchkeysExecutor

Extended by:
MuchkeysExecutor
Included in:
MuchkeysExecutor
Defined in:
lib/muchkeys/cli.rb

Instance Method Summary collapse

Instance Method Details

#check(app_name) ⇒ Object



113
114
115
116
117
118
# File 'lib/muchkeys/cli.rb', line 113

def check(app_name)
  Muchkeys.configure { |c| c.application_name = app_name }
  Muchkeys::ApplicationClient.new(Muchkeys.config).verify_keys(*Muchkeys.env_keys)

  "All keys present and accounted for."
end

#decrypt(consul_key, public_key, private_key) ⇒ Object



83
84
85
# File 'lib/muchkeys/cli.rb', line 83

def decrypt(consul_key, public_key, private_key)
  Muchkeys::ApplicationClient.new.fetch_key(consul_key, public_key: public_key, private_key: private_key)
end

#delete(consul_key) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/muchkeys/cli.rb', line 132

def delete(consul_key)
  app = Muchkeys::ApplicationClient.new
  app.allow_unsafe_operation do
    app.delete_key(consul_key)
  end

  "Key #{consul_key} deleted"
end

#encrypt(file, public_key) ⇒ Object



78
79
80
81
# File 'lib/muchkeys/cli.rb', line 78

def encrypt(file, public_key)
  string_to_encrypt = File.read(file)
  Muchkeys::ApplicationClient.new.secret_adapter.encrypt_string(string_to_encrypt.chomp, public_key)
end

#fetch(consul_key) ⇒ Object



141
142
143
# File 'lib/muchkeys/cli.rb', line 141

def fetch(consul_key)
  Muchkeys::ApplicationClient.new.fetch_key(consul_key)
end

#list(app_name) ⇒ Object



106
107
108
109
110
111
# File 'lib/muchkeys/cli.rb', line 106

def list(app_name)
  Muchkeys.configure { |c| c.application_name = app_name }
  keys = Muchkeys::ApplicationClient.new(Muchkeys.config).known_keys

  keys.join("\n")
end

#store(consul_key, data, public_key: nil, private_key: nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/muchkeys/cli.rb', line 87

def store(consul_key, data, public_key: nil, private_key: nil)
  Muchkeys.configure { |c| c.public_key = public_key; c.private_key = private_key }
  app = Muchkeys::ApplicationClient.new(Muchkeys.config)

  if data == "-"
    data = $stdin.read
  end

  app.allow_unsafe_operation do
    if public_key && private_key
      app.set_key(consul_key, data, type: :secret)
      "Secret '#{data}' stored in #{consul_key}"
    else
      app.set_key(consul_key, data)
      "'#{data}' stored in #{consul_key}"
    end
  end
end

#wipeout(app_name: nil) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/muchkeys/cli.rb', line 120

def wipeout(app_name: nil)
  Muchkeys.configure { |c| c.application_name = app_name }
  app = Muchkeys::ApplicationClient.new
  app.allow_unsafe_operation do
    app.each_path do |path|
      app.delete_key(path)
    end
  end

  "Everything deleted!"
end