chef-infra-api 0.9.1 → 0.10.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  module ChefAPI
2
2
  class Resource::Client < Resource::Base
3
3
  include ChefAPI::AclAble
4
- collection_path '/clients'
4
+ collection_path "/clients"
5
5
 
6
6
  schema do
7
7
  attribute :name, type: String, primary: true, required: true
@@ -14,7 +14,7 @@ module ChefAPI
14
14
  end
15
15
 
16
16
  # @todo implement
17
- protect 'chef-webui', 'chef-validator'
17
+ protect "chef-webui", "chef-validator"
18
18
 
19
19
  class << self
20
20
  #
@@ -49,7 +49,7 @@ module ChefAPI
49
49
  #
50
50
  def initialize(attributes = {}, prefix = {})
51
51
  if certificate = attributes.delete(:certificate) ||
52
- attributes.delete('certificate')
52
+ attributes.delete("certificate")
53
53
  x509 = OpenSSL::X509::Certificate.new(certificate)
54
54
  attributes[:public_key] = x509.public_key.to_pem
55
55
  end
@@ -77,6 +77,7 @@ module ChefAPI
77
77
  #
78
78
  def regenerate_keys
79
79
  raise Error::CannotRegenerateKey if new_resource?
80
+
80
81
  update(private_key: true).save!
81
82
  self
82
83
  end
@@ -59,6 +59,7 @@ module ChefAPI
59
59
  #
60
60
  def fetch(id)
61
61
  return nil unless exists?(id)
62
+
62
63
  cached(id) { klass.from_url(get(id), prefix) }
63
64
  end
64
65
 
@@ -76,7 +77,7 @@ module ChefAPI
76
77
  # true if the resource exists, false otherwise
77
78
  #
78
79
  def exists?(id)
79
- collection.has_key?(id.to_s)
80
+ collection.key?(id.to_s)
80
81
  end
81
82
 
82
83
  #
@@ -131,9 +132,9 @@ module ChefAPI
131
132
  def inspect
132
133
  objects = collection
133
134
  .map { |id, _| cached(id) || klass.new(klass.schema.primary_key => id) }
134
- .map { |object| object.to_s }
135
+ .map(&:to_s)
135
136
 
136
- "#<#{self.class.name} [#{objects.join(', ')}]>"
137
+ "#<#{self.class.name} [#{objects.join(", ")}]>"
137
138
  end
138
139
 
139
140
  private
@@ -5,7 +5,7 @@ module ChefAPI
5
5
  # of +cookbook_version+ objects that fully detail the layout of a cookbook.
6
6
  #
7
7
  class Resource::Cookbook < Resource::Base
8
- collection_path '/cookbooks'
8
+ collection_path "/cookbooks"
9
9
 
10
10
  schema do
11
11
  attribute :name, type: String, primary: true, required: true
@@ -13,7 +13,7 @@ module ChefAPI
13
13
 
14
14
  has_many :versions,
15
15
  class_name: CookbookVersion,
16
- rest_endpoint: '/?num_versions=all'
16
+ rest_endpoint: "/?num_versions=all"
17
17
 
18
18
  class << self
19
19
  def from_json(response, prefix = {})
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::CookbookVersion < Resource::Base
3
- collection_path '/cookbooks/:cookbook'
3
+ collection_path "/cookbooks/:cookbook"
4
4
 
5
5
  schema do
6
6
  attribute :name, type: String, primary: true, required: true
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::DataBag < Resource::Base
3
- collection_path '/data'
3
+ collection_path "/data"
4
4
 
5
5
  schema do
6
6
  attribute :name, type: String, primary: true, required: true
@@ -26,9 +26,9 @@ module ChefAPI
26
26
  # @return [Array<DataBagItem>]
27
27
  #
28
28
  def from_file(path, name = File.basename(path))
29
- path = File.expand_path(path)
29
+ path = File.expand_path(path)
30
30
 
31
- raise Error::FileNotFound.new(path: path) unless File.exists?(path)
31
+ raise Error::FileNotFound.new(path: path) unless File.exist?(path)
32
32
  raise Error::NotADirectory.new(path: path) unless File.directory?(path)
