Class: Chef::EncryptedAttribute::RemoteClients

Inherits:
Object
  • Object
show all
Extended by:
SearchHelper
Defined in:
lib/chef/encrypted_attribute/remote_clients.rb

Overview

Search remote Chef Clients public keys.

Class Method Summary collapse

Methods included from SearchHelper

assert_normal_search_response, assert_partial_search_response, assert_search_keys, catch_search_exceptions, empty_search?, escape, escape_query, filter_normal_search_response, filter_partial_search_response, generate_partial_search_keys, normal_search, parse_normal_search_response, parse_normal_search_row_attribute, parse_partial_search_response, partial_search, query, search, search_by_name, valid_search_keys?, valid_search_keys_key?, valid_search_keys_value?

Class Method Details

.cacheCacheLru

Remote clients search results cache.

You can disable it setting it's size to zero:

Chef::EncryptedAttribute::RemoteClients.cache.max_size(0)

Returns:

  • (CacheLru)

    Remote clients LRU cache.


41
42
43
# File 'lib/chef/encrypted_attribute/remote_clients.rb', line 41

def self.cache
  @@cache ||= Chef::EncryptedAttribute::CacheLru.new
end

.get_public_key(name) ⇒ String

Gets remote client public key.

Parameters:

  • name (String)

    Chef client name.

Returns:

  • (String)

    Chef client public key as string.

Raises:

  • (ClientNotFound)

    if client does not exist.

  • (Net::HTTPServerException)

    for Chef Server HTTP errors.


51
52
53
54
55
56
# File 'lib/chef/encrypted_attribute/remote_clients.rb', line 51

def self.get_public_key(name)
  Chef::ApiClient.load(name).public_key
rescue Net::HTTPServerException => e
  raise e unless e.response.code == '404'
  raise ClientNotFound, "Chef Client not found: #{name.inspect}."
end

.search_public_keys(search = '*:*', rows = 1000, partial_search = true) ⇒ Array<String>

Searches for chef client public keys.

Parameters:

  • search (Array<String>, String) (defaults to: '*:*')

    search queries to perform, the query result will be OR-ed.

  • rows (Integer) (defaults to: 1000)

    maximum number of rows to return in searches.

  • partial_search (Boolean) (defaults to: true)

    whether to use partial search.

Returns:

  • (Array<String>)

    list of public keys.

Raises:


68
69
70
71
72
73
74
75
76
77
# File 'lib/chef/encrypted_attribute/remote_clients.rb', line 68

def self.search_public_keys(
      search = '*:*', rows = 1000, partial_search = true
)
  escaped_query = escape_query(search)
  return cache[escaped_query] if cache.key?(escaped_query)
  cache[escaped_query] = search(
    :client, search,
    { 'public_key' => %w(public_key) }, rows, partial_search
  ).map { |client| client['public_key'] }.compact
end