chef-infra-api 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/lib/chef-api.rb +96 -0
- data/lib/chef-api/aclable.rb +35 -0
- data/lib/chef-api/authentication.rb +300 -0
- data/lib/chef-api/boolean.rb +6 -0
- data/lib/chef-api/configurable.rb +80 -0
- data/lib/chef-api/connection.rb +507 -0
- data/lib/chef-api/defaults.rb +197 -0
- data/lib/chef-api/error_collection.rb +44 -0
- data/lib/chef-api/errors.rb +64 -0
- data/lib/chef-api/multipart.rb +164 -0
- data/lib/chef-api/resource.rb +21 -0
- data/lib/chef-api/resources/base.rb +960 -0
- data/lib/chef-api/resources/client.rb +84 -0
- data/lib/chef-api/resources/collection_proxy.rb +234 -0
- data/lib/chef-api/resources/cookbook.rb +24 -0
- data/lib/chef-api/resources/cookbook_version.rb +23 -0
- data/lib/chef-api/resources/data_bag.rb +136 -0
- data/lib/chef-api/resources/data_bag_item.rb +53 -0
- data/lib/chef-api/resources/environment.rb +16 -0
- data/lib/chef-api/resources/group.rb +16 -0
- data/lib/chef-api/resources/node.rb +20 -0
- data/lib/chef-api/resources/organization.rb +22 -0
- data/lib/chef-api/resources/partial_search.rb +44 -0
- data/lib/chef-api/resources/principal.rb +11 -0
- data/lib/chef-api/resources/role.rb +18 -0
- data/lib/chef-api/resources/search.rb +47 -0
- data/lib/chef-api/resources/user.rb +82 -0
- data/lib/chef-api/schema.rb +150 -0
- data/lib/chef-api/util.rb +119 -0
- data/lib/chef-api/validator.rb +16 -0
- data/lib/chef-api/validators/base.rb +82 -0
- data/lib/chef-api/validators/required.rb +11 -0
- data/lib/chef-api/validators/type.rb +23 -0
- data/lib/chef-api/version.rb +3 -0
- data/templates/errors/abstract_method.erb +5 -0
- data/templates/errors/cannot_regenerate_key.erb +1 -0
- data/templates/errors/chef_api_error.erb +1 -0
- data/templates/errors/file_not_found.erb +1 -0
- data/templates/errors/http_bad_request.erb +3 -0
- data/templates/errors/http_forbidden_request.erb +3 -0
- data/templates/errors/http_gateway_timeout.erb +3 -0
- data/templates/errors/http_method_not_allowed.erb +3 -0
- data/templates/errors/http_not_acceptable.erb +3 -0
- data/templates/errors/http_not_found.erb +3 -0
- data/templates/errors/http_server_unavailable.erb +1 -0
- data/templates/errors/http_unauthorized_request.erb +3 -0
- data/templates/errors/insufficient_file_permissions.erb +1 -0
- data/templates/errors/invalid_resource.erb +1 -0
- data/templates/errors/invalid_validator.erb +1 -0
- data/templates/errors/missing_url_parameter.erb +1 -0
- data/templates/errors/not_a_directory.erb +1 -0
- data/templates/errors/resource_already_exists.erb +1 -0
- data/templates/errors/resource_not_found.erb +1 -0
- data/templates/errors/resource_not_mutable.erb +1 -0
- data/templates/errors/unknown_attribute.erb +1 -0
- metadata +130 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
module ChefAPI
|
2
|
+
module Util
|
3
|
+
extend self
|
4
|
+
|
5
|
+
#
|
6
|
+
# Covert the given CaMelCaSeD string to under_score. Graciously borrowed
|
7
|
+
# from http://stackoverflow.com/questions/1509915.
|
8
|
+
#
|
9
|
+
# @param [String] string
|
10
|
+
# the string to use for transformation
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
def underscore(string)
|
15
|
+
string
|
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('-', '_')
|
21
|
+
.downcase
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Convert an underscored string to it's camelcase equivalent constant.
|
26
|
+
#
|
27
|
+
# @param [String] string
|
28
|
+
# the string to convert
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
#
|
32
|
+
def camelize(string)
|
33
|
+
string
|
34
|
+
.to_s
|
35
|
+
.split('_')
|
36
|
+
.map { |e| e.capitalize }
|
37
|
+
.join
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Truncate the given string to a certain number of characters.
|
42
|
+
#
|
43
|
+
# @param [String] string
|
44
|
+
# the string to truncate
|
45
|
+
# @param [Hash] options
|
46
|
+
# the list of options (such as +length+)
|
47
|
+
#
|
48
|
+
def truncate(string, options = {})
|
49
|
+
length = options[:length] || 30
|
50
|
+
|
51
|
+
if string.length > length
|
52
|
+
string[0..length-3] + '...'
|
53
|
+
else
|
54
|
+
string
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# "Safely" read the contents of a file on disk, catching any permission
|
60
|
+
# errors or not found errors and raising a nicer exception.
|
61
|
+
#
|
62
|
+
# @example Reading a file that does not exist
|
63
|
+
# safe_read('/non-existent/file') #=> Error::FileNotFound
|
64
|
+
#
|
65
|
+
# @example Reading a file with improper permissions
|
66
|
+
# safe_read('/bad-permissions') #=> Error::InsufficientFilePermissions
|
67
|
+
#
|
68
|
+
# @example Reading a regular file
|
69
|
+
# safe_read('my-file.txt') #=> ["my-file", "..."]
|
70
|
+
#
|
71
|
+
# @param [String] path
|
72
|
+
# the path to the file on disk
|
73
|
+
#
|
74
|
+
# @return [Array<String>]
|
75
|
+
# A array where the first value is the basename of the file and the
|
76
|
+
# second value is the literal contents from +File.read+.
|
77
|
+
#
|
78
|
+
def safe_read(path)
|
79
|
+
path = File.expand_path(path)
|
80
|
+
name = File.basename(path, '.*')
|
81
|
+
contents = File.read(path)
|
82
|
+
|
83
|
+
[name, contents]
|
84
|
+
rescue Errno::EACCES
|
85
|
+
raise Error::InsufficientFilePermissions.new(path: path)
|
86
|
+
rescue Errno::ENOENT
|
87
|
+
raise Error::FileNotFound.new(path: path)
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Quickly iterate over a collection using native Ruby threads, preserving
|
92
|
+
# the original order of elements and being all thread-safe and stuff.
|
93
|
+
#
|
94
|
+
# @example Parse a collection of JSON files
|
95
|
+
#
|
96
|
+
# fast_collect(Dir['**/*.json']) do |item|
|
97
|
+
# JSON.parse(File.read(item))
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# @param [#each] collection
|
101
|
+
# the collection to iterate
|
102
|
+
# @param [Proc] block
|
103
|
+
# the block to evaluate (typically an expensive operation)
|
104
|
+
#
|
105
|
+
# @return [Array]
|
106
|
+
# the result of the iteration
|
107
|
+
#
|
108
|
+
def fast_collect(collection, &block)
|
109
|
+
collection.map do |item|
|
110
|
+
Thread.new do
|
111
|
+
Thread.current[:result] = block.call(item)
|
112
|
+
end
|
113
|
+
end.collect do |thread|
|
114
|
+
thread.join
|
115
|
+
thread[:result]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ChefAPI
|
2
|
+
module Validator
|
3
|
+
autoload :Base, 'chef-api/validators/base'
|
4
|
+
autoload :Required, 'chef-api/validators/required'
|
5
|
+
autoload :Type, 'chef-api/validators/type'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Find a validator by the given key.
|
9
|
+
#
|
10
|
+
def self.find(key)
|
11
|
+
const_get(Util.camelize(key))
|
12
|
+
rescue NameError
|
13
|
+
raise Error::InvalidValidator.new(key: key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module ChefAPI
|
2
|
+
class Validator::Base
|
3
|
+
#
|
4
|
+
# @return [Symbol]
|
5
|
+
# the attribute to apply this validation on
|
6
|
+
#
|
7
|
+
attr_reader :attribute
|
8
|
+
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
# the hash of additional arguments passed in
|
12
|
+
#
|
13
|
+
attr_reader :options
|
14
|
+
|
15
|
+
#
|
16
|
+
# Create anew validator.
|
17
|
+
#
|
18
|
+
# @param [Symbol] attribute
|
19
|
+
# the attribute to apply this validation on
|
20
|
+
# @param [Hash] options
|
21
|
+
# the list of options passed in
|
22
|
+
#
|
23
|
+
def initialize(attribute, options = {})
|
24
|
+
@attribute = attribute
|
25
|
+
@options = options.is_a?(Hash) ? options : {}
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Just in case someone forgets to define a key, this will return the
|
30
|
+
# class's underscored name without "validator" as a symbol.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# FooValidator.new.key #=> :foo
|
34
|
+
#
|
35
|
+
# @return [Symbol]
|
36
|
+
#
|
37
|
+
def key
|
38
|
+
name = self.class.name.split('::').last
|
39
|
+
Util.underscore(name).to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Execute the validations. This is an abstract class and must be
|
44
|
+
# overridden in custom validators.
|
45
|
+
#
|
46
|
+
# @param [Resource::Base::Base] resource
|
47
|
+
# the parent resource to validate against
|
48
|
+
#
|
49
|
+
def validate(resource)
|
50
|
+
raise Error::AbstractMethod.new(method: 'Validators::Base#validate')
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# The string representation of this validation.
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
#
|
58
|
+
def to_s
|
59
|
+
"#<#{classname}>"
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# The string representation of this validation.
|
64
|
+
#
|
65
|
+
# @return [String]
|
66
|
+
#
|
67
|
+
def inspect
|
68
|
+
"#<#{classname} :#{attribute}>"
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
#
|
74
|
+
# The class name for this validator.
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
#
|
78
|
+
def classname
|
79
|
+
@classname ||= self.class.name.split('::')[1..-1].join('::')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ChefAPI
|
2
|
+
class Validator::Type < Validator::Base
|
3
|
+
attr_reader :types
|
4
|
+
|
5
|
+
#
|
6
|
+
# Overload the super method to capture the type attribute in the options
|
7
|
+
# hash.
|
8
|
+
#
|
9
|
+
def initialize(attribute, type)
|
10
|
+
super
|
11
|
+
@types = Array(type)
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate(resource)
|
15
|
+
value = resource._attributes[attribute]
|
16
|
+
|
17
|
+
if value && !types.any? { |type| value.is_a?(type) }
|
18
|
+
short_name = type.to_s.split('::').last
|
19
|
+
resource.errors.add(attribute, "must be a kind of #{short_name}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
'<%= @method %>' is an abstract method. You must override this method in your subclass with the proper implementation and logic. For more information, please see the inline documentation for <%= @method %>. If you are not a developer, this is most likely a bug in the ChefAPI gem. Please file a bug report at:
|
2
|
+
|
3
|
+
https://github.com/sethvargo/chef-api/issues/new
|
4
|
+
|
5
|
+
and include the command(s) or code you ran to arrive at this error.
|
@@ -0,0 +1 @@
|
|
1
|
+
You attempted to regenerate the private key for a Client or User that does not yet exist on the remote Chef Server. You can only regenerate the key for an object that is persisted. Try saving this record this object before regenerating the key.
|
@@ -0,0 +1 @@
|
|
1
|
+
Oh no! Something really bad happened. I am not sure what actually happened because this is the catch-all error, but you should most definitely report an issue on GitHub at https://github.com/sethvargo/chef-api.
|
@@ -0,0 +1 @@
|
|
1
|
+
I could not find a file at '<%= @path %>'. Please make sure you have typed the path correctly and that the resource exists at the given path.
|
@@ -0,0 +1 @@
|
|
1
|
+
The Chef Server is currently unavailable or is not currently accepting client connections. Please ensure the server is accessible via ping or telnet on your local network. If this error persists, please contact your network administrator.
|
@@ -0,0 +1 @@
|
|
1
|
+
I cannot read the file at '<%= @path %>' because the permissions on the file do not permit it. Please ensure the file has the correct permissions and that this Ruby process is running as a user with access to that path.
|
@@ -0,0 +1 @@
|
|
1
|
+
There were errors saving your resource: <%= @errors %>
|
@@ -0,0 +1 @@
|
|
1
|
+
'<%= @key %>' is not a valid validator. Please make sure it is spelled correctly and that the constant is properly defined. If you are using a custom validator, please ensure the validator extends ChefAPI::Validator::Base and is a subclass of ChefAPI::Validator.
|
@@ -0,0 +1 @@
|
|
1
|
+
The required URL parameter '<%= @param %>' was not present. Please specify the parameter as an option, like Resource.new(id, <%= @param %>: 'value').
|
@@ -0,0 +1 @@
|
|
1
|
+
The given path '<%= @path %>' is not a directory. Please make sure you have passed the path to a directory on disk.
|
@@ -0,0 +1 @@
|
|
1
|
+
The <%= @type %> '<%= @id %>' already exists on the Chef Server. Each <%= @type %> must have a unique identifier and the Chef Server indicated this <%= @type %> already exists. If you are trying to update the <%= @type %>, consider using the 'update' method instead.
|
@@ -0,0 +1 @@
|
|
1
|
+
There is no <%= @type %> with an id of '<%= @id %>' on the Chef Server. If you are updating the <%= @type %>, please make sure the <%= @type %> exists and has the correct Chef identifier (primary key).
|
@@ -0,0 +1 @@
|
|
1
|
+
The <%= @type %> '<%= @id %>' is not mutable. It may be locked by the remote Chef Server, or the Chef Server may not permit modifying the resource.
|
@@ -0,0 +1 @@
|
|
1
|
+
'<%= @attribute %>' is not a valid attribute!
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-infra-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Vargo
|
8
|
+
- Tim Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-09-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: logify
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mime-types
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: A tiny Chef API client with minimal dependencies
|
43
|
+
email:
|
44
|
+
- sethvargo@gmail.com
|
45
|
+
- tsmith84@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- LICENSE
|
51
|
+
- lib/chef-api.rb
|
52
|
+
- lib/chef-api/aclable.rb
|
53
|
+
- lib/chef-api/authentication.rb
|
54
|
+
- lib/chef-api/boolean.rb
|
55
|
+
- lib/chef-api/configurable.rb
|
56
|
+
- lib/chef-api/connection.rb
|
57
|
+
- lib/chef-api/defaults.rb
|
58
|
+
- lib/chef-api/error_collection.rb
|
59
|
+
- lib/chef-api/errors.rb
|
60
|
+
- lib/chef-api/multipart.rb
|
61
|
+
- lib/chef-api/resource.rb
|
62
|
+
- lib/chef-api/resources/base.rb
|
63
|
+
- lib/chef-api/resources/client.rb
|
64
|
+
- lib/chef-api/resources/collection_proxy.rb
|
65
|
+
- lib/chef-api/resources/cookbook.rb
|
66
|
+
- lib/chef-api/resources/cookbook_version.rb
|
67
|
+
- lib/chef-api/resources/data_bag.rb
|
68
|
+
- lib/chef-api/resources/data_bag_item.rb
|
69
|
+
- lib/chef-api/resources/environment.rb
|
70
|
+
- lib/chef-api/resources/group.rb
|
71
|
+
- lib/chef-api/resources/node.rb
|
72
|
+
- lib/chef-api/resources/organization.rb
|
73
|
+
- lib/chef-api/resources/partial_search.rb
|
74
|
+
- lib/chef-api/resources/principal.rb
|
75
|
+
- lib/chef-api/resources/role.rb
|
76
|
+
- lib/chef-api/resources/search.rb
|
77
|
+
- lib/chef-api/resources/user.rb
|
78
|
+
- lib/chef-api/schema.rb
|
79
|
+
- lib/chef-api/util.rb
|
80
|
+
- lib/chef-api/validator.rb
|
81
|
+
- lib/chef-api/validators/base.rb
|
82
|
+
- lib/chef-api/validators/required.rb
|
83
|
+
- lib/chef-api/validators/type.rb
|
84
|
+
- lib/chef-api/version.rb
|
85
|
+
- templates/errors/abstract_method.erb
|
86
|
+
- templates/errors/cannot_regenerate_key.erb
|
87
|
+
- templates/errors/chef_api_error.erb
|
88
|
+
- templates/errors/file_not_found.erb
|
89
|
+
- templates/errors/http_bad_request.erb
|
90
|
+
- templates/errors/http_forbidden_request.erb
|
91
|
+
- templates/errors/http_gateway_timeout.erb
|
92
|
+
- templates/errors/http_method_not_allowed.erb
|
93
|
+
- templates/errors/http_not_acceptable.erb
|
94
|
+
- templates/errors/http_not_found.erb
|
95
|
+
- templates/errors/http_server_unavailable.erb
|
96
|
+
- templates/errors/http_unauthorized_request.erb
|
97
|
+
- templates/errors/insufficient_file_permissions.erb
|
98
|
+
- templates/errors/invalid_resource.erb
|
99
|
+
- templates/errors/invalid_validator.erb
|
100
|
+
- templates/errors/missing_url_parameter.erb
|
101
|
+
- templates/errors/not_a_directory.erb
|
102
|
+
- templates/errors/resource_already_exists.erb
|
103
|
+
- templates/errors/resource_not_found.erb
|
104
|
+
- templates/errors/resource_not_mutable.erb
|
105
|
+
- templates/errors/unknown_attribute.erb
|
106
|
+
homepage: https://github.com/chef/chef-api
|
107
|
+
licenses:
|
108
|
+
- Apache-2.0
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '2.2'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.7.9
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: A Chef API client in Ruby
|
130
|
+
test_files: []
|