Class: Sym::App::PrivateKey::KeySourceCheck
- Defined in:
- lib/sym/app/private_key/key_source_check.rb
Constant Summary collapse
- CHECKS =
KeySourceCheck.new( name: :interactive, reducted: true, input: ->(detector) { detector.opts[:interactive] }, output: ->(detector, *) { detector.input_handler.prompt('Please paste your private key: ', :magenta) } ), KeySourceCheck.new( name: :file, output: ->(*, value) { ::File.read(value).chomp if value && File.exist?(value) } ), KeySourceCheck.new( name: :keychain, output: ->(*, value) { KeyChain.get(value) if value } ), KeySourceCheck.new( name: :string, reducted: true, output: ->(*, value) do decoded = begin Base64Decoder.new(value).key rescue nil end value if decoded end ), KeySourceCheck.new( name: :env, output: ->(*, value) { value =~ /^[a-zA-Z0-9_]+$/ ? ENV[value] : nil } ), KeySourceCheck.new( name: :default_file, input: ->(*) { Sym.default_key_file if Sym.default_key? }, output: ->(detector, *) { key_provided_by = %i(key interactive) & detector.opts.to_hash.keys.select { |k| detector.opts[k] } Sym.default_key if key_provided_by.empty? } )
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#reducted ⇒ Object
Returns the value of attribute reducted.
Instance Method Summary collapse
- #detect(detector) ⇒ Object
-
#initialize(name:, output:, reducted: false, input: ->(detector) { detector.opts[:key] }) ⇒ KeySourceCheck
constructor
A new instance of KeySourceCheck.
Constructor Details
#initialize(name:, output:, reducted: false, input: ->(detector) { detector.opts[:key] }) ⇒ KeySourceCheck
Returns a new instance of KeySourceCheck.
18 19 20 21 22 23 24 25 26 |
# File 'lib/sym/app/private_key/key_source_check.rb', line 18 def initialize(name:, output:, reducted: false, input: ->(detector) { detector.opts[:key] }) self.name = name self.reducted = reducted self.input = input self.output = output end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
16 17 18 |
# File 'lib/sym/app/private_key/key_source_check.rb', line 16 def input @input end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/sym/app/private_key/key_source_check.rb', line 16 def name @name end |
#output ⇒ Object
Returns the value of attribute output.
16 17 18 |
# File 'lib/sym/app/private_key/key_source_check.rb', line 16 def output @output end |
#reducted ⇒ Object
Returns the value of attribute reducted.
16 17 18 |
# File 'lib/sym/app/private_key/key_source_check.rb', line 16 def reducted @reducted end |
Instance Method Details
#detect(detector) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/sym/app/private_key/key_source_check.rb', line 28 def detect(detector) input_value = input.call(detector) return nil unless input_value KeySourceResult.new(name, reducted, input_value, output.call(detector, input_value)) end |