Class: ClusterChef::PrivateKey

Inherits:
DslObject show all
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

ChefClientKey, DataBagKey, Ec2Keypair

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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’)

Yields:

  • a block, executed in caller’s context, when the body is updated

Yield Parameters:

  • the

    updated body



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

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/cluster_chef/private_key.rb', line 9

def name
  @name
end

#on_updateObject (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

#proxyObject (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

#filenameObject



24
25
26
# File 'lib/cluster_chef/private_key.rb', line 24

def filename
  File.join(key_dir, "#{name}.pem")
end

#loadObject



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

#saveObject



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_sObject



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