Created
September 1, 2023 22:09
-
-
Save bradgessler/959a5fed1b92cd19e6c378691ba53c57 to your computer and use it in GitHub Desktop.
The basis of a secrets editor that works from Rails. I'd probably ditch the file and instead ask for the secret, which I'd store in a cookie with a 10 min ttl (or something)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NoPassword::CredentialsController < ApplicationController | |
before_action :assign_credentials | |
class Editor < Phlex::HTML | |
def initialize(credentials:) | |
@credentials = credentials | |
end | |
def template(&) | |
style do | |
unsafe_raw """ | |
dd > dl { margin-left: 1rem; } | |
body { margin: 1rem; } | |
""" | |
end | |
h1 { "Your Secrets" } | |
list_credentials @credentials | |
end | |
private | |
def list_credentials(credentials) | |
dl do | |
credentials.each do |key, value| | |
dt { key } | |
dd do | |
case value | |
when Hash | |
list_credentials value | |
else | |
value | |
end | |
end | |
end | |
end | |
end | |
end | |
def index | |
render Editor.new(credentials: @credentials) | |
end | |
private | |
def config | |
Rails.application.config.credentials | |
end | |
def content_path | |
@content_path ||= Rails.root.join("config/credentials.yml.enc") | |
end | |
def key_path | |
@key_path ||= Rails.root.join("config/master.key") | |
end | |
def assign_credentials | |
@credentials = Rails.application.encrypted(content_path, key_path: key_path) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment