Class: Lux::Config::Secrets
Instance Attribute Summary collapse
-
#read_file ⇒ Object
readonly
Returns the value of attribute read_file.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#secret_file ⇒ Object
readonly
Returns the value of attribute secret_file.
-
#strength ⇒ Object
readonly
Returns the value of attribute strength.
Instance Method Summary collapse
- #encoded_data ⇒ Object
-
#initialize ⇒ Secrets
constructor
A new instance of Secrets.
- #load ⇒ Object
- #to_h ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize ⇒ Secrets
Returns a new instance of Secrets.
14 15 16 17 18 19 20 |
# File 'lib/lux/config/lib/secrets.rb', line 14 def initialize @read_file = Pathname.new './tmp/secrets.yaml' @secret_file = Pathname.new './config/secrets.enc' @common_file = Pathname.new './config/secrets.yaml' @secret = Lux.config.secret_key_base || Lux.config.secret || ENV['SECRET'] || die('ENV SECRET not found') @strength = 'HS512' end |
Instance Attribute Details
#read_file ⇒ Object (readonly)
Returns the value of attribute read_file.
12 13 14 |
# File 'lib/lux/config/lib/secrets.rb', line 12 def read_file @read_file end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
12 13 14 |
# File 'lib/lux/config/lib/secrets.rb', line 12 def secret @secret end |
#secret_file ⇒ Object (readonly)
Returns the value of attribute secret_file.
12 13 14 |
# File 'lib/lux/config/lib/secrets.rb', line 12 def secret_file @secret_file end |
#strength ⇒ Object (readonly)
Returns the value of attribute strength.
12 13 14 |
# File 'lib/lux/config/lib/secrets.rb', line 12 def strength @strength end |
Instance Method Details
#encoded_data ⇒ Object
27 28 29 |
# File 'lib/lux/config/lib/secrets.rb', line 27 def encoded_data JWT.decode(@secret_file.read, @secret, true, { algorithm: @strength }).first end |
#load ⇒ Object
44 45 46 |
# File 'lib/lux/config/lib/secrets.rb', line 44 def load to_h.to_readonly end |
#to_h ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lux/config/lib/secrets.rb', line 31 def to_h it = if @common_file.exist? @common_file.read else encoded_data end it = YAML.load it data = it['shared'] || {} data.merge(it[Lux.env] || {}) end |
#write ⇒ Object
22 23 24 25 |
# File 'lib/lux/config/lib/secrets.rb', line 22 def write encoded = JWT.encode @read_file.read, @secret, @strength @secret_file.write encoded end |