Class: Stalkedbybean::SecretsSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/stalkedbybean/secrets_setup.rb

Class Method Summary collapse

Class Method Details

.add_secret(key, value) ⇒ Object

Raises:

  • (StandardError)


28
29
30
31
# File 'lib/stalkedbybean/secrets_setup.rb', line 28

def self.add_secret(key, value)
  raise(StandardError, "Missing or invalid key/value") if key == nil || value == nil
  system("credstash -r #{@options[:aws_region]} -p #{@options[:aws_profile]} -t #{@app_tag} put -k alias/#{@app_tag} #{key} #{value}")
end

.change_secret(key, value, version) ⇒ Object

Raises:

  • (StandardError)


42
43
44
45
46
# File 'lib/stalkedbybean/secrets_setup.rb', line 42

def self.change_secret(key, value, version)
  raise(StandardError, "Missing or invalid key/value") if key == nil || value == nil
  raise(StandardError, "Missing version number") if version == nil
  system("credstash -r #{@options[:aws_region]} -p #{@options[:aws_profile]} -t #{@app_tag} put -k alias/#{@app_tag} -v #{version} #{key} #{value}")
end

.create_credstash_tableObject



23
24
25
26
# File 'lib/stalkedbybean/secrets_setup.rb', line 23

def self.create_credstash_table
  system("credstash -r #{@options[:aws_region]} -p #{@options[:aws_profile]} -t #{@app_tag} setup")
  puts "Credstash table #{@app_tag} created."
end

.create_keyObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/stalkedbybean/secrets_setup.rb', line 12

def self.create_key
  @client = Aws::KMS::Client.new(region: "#{@options[:aws_region]}", profile: "#{@options[:aws_profile]}")
  key = @client.create_key({})
  @client.create_alias({
    alias_name: "alias/#{@app_tag}",
    target_key_id: key[:key_metadata][:key_id]
    })

  puts "Your KMS ARN is: #{key[:key_metadata][:arn]}"
end

.get_secret(key) ⇒ Object

Raises:

  • (StandardError)


33
34
35
36
# File 'lib/stalkedbybean/secrets_setup.rb', line 33

def self.get_secret(key)
  raise(StandardError, "Missing or invalid key") if key == nil
  system("credstash -r #{@options[:aws_region]} -p #{@options[:aws_profile]} -t #{@app_tag} get #{key}")
end

.getall_secretsObject



38
39
40
# File 'lib/stalkedbybean/secrets_setup.rb', line 38

def self.getall_secrets
  system("credstash -r #{@options[:aws_region]} -p #{@options[:aws_profile]} -t #{@app_tag} getall")
end

.parse_options(file_path, options) ⇒ Object



7
8
9
10
# File 'lib/stalkedbybean/secrets_setup.rb', line 7

def self.parse_options(file_path, options)
  @options = Stalkedbybean::Parser.parse_options(file_path, options)
  @app_tag = "#{@options[:app_name]}-#{@options[:environment]}"
end