Module: Chef::Knife::SecureDataBag::BaseMixin

Defined in:
lib/chef/knife/secure_data_bag/base_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Steps to execute when the mixin is include. In this case specifically, add additional command line options related to exporting.

Since:

  • 3.0.0



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

def self.included(base)
  base.deps do
    require 'secure_data_bag'
  end

  base.option :encryption_format,
    description: 'The format with which to encrypt data. If unset, it will be autodetected.',
    long: '--enc-format [plain|encrypted|nested]'

  base.option :decryption_format,
    description: 'The format with which to decrypt data. If unset, it will be autodetected.',
    long: '--dec-format [plain|encrypted|nested]'

  base.option :encrypted_keys,
    description: 'Comma delimited list of keys which should be encrypted, in addition to what was previously there',
    long: '--enc-keys FIELD1,FIELD2,FIELD3',
    proc: proc { |s| s.split(',') }
end

Instance Method Details

#config_metadataObject

Metadata to use when interacting with SecureDataBag containing overrides specified on the command-line.

Since:

  • 3.0.0



33
34
35
36
37
38
39
40
41
# File 'lib/chef/knife/secure_data_bag/base_mixin.rb', line 33

def 
  Mash.new(
    encryption_format: config[:encryption_format],
    decryption_format: config[:decryption_format],
    encrypted_keys: encrypted_keys,
    encrypt: true,
    secret: secret
  )
end

#create_item(data_bag, item_name, data = {}, metadata = {}) ⇒ SecureDataBag::Item

Create a new data_bag_item

Parameters:

  • data_bag (String)

    the data_bag to load from

  • item_name (String)

    the data_bag_item name to load

  • data (Hash) (defaults to: {})

    the optional raw_data to use

  • metadata (Hash) (defaults to: {})

    the optional metadata to pass to ::Item

Returns:

Since:

  • 3.0.0



61
62
63
64
65
66
# File 'lib/chef/knife/secure_data_bag/base_mixin.rb', line 61

def create_item(data_bag, item_name, data = {},  = {})
  item = ::SecureDataBag::Item.new()
  item.raw_data = { 'id' => item_name }.merge(data)
  item.data_bag data_bag
  item
end

#load_item(data_bag, item_name, metadata = {}) ⇒ SecureDataBag::Item

Load a data_bag_item from Chef Server

Parameters:

  • data_bag (String)

    the data_bag to load from

  • item_name (String)

    the data_bag_item name to load

  • metadata (Hash) (defaults to: {})

    the optional metadata to pass to ::Item

Returns:

Since:

  • 3.0.0



49
50
51
52
# File 'lib/chef/knife/secure_data_bag/base_mixin.rb', line 49

def load_item(data_bag, item_name,  = {})
  item = ::SecureDataBag::Item.load(data_bag, item_name, )
  item
end