docbrown/app/lib/app_secrets.rb
Mac Siri 678dda8cf4
Routine Rubopcop lint fixes (#17844)
* Routine Rubopcop lint fixes

* Undo app_secrets_spec changes

* Fix broken spec
2022-06-07 10:17:16 -04:00

29 lines
589 B
Ruby

class AppSecrets
SETTABLE_SECRETS = %w[
SLACK_CHANNEL
SLACK_DEPLOY_CHANNEL
SLACK_WEBHOOK_URL
].freeze
def self.[](key)
result = Vault.kv(namespace).read(key)&.data&.fetch(:value) if vault_enabled?
result ||= ApplicationConfig[key]
result
rescue Vault::VaultError
ApplicationConfig[key]
end
def self.[]=(key, value)
Vault.kv(namespace).write(key, value: value)
end
def self.vault_enabled?
ENV["VAULT_TOKEN"].present?
end
def self.namespace
ENV.fetch("VAULT_SECRET_NAMESPACE", nil)
end
private_class_method :namespace
end