33
33
 
34
34
  raise ArgumentError unless File.directory?(path)
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::DataBagItem < Resource::Base
3
- collection_path '/data/:bag'
3
+ collection_path "/data/:bag"
4
4
 
5
5
  schema do
6
6
  attribute :id, type: String, primary: true, required: true
@@ -28,11 +28,10 @@ module ChefAPI
28
28
  def initialize(attributes = {}, prefix = {}, bag = nil)
29
29
  @bag = bag || Resource::DataBag.fetch(prefix[:bag])
30
30
 
31
- id = attributes.delete(:id) || attributes.delete('id')
31
+ id = attributes.delete(:id) || attributes.delete("id")
32
32
  super({ id: id, data: attributes }, prefix)
33
33
  end
34
34
 
35
-
36
35
  #
37
36
  # Override the to_hash method to move data to the upper scope.
38
37
  #
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::Environment < Resource::Base
3
- collection_path '/environments'
3
+ collection_path "/environments"
4
4
 
5
5
  schema do
6
6
  attribute :name, type: String, primary: true, required: true
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::Group < Resource::Base
3
- collection_path '/groups'
3
+ collection_path "/groups"
4
4
 
5
5
  schema do
6
6
  attribute :groupname, type: String, primary: true, required: true
@@ -13,4 +13,3 @@ module ChefAPI
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -1,7 +1,7 @@
1
1
  module ChefAPI
2
2
  class Resource::Node < Resource::Base
3
3
  include ChefAPI::AclAble
4
- collection_path '/nodes'
4
+ collection_path "/nodes"
5
5
 
6
6
  schema do
7
7
  attribute :name, type: String, primary: true, required: true
@@ -14,7 +14,7 @@ module ChefAPI
14
14
  attribute :policy_group, type: String
15
15
 
16
16
  # Enterprise Chef attributes
17
- attribute :chef_environment, type: String, default: '_default'
17
+ attribute :chef_environment, type: String, default: "_default"
18
18
  end
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::Organization < Resource::Base
3
- collection_path '/organizations'
3
+ collection_path "/organizations"
4
4
 
5
5
  schema do
6
6
  attribute :name, type: String, primary: true, required: true
@@ -16,7 +16,7 @@ module ChefAPI
16
16
  ignore :billing_plan
17
17
  ignore :requester_id
18
18
  ignore :assigned_at
19
- ignore 'couchrest-type'
19
+ ignore "couchrest-type"
20
20
  end
21
21
  end
22
22
  end
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::PartialSearch < Resource::Base
3
- collection_path '/search/:index'
3
+ collection_path "/search/:index"
4
4
 
5
5
  schema do
6
6
  attribute :total, type: Integer
@@ -24,19 +24,19 @@ module ChefAPI
24
24
  # @return [self]
25
25
  # the current resource
26
26
  #
27
- def query(index, keys, query = '*:*', options = {})
27
+ def query(index, keys, query = "*:*", options = {})
28
28
  return nil if index.nil?
29
29
 
30
30
  params = {}.tap do |o|
31
31
  o[:q] = query
32
32
  o[:rows] = options[:rows] || 1000
33
- o[:sort] = options[:sort] || 'X_CHEF_id_CHEF_X'
33
+ o[:sort] = options[:sort] || "X_CHEF_id_CHEF_X"
34
34
  o[:start] = options[:start] || 0
35
35
  end
36
36
 
37
37
  path = expanded_collection_path(index: index.to_s)
38
38
  response = connection.post(path, keys.to_json, params)
39
- response['rows'].map! { |row| row['data'] }
39
+ response["rows"].map! { |row| row["data"] }
40
40
  from_json(response, index: index.to_s)
41
41
  end
42
42
  end
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::Principal < Resource::Base
3
- collection_path '/principals'
3
+ collection_path "/principals"
4
4
 
5
5
  schema do
6
6
  attribute :name, type: String, primary: true, required: true
@@ -1,7 +1,7 @@
1
1
  module ChefAPI
2
2
  class Resource::Role < Resource::Base
3
3
  include ChefAPI::AclAble
