ridley 0.7.0.beta → 0.7.0.rc1
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.
- data/README.md +51 -54
- data/lib/ridley.rb +7 -13
- data/lib/ridley/client.rb +251 -0
- data/lib/ridley/connection.rb +32 -188
- data/lib/ridley/middleware/chef_auth.rb +4 -1
- data/lib/ridley/resource.rb +36 -42
- data/lib/ridley/resources.rb +3 -0
- data/lib/ridley/resources/{client.rb → client_resource.rb} +7 -20
- data/lib/ridley/resources/cookbook_resource.rb +121 -0
- data/lib/ridley/resources/{data_bag_item.rb → data_bag_item_resource.rb} +52 -63
- data/lib/ridley/resources/data_bag_resource.rb +74 -0
- data/lib/ridley/resources/encrypted_data_bag_item_resource.rb +55 -0
- data/lib/ridley/resources/{environment.rb → environment_resource.rb} +8 -21
- data/lib/ridley/resources/{node.rb → node_resource.rb} +24 -37
- data/lib/ridley/resources/{role.rb → role_resource.rb} +1 -14
- data/lib/ridley/resources/sandbox_resource.rb +86 -0
- data/lib/ridley/resources/search.rb +24 -55
- data/lib/ridley/sandbox_uploader.rb +118 -0
- data/lib/ridley/ssh.rb +2 -2
- data/lib/ridley/ssh/worker.rb +2 -1
- data/lib/ridley/version.rb +1 -1
- data/ridley.gemspec +1 -1
- data/spec/acceptance/bootstrapping_spec.rb +1 -1
- data/spec/acceptance/client_resource_spec.rb +18 -20
- data/spec/acceptance/cookbook_resource_spec.rb +4 -22
- data/spec/acceptance/data_bag_item_resource_spec.rb +5 -7
- data/spec/acceptance/data_bag_resource_spec.rb +4 -6
- data/spec/acceptance/environment_resource_spec.rb +14 -16
- data/spec/acceptance/node_resource_spec.rb +12 -14
- data/spec/acceptance/role_resource_spec.rb +13 -15
- data/spec/acceptance/sandbox_resource_spec.rb +7 -9
- data/spec/acceptance/search_resource_spec.rb +6 -8
- data/spec/support/shared_examples/ridley_resource.rb +23 -22
- data/spec/unit/ridley/client_spec.rb +153 -0
- data/spec/unit/ridley/connection_spec.rb +8 -221
- data/spec/unit/ridley/resources/{client_spec.rb → client_resource_spec.rb} +4 -4
- data/spec/unit/ridley/resources/cookbook_resource_spec.rb +5 -0
- data/spec/unit/ridley/resources/{data_bag_item_spec.rb → data_bag_item_resource_spec.rb} +2 -2
- data/spec/unit/ridley/resources/{data_bag_spec.rb → data_bag_resource_spec.rb} +3 -3
- data/spec/unit/ridley/resources/{environment_spec.rb → environment_resource_spec.rb} +4 -4
- data/spec/unit/ridley/resources/{node_spec.rb → node_resource_spec.rb} +4 -4
- data/spec/unit/ridley/resources/{role_spec.rb → role_resource_spec.rb} +3 -3
- data/spec/unit/ridley/resources/sandbox_resource_spec.rb +172 -0
- data/spec/unit/ridley/resources/search_spec.rb +34 -30
- data/spec/unit/ridley/sandbox_uploader_spec.rb +99 -0
- data/spec/unit/ridley/ssh_spec.rb +2 -2
- data/spec/unit/ridley_spec.rb +4 -12
- metadata +36 -28
- data/lib/ridley/dsl.rb +0 -58
- data/lib/ridley/resources/cookbook.rb +0 -51
- data/lib/ridley/resources/data_bag.rb +0 -81
- data/lib/ridley/resources/encrypted_data_bag_item.rb +0 -54
- data/lib/ridley/resources/sandbox.rb +0 -154
- data/spec/unit/ridley/resources/cookbook_spec.rb +0 -5
@@ -1,51 +0,0 @@
|
|
1
|
-
module Ridley
|
2
|
-
# @author Jamie Winsor <jamie@vialstudios.com>
|
3
|
-
class Cookbook < Ridley::Resource
|
4
|
-
class << self
|
5
|
-
# Save a new Cookbook Version of the given name, version with the
|
6
|
-
# given manifest of files and checksums.
|
7
|
-
#
|
8
|
-
# @param [Ridley::Connection] connection
|
9
|
-
# @param [String] name
|
10
|
-
# @param [String] version
|
11
|
-
# @param [String] manifest
|
12
|
-
# a JSON blob containing file names, file paths, and checksums for each
|
13
|
-
# that describe the cookbook version being uploaded.
|
14
|
-
#
|
15
|
-
# @option options [Boolean] :freeze
|
16
|
-
# @option options [Boolean] :force
|
17
|
-
#
|
18
|
-
# @return [Hash]
|
19
|
-
def save(connection, name, version, manifest, options = {})
|
20
|
-
freeze = options.fetch(:freeze, false)
|
21
|
-
force = options.fetch(:force, false)
|
22
|
-
|
23
|
-
url = "cookbooks/#{name}/#{version}"
|
24
|
-
url << "?force=true" if force
|
25
|
-
|
26
|
-
connection.put(url, manifest)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
set_chef_id "name"
|
31
|
-
set_chef_type "cookbook"
|
32
|
-
set_chef_json_class "Chef::Cookbook"
|
33
|
-
set_resource_path "cookbooks"
|
34
|
-
|
35
|
-
attribute :name,
|
36
|
-
required: true
|
37
|
-
end
|
38
|
-
|
39
|
-
module DSL
|
40
|
-
# Coerces instance functions into class functions on Ridley::Cookbook. This coercion
|
41
|
-
# sends an instance of the including class along to the class function.
|
42
|
-
#
|
43
|
-
# @see Ridley::ChainLink
|
44
|
-
#
|
45
|
-
# @return [Ridley::ChainLink]
|
46
|
-
# a context object to delegate instance functions to class functions on Ridley::Cookbook
|
47
|
-
def cookbook
|
48
|
-
ChainLink.new(self, Ridley::Cookbook)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Ridley
|
2
|
-
# @author Jamie Winsor <jamie@vialstudios.com>
|
3
|
-
# @api private
|
4
|
-
class DBIChainLink
|
5
|
-
attr_reader :data_bag
|
6
|
-
attr_reader :connection
|
7
|
-
attr_reader :klass
|
8
|
-
|
9
|
-
# @param [Ridley::DataBag] data_bag
|
10
|
-
def initialize(data_bag, connection, options = {})
|
11
|
-
options[:encrypted] ||= false
|
12
|
-
|
13
|
-
@data_bag = data_bag
|
14
|
-
@connection = connection
|
15
|
-
@klass = options[:encrypted] ? Ridley::EncryptedDataBagItem : Ridley::DataBagItem
|
16
|
-
end
|
17
|
-
|
18
|
-
def new(*args)
|
19
|
-
klass.send(:new, connection, data_bag, *args)
|
20
|
-
end
|
21
|
-
|
22
|
-
def method_missing(fun, *args, &block)
|
23
|
-
klass.send(fun, connection, data_bag, *args, &block)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# @author Jamie Winsor <jamie@vialstudios.com>
|
28
|
-
class DataBag < Ridley::Resource
|
29
|
-
class << self
|
30
|
-
# @param [Ridley::Connection] connection
|
31
|
-
# @param [String, #chef_id] object
|
32
|
-
#
|
33
|
-
# @return [nil, Ridley::DataBag]
|
34
|
-
def find(connection, object)
|
35
|
-
find!(connection, object)
|
36
|
-
rescue Errors::HTTPNotFound
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
|
40
|
-
# @param [Ridley::Connection] connection
|
41
|
-
# @param [String, #chef_id] object
|
42
|
-
#
|
43
|
-
# @raise [Errors::HTTPNotFound]
|
44
|
-
# if a resource with the given chef_id is not found
|
45
|
-
#
|
46
|
-
# @return [Ridley::DataBag]
|
47
|
-
def find!(connection, object)
|
48
|
-
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
|
49
|
-
connection.get("#{self.resource_path}/#{chef_id}")
|
50
|
-
new(connection, name: chef_id)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
set_chef_id "name"
|
55
|
-
set_resource_path "data"
|
56
|
-
|
57
|
-
attribute :name,
|
58
|
-
required: true
|
59
|
-
|
60
|
-
def item
|
61
|
-
DBIChainLink.new(self, connection)
|
62
|
-
end
|
63
|
-
|
64
|
-
def encrypted_item
|
65
|
-
DBIChainLink.new(self, connection, encrypted: true)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
module DSL
|
70
|
-
# Coerces instance functions into class functions on Ridley::DataBag. This coercion
|
71
|
-
# sends an instance of the including class along to the class function.
|
72
|
-
#
|
73
|
-
# @see Ridley::ChainLink
|
74
|
-
#
|
75
|
-
# @return [Ridley::ChainLink]
|
76
|
-
# a context object to delegate instance functions to class functions on Ridley::DataBag
|
77
|
-
def data_bag
|
78
|
-
ChainLink.new(self, Ridley::DataBag)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Ridley
|
2
|
-
class EncryptedDataBagItem
|
3
|
-
class << self
|
4
|
-
# Finds a data bag item and decrypts it.
|
5
|
-
#
|
6
|
-
# @param [Ridley::Connection] connection
|
7
|
-
# @param [Ridley::DataBag] data_bag
|
8
|
-
# @param [String, #chef_id] object
|
9
|
-
#
|
10
|
-
# @return [nil, Ridley::DataBagItem]
|
11
|
-
def find(connection, data_bag, object)
|
12
|
-
find!(connection, data_bag, object)
|
13
|
-
rescue Errors::HTTPNotFound
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
|
17
|
-
# Finds a data bag item and decrypts it. Throws an exception if the item doesn't exist.
|
18
|
-
#
|
19
|
-
# @param [Ridley::Connection] connection
|
20
|
-
# @param [Ridley::DataBag] data_bag
|
21
|
-
# @param [String, #chef_id] object
|
22
|
-
#
|
23
|
-
# @raise [Errors::HTTPNotFound]
|
24
|
-
# if a resource with the given chef_id is not found
|
25
|
-
#
|
26
|
-
# @return [nil, Ridley::DataBagItem]
|
27
|
-
def find!(connection, data_bag, object)
|
28
|
-
data_bag_item = DataBagItem.find!(connection, data_bag, object)
|
29
|
-
data_bag_item.decrypt
|
30
|
-
new(connection, data_bag, data_bag_item.attributes)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
attr_reader :data_bag
|
35
|
-
attr_reader :attributes
|
36
|
-
|
37
|
-
# @param [Ridley::Connection] connection
|
38
|
-
# @param [Ridley::DataBag] data_bag
|
39
|
-
# @param [#to_hash] attributes
|
40
|
-
def initialize(connection, data_bag, attributes = {})
|
41
|
-
@connection = connection
|
42
|
-
@data_bag = data_bag
|
43
|
-
@attributes = attributes
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_s
|
47
|
-
self.attributes
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
attr_reader :connection
|
53
|
-
end
|
54
|
-
end
|
@@ -1,154 +0,0 @@
|
|
1
|
-
module Ridley
|
2
|
-
class Sandbox
|
3
|
-
class << self
|
4
|
-
# @param [Ridley::Connection] connection
|
5
|
-
# @param [Array] checksums
|
6
|
-
# @option options [Integer] :size (12)
|
7
|
-
# size of the upload pool
|
8
|
-
#
|
9
|
-
# @return [Ridley::Sandbox]
|
10
|
-
def create(connection, checksums = [], options = {})
|
11
|
-
options.reverse_merge!(size: 12)
|
12
|
-
|
13
|
-
sumhash = { checksums: Hash.new }.tap do |chks|
|
14
|
-
Array(checksums).each { |chk| chks[:checksums][chk] = nil }
|
15
|
-
end
|
16
|
-
|
17
|
-
attrs = connection.post("sandboxes", sumhash.to_json).body
|
18
|
-
pool(size: options[:size], args: [connection, attrs[:sandbox_id], attrs[:checksums]])
|
19
|
-
end
|
20
|
-
|
21
|
-
# Checksum the file at the given filepath for a Chef API.
|
22
|
-
#
|
23
|
-
# @param [String] path
|
24
|
-
#
|
25
|
-
# @return [String]
|
26
|
-
def checksum(path)
|
27
|
-
File.open(path, 'rb') { |f| checksum_io(f, Digest::MD5.new) }
|
28
|
-
end
|
29
|
-
|
30
|
-
# Checksum and encode the file at the given filepath for uploading
|
31
|
-
#
|
32
|
-
# @param [String] path
|
33
|
-
#
|
34
|
-
# @return [String]
|
35
|
-
# a base64 encoded checksum
|
36
|
-
def checksum64(path)
|
37
|
-
Base64.encode64([checksum(path)].pack("H*")).strip
|
38
|
-
end
|
39
|
-
|
40
|
-
# @param [String] io
|
41
|
-
# @param [Object] digest
|
42
|
-
#
|
43
|
-
# @return [String]
|
44
|
-
def checksum_io(io, digest)
|
45
|
-
while chunk = io.read(1024 * 8)
|
46
|
-
digest.update(chunk)
|
47
|
-
end
|
48
|
-
digest.hexdigest
|
49
|
-
end
|
50
|
-
|
51
|
-
def future(connection, *args)
|
52
|
-
puts connection
|
53
|
-
connection.future(*args)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
include Celluloid
|
58
|
-
|
59
|
-
attr_reader :sandbox_id
|
60
|
-
attr_reader :checksums
|
61
|
-
|
62
|
-
def initialize(connection, id, checksums)
|
63
|
-
@connection = connection
|
64
|
-
@sandbox_id = id
|
65
|
-
@checksums = checksums
|
66
|
-
end
|
67
|
-
|
68
|
-
def checksum(chk_id)
|
69
|
-
checksums.fetch(chk_id.to_sym)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Concurrently upload multiple files into a sandbox
|
73
|
-
#
|
74
|
-
# @param [Hash] checksums
|
75
|
-
# a hash of file checksums and file paths
|
76
|
-
#
|
77
|
-
# @example uploading multiple checksums
|
78
|
-
#
|
79
|
-
# sandbox.multi_upload(
|
80
|
-
# "e5a0f6b48d0712382295ff30bec1f9cc" => "/Users/reset/code/rbenv-cookbook/recipes/default.rb",
|
81
|
-
# "de6532a7fbe717d52020dc9f3ae47dbe" => "/Users/reset/code/rbenv-cookbook/recipes/ohai_plugin.rb"
|
82
|
-
# )
|
83
|
-
def multi_upload(checksums)
|
84
|
-
checksums.collect do |chk_id, path|
|
85
|
-
future.upload(chk_id, path)
|
86
|
-
end.map(&:value)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Upload one file into the sandbox for the given checksum id
|
90
|
-
#
|
91
|
-
# @param [String] chk_id
|
92
|
-
# checksum of the file being uploaded
|
93
|
-
# @param [String] path
|
94
|
-
# path to the file to upload
|
95
|
-
#
|
96
|
-
# @return [Hash, nil]
|
97
|
-
def upload(chk_id, path)
|
98
|
-
checksum = self.checksum(chk_id)
|
99
|
-
|
100
|
-
unless checksum[:needs_upload]
|
101
|
-
return nil
|
102
|
-
end
|
103
|
-
|
104
|
-
headers = {
|
105
|
-
'Content-Type' => 'application/x-binary',
|
106
|
-
'content-md5' => self.class.checksum64(path)
|
107
|
-
}
|
108
|
-
contents = File.open(path, 'rb') { |f| f.read }
|
109
|
-
|
110
|
-
# Hosted Chef returns Amazon S3 URLs for where to upload
|
111
|
-
# checksums to. OSS Chef Server and Hosted Chef return URLs
|
112
|
-
# to the same Chef API that the Sandbox creation request was
|
113
|
-
# sent to.
|
114
|
-
#
|
115
|
-
# The connection object is duplicated to ensure all of our connection
|
116
|
-
# settings persist, but the scheme, host, and port are set to the
|
117
|
-
# value of the given checksum.
|
118
|
-
conn = connection.send(:conn).dup
|
119
|
-
|
120
|
-
url = URI(checksum[:url])
|
121
|
-
upload_path = url.path
|
122
|
-
url.path = ""
|
123
|
-
|
124
|
-
conn.url_prefix = url.to_s
|
125
|
-
|
126
|
-
conn.put(upload_path, contents, headers)
|
127
|
-
end
|
128
|
-
|
129
|
-
def commit
|
130
|
-
connection.put("sandboxes/#{sandbox_id}", MultiJson.encode(is_completed: true)).body
|
131
|
-
end
|
132
|
-
|
133
|
-
def to_s
|
134
|
-
"#{sandbox_id}: #{checksums}"
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
attr_reader :connection
|
140
|
-
end
|
141
|
-
|
142
|
-
module DSL
|
143
|
-
# Coerces instance functions into class functions on Ridley::Sandbox. This coercion
|
144
|
-
# sends an instance of the including class along to the class function.
|
145
|
-
#
|
146
|
-
# @see Ridley::ChainLink
|
147
|
-
#
|
148
|
-
# @return [Ridley::ChainLink]
|
149
|
-
# a context object to delegate instance functions to class functions on Ridley::Sandbox
|
150
|
-
def sandbox
|
151
|
-
ChainLink.new(self, Ridley::Sandbox)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|