Class: MyPKI::Configuration
- Inherits:
-
Hash
- Object
- Hash
- MyPKI::Configuration
- Includes:
- Prompter
- Defined in:
- lib/mypki/configuration.rb
Defined Under Namespace
Modules: Loader
Class Attribute Summary collapse
-
.loaders ⇒ Object
Returns the value of attribute loaders.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(path, **options) ⇒ Configuration
constructor
A new instance of Configuration.
- #loaders ⇒ Object
Methods included from Prompter
#file_prompt, #pass_prompt, #prompter
Constructor Details
#initialize(path, **options) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mypki/configuration.rb', line 9 def initialize path, ** = @path = File. path @loaders = loaders.map{|loader| loader.new } if File.exist? @path begin merge! MultiJson.load(File.read(@path)) @loaders.each {|l| l.load self} rescue => ex raise "Bad MyPKI configuration (#{ex.message})" end else retriable on_retry: proc { warn $! } do clear create end end end |
Class Attribute Details
.loaders ⇒ Object
Returns the value of attribute loaders.
49 50 51 |
# File 'lib/mypki/configuration.rb', line 49 def loaders @loaders end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/mypki/configuration.rb', line 7 def end |
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mypki/configuration.rb', line 29 def create pki = file_prompt 'Path to your PKI: ' @loaders.each do |loader| loader.configure self, pki loader.load self unless [:no_verify] end if Instance.cert.nil? and Instance.key.nil? and not [:no_verify] fail 'Unknown PKI type - add an extension or try another file' end if File.writable? File.dirname(@path) File.write @path, MultiJson.dump(Hash[keys.zip(values)], :pretty => true) else warn "warning: #{File.dirname(@path)} is not writable! MyPKI will not save a configuration." end end |
#loaders ⇒ Object
52 53 54 |
# File 'lib/mypki/configuration.rb', line 52 def loaders self.class.loaders ||= [] end |