Class: Chef::Resource::ChefDataBagItem

Inherits:
LWRPBase
  • Object
show all
Defined in:
lib/chef/resource/chef_data_bag_item.rb

Constant Summary collapse

NOT_PASSED =
Object.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ChefDataBagItem

Returns a new instance of ChefDataBagItem.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chef/resource/chef_data_bag_item.rb', line 11

def initialize(*args)
  super
  name @name
  if !data_bag
    data_bag run_context.cheffish.current_data_bag
  end
  if run_context.cheffish.current_data_bag_item_encryption
    @encrypt = true if run_context.cheffish.current_data_bag_item_encryption[:encrypt_all]
    @secret = run_context.cheffish.current_data_bag_item_encryption[:secret]
    @secret_path = run_context.cheffish.current_data_bag_item_encryption[:secret_path] || Chef::Config[:encrypted_data_bag_secret]
    @encryption_cipher = run_context.cheffish.current_data_bag_item_encryption[:encryption_cipher]
    @encryption_version = run_context.cheffish.current_data_bag_item_encryption[:encryption_version]
    @old_secret = run_context.cheffish.current_data_bag_item_encryption[:old_secret]
    @old_secret_path = run_context.cheffish.current_data_bag_item_encryption[:old_secret_path]
  end
  chef_server run_context.cheffish.current_chef_server
end

Instance Attribute Details

#raw_data_modifiersObject (readonly)

value ‘ip_address’, ‘127.0.0.1’ value [ ‘pushy’, ‘port’ ], ‘9000’ value ‘ip_addresses’ do |existing_value|

(existing_value || []) + [ '127.0.0.1' ]

end value ‘ip_address’, :delete



103
104
105
# File 'lib/chef/resource/chef_data_bag_item.rb', line 103

def raw_data_modifiers
  @raw_data_modifiers
end

Instance Method Details

#data_bag(value = NOT_PASSED) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/chef/resource/chef_data_bag_item.rb', line 54

def data_bag(value = NOT_PASSED)
  if value == NOT_PASSED
    @data_bag
  else
    @data_bag = value
    name data_bag ? "#{data_bag}/#{id}" : id
  end
end

#id(value = NOT_PASSED) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/chef/resource/chef_data_bag_item.rb', line 46

def id(value = NOT_PASSED)
  if value == NOT_PASSED
    @id
  else
    @id = value
    name data_bag ? "#{data_bag}/#{id}" : id
  end
end

#name(*args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chef/resource/chef_data_bag_item.rb', line 29

def name(*args)
  result = super(*args)
  if args.size == 1
    parts = name.split('/')
    if parts.size == 1
      @id = parts[0]
    elsif parts.size == 2
      @data_bag = parts[0]
      @id = parts[1]
    else
      raise "Name #{args[0].inspect} must be a string with 1 or 2 parts, either 'id' or 'data_bag/id"
    end
  end
  result
end

#secret(new_secret = nil) ⇒ Object

attribute :secret, :kind_of => String



67
68
69
70
71
72
73
74
# File 'lib/chef/resource/chef_data_bag_item.rb', line 67

def secret(new_secret = nil)
  if !new_secret
    @secret
  else
    @secret = new_secret
    @encrypt = true if @encrypt.nil?
  end
end

#secret_path(new_secret_path = nil) ⇒ Object

attribute :secret_path, :kind_of => String



76
77
78
79
80
81
82
83
# File 'lib/chef/resource/chef_data_bag_item.rb', line 76

def secret_path(new_secret_path = nil)
  if !new_secret_path
    @secret_path
  else
    @secret_path = new_secret_path
    @encrypt = true if @encrypt.nil?
  end
end

#value(raw_data_path, value = NOT_PASSED, &block) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/chef/resource/chef_data_bag_item.rb', line 104

def value(raw_data_path, value=NOT_PASSED, &block)
  @raw_data_modifiers ||= []
  if value != NOT_PASSED
    @raw_data_modifiers << [ raw_data_path, value ]
  elsif block
    @raw_data_modifiers << [ raw_data_path, block ]
  else
    raise "value requires either a value or a block"
  end
end