Class: Stalkedbybean::SecretsSetup
- Inherits:
-
Object
- Object
- Stalkedbybean::SecretsSetup
- Defined in:
- lib/stalkedbybean/secrets_setup.rb
Class Method Summary collapse
- .add_secret(key, value) ⇒ Object
- .change_secret(key, value, version) ⇒ Object
- .create_credstash_table ⇒ Object
- .create_key ⇒ Object
- .get_secret(key) ⇒ Object
- .getall_secrets ⇒ Object
- .parse_options(file_path, options) ⇒ Object
Class Method Details
.add_secret(key, value) ⇒ Object
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
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_table ⇒ Object
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_key ⇒ Object
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
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_secrets ⇒ Object
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.(file_path, ) @options = Stalkedbybean::Parser.(file_path, ) @app_tag = "#{@options[:app_name]}-#{@options[:environment]}" end |