4
- collection_path '/roles'
4
+ collection_path "/roles"
5
5
 
6
6
  schema do
7
7
  attribute :name, type: String, primary: true, required: true
@@ -1,6 +1,6 @@
1
1
  module ChefAPI
2
2
  class Resource::Search < Resource::Base
3
- collection_path '/search/:index'
3
+ collection_path "/search/:index"
4
4
 
5
5
  schema do
6
6
  attribute :total, type: Integer
@@ -22,22 +22,22 @@ module ChefAPI
22
22
  # @return [self]
23
23
  # the current resource
24
24
  #
25
- def query(index, query = '*:*', options = {})
25
+ def query(index, query = "*:*", options = {})
26
26
  return nil if index.nil?
27
27
 
28
28
  params = {}.tap do |o|
29
29
  o[:q] = query
30
30
  o[:rows] = options[:rows] || 1000
31
- o[:sort] = options[:sort] || 'X_CHEF_id_CHEF_X'
31
+ o[:sort] = options[:sort] || "X_CHEF_id_CHEF_X"
32
32
  o[:start] = options[:start] || 0
33
33
  end
34
34
 
35
35
  path = expanded_collection_path(index: index.to_s)
36
36
 
37
37
  response = if filter_result = options[:filter_result]
38
- connection.post(path, filter_result.to_json, params)
39
- else
40
- connection.get(path, params)
38
+ connection.post(path, filter_result.to_json, params)
39
+ else
40
+ connection.get(path, params)
41
41
  end
42
42
 
43
43
  from_json(response, index: index.to_s)
@@ -1,6 +1,8 @@
1
1
  module ChefAPI
2
2
  class Resource::User < Resource::Base
3
- collection_path '/users'
3
+ require "cgi" unless defined?(CGI)
4
+
5
+ collection_path "/users"
4
6
 
5
7
  schema do
6
8
  flavor :enterprise do
@@ -38,7 +40,7 @@ module ChefAPI
38
40
  # HEC/EC returns a slightly different response than OSC/CZ
39
41
  if users.is_a?(Array)
40
42
  users.each do |info|
41
- name = URI.escape(info['user']['username'])
43
+ name = CGI.escape(info["user"]["username"])
42
44
  response = connection.get("/users/#{name}")
43
45
  result = from_json(response, prefix)
44
46
 
@@ -75,7 +77,7 @@ module ChefAPI
75
77
  # the parsed JSON response from the server
76
78
  #
77
79
  def authenticate(options = {})
78
- connection.post('/authenticate_user', options.to_json)
80
+ connection.post("/authenticate_user", options.to_json)
79
81
  end
80
82
  end
81
83
  end
@@ -14,10 +14,10 @@ module ChefAPI
14
14
  def underscore(string)
15
15
  string
16
16
  .to_s
17
- .gsub(/::/, '/')
18
- .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
19
- .gsub(/([a-z\d])([A-Z])/,'\1_\2')
20
- .tr('-', '_')
17
+ .gsub(/::/, "/")
18
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
19
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
20
+ .tr("-", "_")
21
21
  .downcase
22
22
  end
23
23
 
@@ -32,8 +32,8 @@ module ChefAPI
32
32
  def camelize(string)
33
33
  string
34
34
  .to_s
35
- .split('_')
36
- .map { |e| e.capitalize }
35
+ .split("_")
36
+ .map(&:capitalize)
37
37
  .join
38
38
  end
39
39
 
@@ -49,7 +49,7 @@ module ChefAPI
49
49
  length = options[:length] || 30
50
50
 
51
51
  if string.length > length
52
- string[0..length-3] + '...'
52
+ string[0..length - 3] + "..."
53
53
  else
54
54
  string
55
55
  end
@@ -77,7 +77,7 @@ module ChefAPI
77
77
  #
78
78
  def safe_read(path)
79
79
  path = File.expand_path(path)
80
- name = File.basename(path, '.*')
80
+ name = File.basename(path, ".*")
81
81
  contents = File.read(path)
82
82
 
83
83
  [name, contents]
@@ -1,8 +1,8 @@
1
1
  module ChefAPI
