Class: Chef::Provider::PublicKey
- Inherits:
-
LWRPBase
- Object
- LWRPBase
- Chef::Provider::PublicKey
- Defined in:
- lib/chef/provider/public_key.rb
Instance Attribute Summary collapse
-
#current_public_key ⇒ Object
readonly
Returns the value of attribute current_public_key.
-
#new_source_key_publicity ⇒ Object
readonly
Returns the value of attribute new_source_key_publicity.
Instance Method Summary collapse
- #encode_public_key(key) ⇒ Object
- #load_current_resource ⇒ Object
- #new_source_key ⇒ Object
- #whyrun_supported? ⇒ Boolean
Instance Attribute Details
#current_public_key ⇒ Object (readonly)
Returns the value of attribute current_public_key.
38 39 40 |
# File 'lib/chef/provider/public_key.rb', line 38 def current_public_key @current_public_key end |
#new_source_key_publicity ⇒ Object (readonly)
Returns the value of attribute new_source_key_publicity.
39 40 41 |
# File 'lib/chef/provider/public_key.rb', line 39 def new_source_key_publicity @new_source_key_publicity end |
Instance Method Details
#encode_public_key(key) ⇒ Object
32 33 34 35 36 |
# File 'lib/chef/provider/public_key.rb', line 32 def encode_public_key(key) key_format = {} key_format[:format] = new_resource.format if new_resource.format Cheffish::KeyFormatter.encode(key, key_format) end |
#load_current_resource ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chef/provider/public_key.rb', line 63 def load_current_resource if ::File.exist?(new_resource.path) resource = Chef::Resource::PublicKey.new(new_resource.path, run_context) begin key, key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.path), nil, new_resource.path) if key @current_public_key = key resource.format key_format[:format] end rescue # If there is an error reading we assume format and such is broken end @current_resource = resource else not_found_resource = Chef::Resource::PublicKey.new(new_resource.path) not_found_resource.action :delete @current_resource = not_found_resource end end |
#new_source_key ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef/provider/public_key.rb', line 41 def new_source_key @new_source_key ||= begin if new_resource.source_key.is_a?(String) source_key, source_key_format = Cheffish::KeyFormatter.decode(new_resource.source_key, new_resource.source_key_pass_phrase) elsif new_resource.source_key source_key = new_resource.source_key elsif new_resource.source_key_path source_key, source_key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.source_key_path), new_resource.source_key_pass_phrase, new_resource.source_key_path) else return nil end if source_key.private? @new_source_key_publicity = 'private' source_key.public_key else @new_source_key_publicity = 'public' source_key end end end |
#whyrun_supported? ⇒ Boolean
28 29 30 |
# File 'lib/chef/provider/public_key.rb', line 28 def whyrun_supported? true end |