Class: LeapCli::Config::Secrets
- Defined in:
- lib/leap_cli/config/secrets.rb
Instance Attribute Summary collapse
-
#node_list ⇒ Object
readonly
Returns the value of attribute node_list.
Attributes inherited from Object
Instance Method Summary collapse
-
#dump_json(clean = false) ⇒ Object
if clean is true, then only secrets that have been discovered during this run will be exported.
-
#initialize(manager = nil) ⇒ Secrets
constructor
A new instance of Secrets.
-
#retrieve(key, environment) ⇒ Object
we can’t use fetch() or get(), since those already have special meanings.
- #set(*args, &block) ⇒ Object
- #set_with_block(key, environment, &block) ⇒ Object
- #set_without_block(key, value, environment) ⇒ Object
Methods inherited from Object
#[], #deep_merge!, #default, #dump_yaml, #environment, #environment=, #eval_file, #evaluate, #get, #get!, #hkey, #inherit_from!, #key, #manager, #method_missing, #pick
Methods inherited from Hash
#deep_dup, #deep_merge, #deep_merge!, #pick
Constructor Details
#initialize(manager = nil) ⇒ Secrets
Returns a new instance of Secrets.
11 12 13 14 |
# File 'lib/leap_cli/config/secrets.rb', line 11 def initialize(manager=nil) super(manager) @discovered_keys = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class LeapCli::Config::Object
Instance Attribute Details
#node_list ⇒ Object (readonly)
Returns the value of attribute node_list.
9 10 11 |
# File 'lib/leap_cli/config/secrets.rb', line 9 def node_list @node_list end |
Instance Method Details
#dump_json(clean = false) ⇒ Object
if clean is true, then only secrets that have been discovered during this run will be exported.
if environment is also pinned, then we will clean those secrets just for that environment.
the clean argument should only be used when all nodes have been processed, otherwise secrets that are actually in use will get mistakenly removed.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/leap_cli/config/secrets.rb', line 54 def dump_json(clean=false) pinned_env = LeapCli.leapfile.environment if clean self.each_key do |environment| if pinned_env.nil? || pinned_env == environment self[environment].each_key do |key| unless @discovered_keys[environment] && @discovered_keys[environment][key] self[environment].delete(key) end end if self[environment].empty? self.delete(environment) end end end end super() end |
#retrieve(key, environment) ⇒ Object
we can’t use fetch() or get(), since those already have special meanings
17 18 19 20 |
# File 'lib/leap_cli/config/secrets.rb', line 17 def retrieve(key, environment) environment ||= 'default' self.fetch(environment, {})[key.to_s] end |
#set(*args, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/leap_cli/config/secrets.rb', line 22 def set(*args, &block) if block_given? set_with_block(*args, &block) else set_without_block(*args) end end |
#set_with_block(key, environment, &block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/leap_cli/config/secrets.rb', line 34 def set_with_block(key, environment, &block) environment ||= 'default' key = key.to_s @discovered_keys[environment] ||= {} @discovered_keys[environment][key] = true self[environment] ||= {} self[environment][key] ||= yield end |
#set_without_block(key, value, environment) ⇒ Object
30 31 32 |
# File 'lib/leap_cli/config/secrets.rb', line 30 def set_without_block(key, value, environment) set_with_block(key, environment) {value} end |