Class: Chef::EncryptedAttribute::Config

Inherits:
Object
  • Object
show all
Includes:
Mixin::ParamsValidate
Defined in:
lib/chef/encrypted_attribute/config.rb

Overview

Encrypted attributes configuration options object.

Constant Summary collapse

OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns configuration options list.

[
  :version,
  :partial_search,
  :client_search,
  :search_max_rows,
  :node_search,
  :users,
  :keys
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Config

Constructs a Chef::EncryptedAttribute::Config object.

Parameters:

  • config (Config, Hash) (defaults to: nil)

    configuration object to clone.



44
45
46
# File 'lib/chef/encrypted_attribute/config.rb', line 44

def initialize(config = nil)
  update!(config) unless config.nil?
end

Instance Method Details

#[](key) ⇒ Mixed

Reads a configuration option.

Parameters:

  • key (String, Symbol)

    configuration option to read.

Returns:

  • (Mixed)

    configuration value.



166
167
168
169
# File 'lib/chef/encrypted_attribute/config.rb', line 166

def [](key)
  key = key.to_sym if key.is_a?(String)
  send(key) if OPTIONS.include?(key)
end

#[]=(key, value) ⇒ Mixed

Sets a configuration option.

Parameters:

  • key (String, Symbol)

    configuration option name to set.

  • value (Mixed)

    configuration value to set.

Returns:

  • (Mixed)

    configuration value.



176
177
178
179
# File 'lib/chef/encrypted_attribute/config.rb', line 176

def []=(key, value)
  key = key.to_sym if key.is_a?(String)
  send(key, value) if OPTIONS.include?(key)
end

#client_search(arg = nil) ⇒ Array<String>

Reads or sets client search query.

This query will return a list of clients that will be able to read the encrypted attribute.

Parameters:

  • arg (String, Array<String>) (defaults to: nil)

    list of client queries to perform.

Returns:

  • (Array<String>)

    list of client queries.

See Also:



86
87
88
# File 'lib/chef/encrypted_attribute/config.rb', line 86

def client_search(arg = nil)
  set_or_return_search_array(:client_search, arg)
end

#keys(arg = nil) ⇒ Array<String, OpenSSL::PKey::RSA>

Reads or sets key list.

This contains the raw key list that will be able to read the encrypted attribute.

Parameters:

  • arg (Array<String, OpenSSL::PKey::RSA>) (defaults to: nil)

    the keys in PEM format.

Returns:

  • (Array<String, OpenSSL::PKey::RSA>)

    the keys in PEM format



137
138
139
140
141
142
143
# File 'lib/chef/encrypted_attribute/config.rb', line 137

def keys(arg = nil)
  set_or_return(
    :keys, arg,
    kind_of: Array, default: [],
    callbacks: config_valid_keys_array_callbacks
  )
end

#node_search(arg = nil) ⇒ Array<String>

Reads or sets node search query.

This query will return a list of nodes that will be able to read the encrypted attribute.

Parameters:

  • arg (String, Array<String>) (defaults to: nil)

    list of node queries to perform.

Returns:

  • (Array<String>)

    list of node queries.



111
112
113
# File 'lib/chef/encrypted_attribute/config.rb', line 111

def node_search(arg = nil)
  set_or_return_search_array(:node_search, arg)
end

#partial_search(arg = nil) ⇒ Boolean

Reads or sets partial search support.

Set it to false to disable partial search. Defaults to true.

Parameters:

  • arg (Boolean) (defaults to: nil)

    whether to enable partial search.

Returns:

  • (Boolean)

    partial search usage.

See Also:



71
72
73
74
75
# File 'lib/chef/encrypted_attribute/config.rb', line 71

def partial_search(arg = nil)
  set_or_return(
    :partial_search, arg, kind_of: [TrueClass, FalseClass], default: true
  )
end

#search_max_rows(arg = nil) ⇒ Integer

Set the maximum number of rows to be returned by internal search functions.

You must set this value to your maximum number of nodes in your Chef Server. Defaults to 1000.

Parameters:

  • arg (Integer) (defaults to: nil)

    maximum rows number.

Returns:

  • (Integer)

    maximum rows number.



98
99
100
101
102
# File 'lib/chef/encrypted_attribute/config.rb', line 98

def search_max_rows(arg = nil)
  set_or_return(
    :search_max_rows, arg, kind_of: Integer, default: 1000
  )
end

#update!(config) ⇒ Config

Replaces the current config.

When setting using a Chef::EncryptedAttribute::Config class, all the configuration options will be replaced.

When setting using a Hash, only the provided keys will be replaced.

Parameters:

  • config (Config, Hash)

    the configuration to set.

Returns:



154
155
156
157
158
159
160
# File 'lib/chef/encrypted_attribute/config.rb', line 154

def update!(config)
  if config.is_a?(self.class)
    update_from_config!(config)
  elsif config.is_a?(Hash)
    update_from_hash!(config)
  end
end

#users(arg = nil) ⇒ Array<String>

Reads or sets user list.

This contains the user list that will be able to read the encrypted attribute.

Parameters:

  • arg (String, Array<String>) (defaults to: nil)

    list of users to set.

Returns:

  • (Array<String>)

    list of users.



122
123
124
125
126
127
128
# File 'lib/chef/encrypted_attribute/config.rb', line 122

def users(arg = nil)
  set_or_return(
    :users, arg,
    kind_of: [String, Array], default: [],
    callbacks: config_users_arg_callbacks
  )
end

#version(arg = nil) ⇒ Fixnum

Reads or sets Encrypted Mash protocol version.

Parameters:

  • arg (String, Fixnum) (defaults to: nil)

    protocol version to use. Must be a number.

Returns:

  • (Fixnum)

    protocol version.



52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/encrypted_attribute/config.rb', line 52

def version(arg = nil)
  unless arg.nil? || !arg.is_a?(String)
    begin
      arg = Integer(arg)
    rescue ArgumentError
      arg
    end
  end
  set_or_return(:version, arg, kind_of: [Fixnum, String], default: 1)
end