chef-api 0.10.0 → 0.10.2
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.
- checksums.yaml +4 -4
- data/lib/chef-api.rb +17 -18
- data/lib/chef-api/aclable.rb +6 -6
- data/lib/chef-api/authentication.rb +18 -19
- data/lib/chef-api/configurable.rb +14 -14
- data/lib/chef-api/connection.rb +36 -36
- data/lib/chef-api/defaults.rb +25 -24
- data/lib/chef-api/error_collection.rb +1 -1
- data/lib/chef-api/errors.rb +3 -3
- data/lib/chef-api/multipart.rb +17 -17
- data/lib/chef-api/resource.rb +17 -17
- data/lib/chef-api/resources/base.rb +22 -22
- data/lib/chef-api/resources/client.rb +4 -3
- data/lib/chef-api/resources/collection_proxy.rb +4 -3
- data/lib/chef-api/resources/cookbook.rb +2 -2
- data/lib/chef-api/resources/cookbook_version.rb +1 -1
- data/lib/chef-api/resources/data_bag.rb +3 -3
- data/lib/chef-api/resources/data_bag_item.rb +2 -3
- data/lib/chef-api/resources/environment.rb +1 -1
- data/lib/chef-api/resources/group.rb +1 -2
- data/lib/chef-api/resources/node.rb +2 -2
- data/lib/chef-api/resources/organization.rb +2 -2
- data/lib/chef-api/resources/partial_search.rb +4 -4
- data/lib/chef-api/resources/principal.rb +1 -1
- data/lib/chef-api/resources/role.rb +1 -1
- data/lib/chef-api/resources/search.rb +6 -6
- data/lib/chef-api/resources/user.rb +3 -3
- data/lib/chef-api/util.rb +8 -8
- data/lib/chef-api/validator.rb +3 -3
- data/lib/chef-api/validators/base.rb +3 -3
- data/lib/chef-api/validators/required.rb +1 -1
- data/lib/chef-api/validators/type.rb +1 -1
- data/lib/chef-api/version.rb +1 -1
- metadata +2 -2
data/lib/chef-api/errors.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "erb"
|
2
2
|
|
3
3
|
module ChefAPI
|
4
4
|
module Error
|
@@ -31,9 +31,9 @@ module ChefAPI
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def template
|
34
|
-
class_name = self.class.to_s.split(
|
34
|
+
class_name = self.class.to_s.split("::").last
|
35
35
|
filename = @filename || Util.underscore(class_name)
|
36
|
-
ChefAPI.root.join(
|
36
|
+
ChefAPI.root.join("templates", "errors", "#{filename}.erb")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/chef-api/multipart.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "cgi"
|
2
|
+
require "mime/types"
|
3
3
|
|
4
4
|
module ChefAPI
|
5
5
|
module Multipart
|
6
|
-
BOUNDARY =
|
6
|
+
BOUNDARY = "------ChefAPIMultipartBoundary".freeze
|
7
7
|
|
8
8
|
class Body
|
9
9
|
def initialize(params = {})
|
@@ -48,12 +48,12 @@ module ChefAPI
|
|
48
48
|
# Read from IOs in order until `length` bytes have been received.
|
49
49
|
def read(length = nil, outbuf = nil)
|
50
50
|
got_result = false
|
51
|
-
outbuf = outbuf ? outbuf.replace(
|
51
|
+
outbuf = outbuf ? outbuf.replace("") : ""
|
52
52
|
|
53
53
|
while io = current_io
|
54
54
|
if result = io.read(length)
|
55
55
|
got_result ||= !result.nil?
|
56
|
-
result.force_encoding(
|
56
|
+
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
57
57
|
outbuf << result
|
58
58
|
length -= result.length if length
|
59
59
|
break if length == 0
|
@@ -65,7 +65,7 @@ module ChefAPI
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def rewind
|
68
|
-
@ios.each
|
68
|
+
@ios.each(&:rewind)
|
69
69
|
@index = 0
|
70
70
|
end
|
71
71
|
|
@@ -99,9 +99,9 @@ module ChefAPI
|
|
99
99
|
private
|
100
100
|
|
101
101
|
def build(name, value)
|
102
|
-
part =
|
103
|
-
part <<
|
104
|
-
part <<
|
102
|
+
part = %{--#{BOUNDARY}\r\n}
|
103
|
+
part << %{Content-Disposition: form-data; name="#{CGI.escape(name)}"\r\n\r\n}
|
104
|
+
part << %{#{value}\r\n}
|
105
105
|
part
|
106
106
|
end
|
107
107
|
end
|
@@ -132,14 +132,14 @@ module ChefAPI
|
|
132
132
|
|
133
133
|
def build(name, file)
|
134
134
|
filename = File.basename(file.path)
|
135
|
-
mime_type = MIME::Types.type_for(filename)[0] || MIME::Types[
|
136
|
-
|
137
|
-
part =
|
138
|
-
part <<
|
139
|
-
part <<
|
140
|
-
part <<
|
141
|
-
part <<
|
142
|
-
part <<
|
135
|
+
mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0]
|
136
|
+
|
137
|
+
part = %{--#{BOUNDARY}\r\n}
|
138
|
+
part << %{Content-Disposition: form-data; name="#{CGI.escape(name)}"; filename="#{filename}"\r\n}
|
139
|
+
part << %{Content-Length: #{file.size}\r\n}
|
140
|
+
part << %{Content-Type: #{mime_type.simplified}\r\n}
|
141
|
+
part << %{Content-Transfer-Encoding: binary\r\n}
|
142
|
+
part << %{\r\n}
|
143
143
|
part
|
144
144
|
end
|
145
145
|
end
|
data/lib/chef-api/resource.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
|
1
|
+
require_relative "aclable"
|
2
2
|
module ChefAPI
|
3
3
|
module Resource
|
4
|
-
autoload :Base,
|
5
|
-
autoload :Client,
|
6
|
-
autoload :CollectionProxy,
|
7
|
-
autoload :Cookbook,
|
8
|
-
autoload :CookbookVersion,
|
9
|
-
autoload :DataBag,
|
10
|
-
autoload :DataBagItem,
|
11
|
-
autoload :Environment,
|
12
|
-
autoload :Group,
|
13
|
-
autoload :Node,
|
14
|
-
autoload :Organization,
|
15
|
-
autoload :PartialSearch,
|
16
|
-
autoload :Principal,
|
17
|
-
autoload :Role,
|
18
|
-
autoload :Search,
|
19
|
-
autoload :User,
|
4
|
+
autoload :Base, "chef-api/resources/base"
|
5
|
+
autoload :Client, "chef-api/resources/client"
|
6
|
+
autoload :CollectionProxy, "chef-api/resources/collection_proxy"
|
7
|
+
autoload :Cookbook, "chef-api/resources/cookbook"
|
8
|
+
autoload :CookbookVersion, "chef-api/resources/cookbook_version"
|
9
|
+
autoload :DataBag, "chef-api/resources/data_bag"
|
10
|
+
autoload :DataBagItem, "chef-api/resources/data_bag_item"
|
11
|
+
autoload :Environment, "chef-api/resources/environment"
|
12
|
+
autoload :Group, "chef-api/resources/group"
|
13
|
+
autoload :Node, "chef-api/resources/node"
|
14
|
+
autoload :Organization, "chef-api/resources/organization"
|
15
|
+
autoload :PartialSearch, "chef-api/resources/partial_search"
|
16
|
+
autoload :Principal, "chef-api/resources/principal"
|
17
|
+
autoload :Role, "chef-api/resources/role"
|
18
|
+
autoload :Search, "chef-api/resources/search"
|
19
|
+
autoload :User, "chef-api/resources/user"
|
20
20
|
end
|
21
21
|
end
|
@@ -13,7 +13,7 @@ module ChefAPI
|
|
13
13
|
# the path to the file on disk
|
14
14
|
#
|
15
15
|
def from_file(path)
|
16
|
-
raise Error::AbstractMethod.new(method:
|
16
|
+
raise Error::AbstractMethod.new(method: "Resource::Base#from_file")
|
17
17
|
end
|
18
18
|
|
19
19
|
#
|
@@ -78,7 +78,7 @@ module ChefAPI
|
|
78
78
|
# has_many :environments, class_name: 'Environment'
|
79
79
|
#
|
80
80
|
def has_many(method, options = {})
|
81
|
-
class_name = options[:class_name] || "Resource::#{Util.camelize(method).sub(/s$/,
|
81
|
+
class_name = options[:class_name] || "Resource::#{Util.camelize(method).sub(/s$/, "")}"
|
82
82
|
rest_endpoint = options[:rest_endpoint] || method
|
83
83
|
|
84
84
|
class_eval <<-EOH, __FILE__, __LINE__ + 1
|
@@ -227,7 +227,7 @@ module ChefAPI
|
|
227
227
|
# an array containing the list of resources that were deleted
|
228
228
|
#
|
229
229
|
def destroy_all(prefix = {})
|
230
|
-
map
|
230
|
+
map(&:destroy)
|
231
231
|
end
|
232
232
|
|
233
233
|
#
|
@@ -404,8 +404,8 @@ module ChefAPI
|
|
404
404
|
# an instance of the resource represented by this JSON
|
405
405
|
#
|
406
406
|
def from_json(response, prefix = {})
|
407
|
-
response.delete(
|
408
|
-
response.delete(
|
407
|
+
response.delete("json_class")
|
408
|
+
response.delete("chef_type")
|
409
409
|
|
410
410
|
new(response, prefix)
|
411
411
|
end
|
@@ -432,7 +432,7 @@ module ChefAPI
|
|
432
432
|
# @return [String]
|
433
433
|
#
|
434
434
|
def inspect
|
435
|
-
"#{classname}(#{schema.attributes.keys.join(
|
435
|
+
"#{classname}(#{schema.attributes.keys.join(", ")})"
|
436
436
|
end
|
437
437
|
|
438
438
|
#
|
@@ -444,7 +444,7 @@ module ChefAPI
|
|
444
444
|
# @return [String]
|
445
445
|
#
|
446
446
|
def classname
|
447
|
-
name.split(
|
447
|
+
name.split("::")[1..-1].join("::")
|
448
448
|
end
|
449
449
|
|
450
450
|
#
|
@@ -456,7 +456,7 @@ module ChefAPI
|
|
456
456
|
# @return [String]
|
457
457
|
#
|
458
458
|
def type
|
459
|
-
Util.underscore(name.split(
|
459
|
+
Util.underscore(name.split("::").last).gsub("_", " ")
|
460
460
|
end
|
461
461
|
|
462
462
|
#
|
@@ -482,7 +482,7 @@ module ChefAPI
|
|
482
482
|
# the path to the resource
|
483
483
|
#
|
484
484
|
def resource_path(id, prefix = {})
|
485
|
-
[expanded_collection_path(prefix), id].join(
|
485
|
+
[expanded_collection_path(prefix), id].join("/")
|
486
486
|
end
|
487
487
|
|
488
488
|
#
|
@@ -505,7 +505,7 @@ module ChefAPI
|
|
505
505
|
#
|
506
506
|
def expanded_collection_path(prefix = {})
|
507
507
|
collection_path.gsub(/:\w+/) do |param|
|
508
|
-
key = param.delete(
|
508
|
+
key = param.delete(":")
|
509
509
|
value = prefix[key] || prefix[key.to_sym]
|
510
510
|
|
511
511
|
if value.nil?
|
@@ -513,7 +513,7 @@ module ChefAPI
|
|
513
513
|
end
|
514
514
|
|
515
515
|
URI.escape(value)
|
516
|
-
end.sub(
|
516
|
+
end.sub(%r{^/}, "") # Remove leading slash
|
517
517
|
end
|
518
518
|
|
519
519
|
#
|
@@ -522,7 +522,7 @@ module ChefAPI
|
|
522
522
|
# @return [ChefAPI::Connection]
|
523
523
|
#
|
524
524
|
def connection
|
525
|
-
Thread.current[
|
525
|
+
Thread.current["chefapi.connection"] || ChefAPI.connection
|
526
526
|
end
|
527
527
|
end
|
528
528
|
|
@@ -620,7 +620,7 @@ module ChefAPI
|
|
620
620
|
# true if the attribute exists, false otherwise
|
621
621
|
#
|
622
622
|
def attribute?(key)
|
623
|
-
_attributes.
|
623
|
+
_attributes.key?(key.to_sym)
|
624
624
|
end
|
625
625
|
|
626
626
|
#
|
@@ -633,12 +633,12 @@ module ChefAPI
|
|
633
633
|
#
|
634
634
|
def protected?
|
635
635
|
@protected ||= self.class.protected_resources.any? do |thing|
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
636
|
+
if thing.is_a?(Proc)
|
637
|
+
thing.call(self)
|
638
|
+
else
|
639
|
+
id == thing
|
640
|
+
end
|
641
|
+
end
|
642
642
|
end
|
643
643
|
|
644
644
|
#
|
@@ -775,7 +775,7 @@ module ChefAPI
|
|
775
775
|
#
|
776
776
|
def validate!
|
777
777
|
unless valid?
|
778
|
-
sentence = errors.full_messages.join(
|
778
|
+
sentence = errors.full_messages.join(", ")
|
779
779
|
raise Error::InvalidResource.new(errors: sentence)
|
780
780
|
end
|
781
781
|
|
@@ -896,7 +896,7 @@ module ChefAPI
|
|
896
896
|
# @return [Boolean]
|
897
897
|
#
|
898
898
|
def ignore_attribute?(key)
|
899
|
-
@schema.ignored_attributes.
|
899
|
+
@schema.ignored_attributes.key?(key.to_sym)
|
900
900
|
end
|
901
901
|
|
902
902
|
#
|
@@ -954,7 +954,7 @@ module ChefAPI
|
|
954
954
|
end
|
955
955
|
end
|
956
956
|
|
957
|
-
"#<#{self.class.classname} #{attrs.join(
|
957
|
+
"#<#{self.class.classname} #{attrs.join(", ")}>"
|
958
958
|
end
|
959
959
|
end
|
960
960
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ChefAPI
|
2
2
|
class Resource::Client < Resource::Base
|
3
3
|
include ChefAPI::AclAble
|
4
|
-
collection_path
|
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
|
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
|
-
|
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.
|
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
|
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
|
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:
|
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::DataBag < Resource::Base
|
3
|
-
collection_path
|
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
|
29
|
+
path = File.expand_path(path)
|
30
30
|
|
31
|
-
raise Error::FileNotFound.new(path: path) unless File.
|
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
|
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(
|
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,7 +1,7 @@
|
|
1
1
|
module ChefAPI
|
2
2
|
class Resource::Node < Resource::Base
|
3
3
|
include ChefAPI::AclAble
|
4
|
-
collection_path
|
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:
|
17
|
+
attribute :chef_environment, type: String, default: "_default"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|