Class: ClusterChef::PrivateKey
- Defined in:
- lib/cluster_chef/private_key.rb
Overview
A private key – chef client key, ssh key, etc.
The key is a pro
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on_update ⇒ Object
readonly
Returns the value of attribute on_update.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Class Method Summary collapse
Instance Method Summary collapse
- #body=(content) ⇒ Object
- #filename ⇒ Object
-
#initialize(name, proxy = nil) {|the| ... } ⇒ PrivateKey
constructor
PrivateKey.new(‘bob’).
- #load ⇒ Object
- #save ⇒ Object
- #to_s ⇒ Object
Methods inherited from DslObject
#configure, #die, #dump, has_keys, #reverse_merge!, #safely, #set, #step, #to_hash, #to_mash, #ui, ui
Constructor Details
#initialize(name, proxy = nil) {|the| ... } ⇒ PrivateKey
PrivateKey.new(‘bob’)
18 19 20 21 22 |
# File 'lib/cluster_chef/private_key.rb', line 18 def initialize(name, proxy=nil, &on_update) @name = name @proxy = proxy @on_update = on_update end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/cluster_chef/private_key.rb', line 9 def name @name end |
#on_update ⇒ Object (readonly)
Returns the value of attribute on_update.
11 12 13 |
# File 'lib/cluster_chef/private_key.rb', line 11 def on_update @on_update end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
10 11 12 |
# File 'lib/cluster_chef/private_key.rb', line 10 def proxy @proxy end |
Class Method Details
.create!(name, *args, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/cluster_chef/private_key.rb', line 50 def self.create!(name, *args, &block) obj = self.new(name, *args, &block) obj.create_proxy! obj end |
Instance Method Details
#body=(content) ⇒ Object
44 45 46 47 48 |
# File 'lib/cluster_chef/private_key.rb', line 44 def body=(content) @body = content on_update.call(content) if on_update content end |
#filename ⇒ Object
24 25 26 |
# File 'lib/cluster_chef/private_key.rb', line 24 def filename File.join(key_dir, "#{name}.pem") end |
#load ⇒ Object
39 40 41 42 |
# File 'lib/cluster_chef/private_key.rb', line 39 def load return unless File.exists?(filename) self.body = File.read(filename).chomp end |
#save ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cluster_chef/private_key.rb', line 28 def save return unless @body if ClusterChef.chef_config[:dry_run] Chef::Log.debug(" key #{name} - dry run, not writing out key") return end ui.info( " key #{name} - writing to #{filename}" ) FileUtils.mkdir_p(File.dirname(filename)) File.open(filename, "w", 0600){|f| f.print( @body ) } end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/cluster_chef/private_key.rb', line 56 def to_s [super[0..-2], @name, @proxy, @body.to_s[32..64], '...', @body.to_s[-60..-30]].join(" ").gsub(/[\r\n\t]+/,'') + '>' end |