Module: VaultApi::Client::Secrets
- Included in:
- VaultApi::Client
- Defined in:
- lib/vault_api/client/secrets.rb
Instance Method Summary collapse
- #add_secret(config_file_path, user_name = nil) ⇒ Object
- #delete_secret(config_name, user_name = nil) ⇒ Object
- #read_secret(config_name, user_name = nil) ⇒ Object
- #secrets(user_name = nil) ⇒ Object
- #update_secret(config_file_path, user_name = nil) ⇒ Object
- #upload_secrets(config_folder_path, user_name = nil) ⇒ Object
Instance Method Details
#add_secret(config_file_path, user_name = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/vault_api/client/secrets.rb', line 17 def add_secret(config_file_path, user_name = nil) file_basename = File.basename(config_file_path, '.yml') secret_path = "#{VaultApi.secret_base_path(user_name)}/#{file_basename}" output_json = JSON.dump(YAML.load_file(config_file_path)) obj = JSON.parse(output_json) content = obj[VaultApi.env.to_s] VaultApi.write(secret_path, content) end |
#delete_secret(config_name, user_name = nil) ⇒ Object
38 39 40 |
# File 'lib/vault_api/client/secrets.rb', line 38 def delete_secret(config_name, user_name = nil) VaultApi.delete("#{VaultApi.secret_base_path(user_name)}/#{config_name}") end |
#read_secret(config_name, user_name = nil) ⇒ Object
13 14 15 |
# File 'lib/vault_api/client/secrets.rb', line 13 def read_secret(config_name, user_name = nil) VaultApi.read("#{VaultApi.secret_base_path(user_name)}/#{config_name}").data end |
#secrets(user_name = nil) ⇒ Object
9 10 11 |
# File 'lib/vault_api/client/secrets.rb', line 9 def secrets(user_name = nil) VaultApi.list(VaultApi.secret_base_path(user_name)) end |
#update_secret(config_file_path, user_name = nil) ⇒ Object
27 28 29 |
# File 'lib/vault_api/client/secrets.rb', line 27 def update_secret(config_file_path, user_name = nil) add_secret(config_file_path, user_name) # overwrites existing file end |
#upload_secrets(config_folder_path, user_name = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/vault_api/client/secrets.rb', line 31 def upload_secrets(config_folder_path, user_name = nil) Dir.chdir config_folder_path Dir.glob('*.yml').each do |file| add_secret("#{config_folder_path}/#{file}", user_name) end end |