docbrown/app/controllers/admin/secrets_controller.rb
Josh Puetz 1c566e0ec4
[deploy] Move /internal to `/admin (#9639)
* First draft - all the big changes

* Changing some more references to 'internal'

* Relocate internal request tests to admin

* Relocate internal system tests to admin

* Fix trailing space

* Test fix

* Move queries from internal to admin

* Docs updates

* Rename internal stimuls controllers to admin (plus docs)

* Rename admin layout

* Fix routing after rebase

* Fixes for latest added admin interfaces

* Serviceworker ignore paths
2020-08-07 10:36:26 -04:00

35 lines
1.1 KiB
Ruby

module Admin
class SecretsController < Admin::ApplicationController
layout "admin"
before_action :validate_settable_secret, only: [:update]
after_action only: [:update] do
Audit::Logger.log(:internal, current_user, params.dup)
end
def index
@vault_enabled = AppSecrets.vault_enabled?
@secrets = AppSecrets::SETTABLE_SECRETS.map do |key|
secret_value = AppSecrets[key]
secret_value = secret_value.present? ? "#{secret_value.first(8)}******" : "Not In Vault"
[key, secret_value]
end
end
def update
AppSecrets[params[:key_name]] = params[:key_value]
flash[:success] = "Secret #{params[:key_name]} was successfully updated in Vault."
redirect_to admin_secrets_path
end
private
def validate_settable_secret
update_param = params.permit(*AppSecrets::SETTABLE_SECRETS)
params[:key_name], params[:key_value] = update_param.to_h.to_a.first
bad_request unless update_param.present? && params[:key_name].is_a?(String) && params[:key_value].is_a?(String)
end
end
end