2
2
  module Validator
3
- autoload :Base, 'chef-api/validators/base'
4
- autoload :Required, 'chef-api/validators/required'
5
- autoload :Type, 'chef-api/validators/type'
3
+ autoload :Base, "chef-api/validators/base"
4
+ autoload :Required, "chef-api/validators/required"
5
+ autoload :Type, "chef-api/validators/type"
6
6
 
7
7
  #
8
8
  # Find a validator by the given key.
@@ -35,7 +35,7 @@ module ChefAPI
35
35
  # @return [Symbol]
36
36
  #
37
37
  def key
38
- name = self.class.name.split('::').last
38
+ name = self.class.name.split("::").last
39
39
  Util.underscore(name).to_sym
40
40
  end
41
41
 
@@ -47,7 +47,7 @@ module ChefAPI
47
47
  # the parent resource to validate against
48
48
  #
49
49
  def validate(resource)
50
- raise Error::AbstractMethod.new(method: 'Validators::Base#validate')
50
+ raise Error::AbstractMethod.new(method: "Validators::Base#validate")
51
51
  end
52
52
 
53
53
  #
@@ -76,7 +76,7 @@ module ChefAPI
76
76
  # @return [String]
77
77
  #
78
78
  def classname
79
- @classname ||= self.class.name.split('::')[1..-1].join('::')
79
+ @classname ||= self.class.name.split("::")[1..-1].join("::")
80
80
  end
81
81
  end
82
82
  end
@@ -4,7 +4,7 @@ module ChefAPI
4
4
  value = resource._attributes[attribute]
5
5
 
6
6
  if value.to_s.strip.empty?
7
- resource.errors.add(attribute, 'must be present')
7
+ resource.errors.add(attribute, "must be present")
8
8
  end
9
9
  end
10
10
  end
@@ -15,7 +15,7 @@ module ChefAPI
15
15
  value = resource._attributes[attribute]
16
16
 
17
17
  if value && !types.any? { |type| value.is_a?(type) }
18
- short_name = type.to_s.split('::').last
18
+ short_name = types.to_s.split("::").last
19
19
  resource.errors.add(attribute, "must be a kind of #{short_name}")
20
20
  end
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module ChefAPI
2
- VERSION = '0.9.1'
2
+ VERSION = "0.10.10".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-infra-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-19 00:00:00.000000000 Z
12
+ date: 2020-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: logify
15
+ name: mixlib-log
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '1'
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: '0.1'
23
+ version: '4'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '1'
31
+ - - "<"
26
32
  - !ruby/object:Gem::Version
27
- version: '0.1'
33
+ version: '4'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: mime-types
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +45,7 @@ dependencies:
39
45
  - - ">="
40
46
  - !ruby/object:Gem::Version
41
47
  version: '0'
42
- description: A tiny Chef API client with minimal dependencies
48
+ description: A tiny Chef Infra API client with minimal dependencies
43
49
  email:
44
50
  - sethvargo@gmail.com
45
51
  - tsmith84@gmail.com
@@ -57,6 +63,7 @@ files:
57
63
  - lib/chef-api/defaults.rb
58
64
  - lib/chef-api/error_collection.rb
59
65
  - lib/chef-api/errors.rb
66
+ - lib/chef-api/log.rb
60
67
  - lib/chef-api/multipart.rb
61
68
  - lib/chef-api/resource.rb
62
69
  - lib/chef-api/resources/base.rb
@@ -115,16 +122,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
122
  requirements:
116
123
  - - ">="
117
124
  - !ruby/object:Gem::Version
118
- version: '2.2'
125
+ version: '2.3'
119
126
  required_rubygems_version: !ruby/object:Gem::Requirement
120
127
  requirements:
121
128
  - - ">="
122
129
  - !ruby/object:Gem::Version
123
130
  version: '0'
124
131
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.7.9
132
+ rubygems_version: 3.0.3
127
133
  signing_key:
128
134
  specification_version: 4
129
- summary: A Chef API client in Ruby
135
+ summary: A Chef Infra API client in Ruby
130
136
  test_files: []