module Sekreto

Sekreto allows you to interact with the AWS Secrets Manager to retrieve your secrets from Ruby. This exposes a thin wrapper around the AWS SecretsManager SDK.

Constants

VERSION

Public Class Methods

config() click to toggle source

Get the configuration for Sekreto

@return [Sekreto::Config] - The configuration

# File lib/sekreto.rb, line 64
def config
  @config ||= Config.new
end
get_json_value(secret_id, prefix = nil) click to toggle source

Get the JSON value of a secret

@param secret_id [String] - The secret ID to get the value for @param prefix [String] - An optional override of the prefix @return [Hash] - The parsed JSON value of the secret

# File lib/sekreto.rb, line 54
def get_json_value(secret_id, prefix = nil)
  response = get_value(secret_id, prefix)
  MultiJson.load(response)
end
get_value(secret_id, prefix = nil) click to toggle source

Get the value given a secret

@param secret_id [String] - The secret ID to get the value for @param prefix [String] - An optional override of the prefix @return [String] - The value of the stored secret

# File lib/sekreto.rb, line 36
def get_value(secret_id, prefix = nil)
  raise 'Not allowed env' unless config.is_allowed_env.call

  secrets_manager.get_secret_value(
    secret_id: secret_name(secret_id, prefix)
  ).secret_string
rescue StandardError => e
  logger.warn("[Sekreto] Failed to get value for #{secret_name(secret_id, prefix)}!\n#{e}")
  config.fallback_lookup.call(secret_id)
end
setup() { |config| ... } click to toggle source

Set up the Sekreto gem configuration

@yieldreturn [Sekreto::Config]

@example Configuring Sekreto

Sekreto.setup do |setup|
  setup.prefix = 'app-prefix'
end
# File lib/sekreto.rb, line 25
def setup
  yield config if block_given?
end

Private Class Methods

logger() click to toggle source
# File lib/sekreto.rb, line 78
def logger
  config.logger
end
secret_name(secret_id, prefix = nil) click to toggle source
# File lib/sekreto.rb, line 70
def secret_name(secret_id, prefix = nil)
  [config.prefix_name(prefix), secret_id].compact.join('/')
end
secrets_manager() click to toggle source
# File lib/sekreto.rb, line 74
def secrets_manager
  config.secrets_manager
end