safety_razor 0.1.0
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/.cane +0 -0
- data/.gitignore +19 -0
- data/.tailor +4 -0
- data/.travis.yml +11 -0
- data/Berksfile +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +328 -0
- data/Rakefile +39 -0
- data/Vagrantfile +27 -0
- data/lib/safety_razor.rb +7 -0
- data/lib/safety_razor/client.rb +58 -0
- data/lib/safety_razor/slice/active_model.rb +30 -0
- data/lib/safety_razor/slice/base.rb +89 -0
- data/lib/safety_razor/slice/broker.rb +27 -0
- data/lib/safety_razor/slice/model.rb +27 -0
- data/lib/safety_razor/slice/node.rb +58 -0
- data/lib/safety_razor/slice/policy.rb +27 -0
- data/lib/safety_razor/slice/tag.rb +22 -0
- data/lib/safety_razor/slice/tag_matcher.rb +65 -0
- data/lib/safety_razor/version.rb +6 -0
- data/safety_razor.gemspec +36 -0
- data/script/bootstrap +33 -0
- data/spec/acceptance/active_model_spec.rb +115 -0
- data/spec/acceptance/broker_spec.rb +52 -0
- data/spec/acceptance/model_spec.rb +69 -0
- data/spec/acceptance/node_spec.rb +59 -0
- data/spec/acceptance/policy_spec.rb +82 -0
- data/spec/acceptance/tag_matcher_spec.rb +38 -0
- data/spec/acceptance/tag_spec.rb +43 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/safety_razor/client_spec.rb +84 -0
- metadata +281 -0
data/.cane
ADDED
File without changes
|
data/.gitignore
ADDED
data/.tailor
ADDED
data/.travis.yml
ADDED
data/Berksfile
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Blue Box All Rights Reserved
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,328 @@
|
|
1
|
+
# <a name="title"></a> Safety Razor - A Ruby client for the Razor API
|
2
|
+
|
3
|
+
There are 2 overriding design decisions at play in this library:
|
4
|
+
|
5
|
+
1. Implement a solution using the
|
6
|
+
[Faraday gem](https://github.com/lostisland/faraday) to support
|
7
|
+
middleware injection such as additional authentication, rety logic, etc.
|
8
|
+
2. Provide a thin wrapper around Razor's REST API that doesn't hide data
|
9
|
+
internals. At the time of authoring this library Razor has not yet hit a
|
10
|
+
SemVer-stable release and could therefore change internals at any time.
|
11
|
+
|
12
|
+
## <a name="installation"></a> Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'safety_razor'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install safety_razor
|
25
|
+
|
26
|
+
## <a name="usage"></a> Usage
|
27
|
+
|
28
|
+
### <a name="usage-active-model"></a> Active Model
|
29
|
+
|
30
|
+
* Razor
|
31
|
+
[active_model](https://github.com/puppetlabs/Razor/wiki/active_model)
|
32
|
+
documentation
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'safety_razor'
|
36
|
+
|
37
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
38
|
+
|
39
|
+
# GET /active_model/{UUID}
|
40
|
+
client.active_model.get("uuid1-xxxx")
|
41
|
+
|
42
|
+
# GET /active_model
|
43
|
+
client.active_model.all
|
44
|
+
|
45
|
+
# DELETE /active_model/{UUID}
|
46
|
+
client.active_model.destroy("uuid1-xxxx")
|
47
|
+
```
|
48
|
+
|
49
|
+
### <a name="usage-broker"></a> Broker
|
50
|
+
|
51
|
+
* Razor
|
52
|
+
[broker](https://github.com/puppetlabs/Razor/wiki/broker)
|
53
|
+
documentation
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require 'safety_razor'
|
57
|
+
|
58
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
59
|
+
|
60
|
+
# POST /broker?json_hash=(JSON_STR)
|
61
|
+
client.broker.create({
|
62
|
+
name: "Chefy",
|
63
|
+
plugin: "chef",
|
64
|
+
description: "Production Chef Server",
|
65
|
+
req_metadata_hash: {
|
66
|
+
chef_server_url: "https://chef.example.com",
|
67
|
+
chef_version: "11.4.0",
|
68
|
+
validation_key: "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAK..."
|
69
|
+
}
|
70
|
+
})
|
71
|
+
|
72
|
+
# GET /broker/{UUID}
|
73
|
+
client.broker.get("uuid1-xxxx")
|
74
|
+
|
75
|
+
# GET /broker
|
76
|
+
client.broker.all
|
77
|
+
|
78
|
+
# GET /broker/plugins
|
79
|
+
client.broker.plugins
|
80
|
+
|
81
|
+
# PUT /broker/{UUID}?json_hash=(JSON_STR)
|
82
|
+
client.broker.update({
|
83
|
+
uuid: "uuid1-xxxx",
|
84
|
+
name: "Production Chef Server"
|
85
|
+
})
|
86
|
+
|
87
|
+
# DELETE /broker/{UUID}
|
88
|
+
client.broker.destroy("uuid1-xxxx")
|
89
|
+
|
90
|
+
broker = client.broker.get("uuid1-xxxx")
|
91
|
+
client.broker.destroy(broker)
|
92
|
+
```
|
93
|
+
|
94
|
+
### <a name="usage-model"></a> Model
|
95
|
+
|
96
|
+
* Razor
|
97
|
+
[model](https://github.com/puppetlabs/Razor/wiki/model)
|
98
|
+
documentation
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
require 'safety_razor'
|
102
|
+
|
103
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
104
|
+
|
105
|
+
# POST /model?json_hash=(JSON_STR)
|
106
|
+
client.model.create({
|
107
|
+
label: "Test Model",
|
108
|
+
image_uuid: "OTP",
|
109
|
+
template: "ubuntu_oneirc",
|
110
|
+
req_metadata_hash: {
|
111
|
+
hostname_prefix: "test",
|
112
|
+
domainname: "testdomain.com",
|
113
|
+
root_password: "test4321"
|
114
|
+
}
|
115
|
+
})
|
116
|
+
|
117
|
+
# GET /model/{UUID}
|
118
|
+
client.model.get("uuid1-xxxx")
|
119
|
+
|
120
|
+
# GET /model
|
121
|
+
client.model.all
|
122
|
+
|
123
|
+
# GET /model/templates
|
124
|
+
client.model.templates
|
125
|
+
|
126
|
+
# PUT /model/{UUID}?json_hash=(JSON_STR)
|
127
|
+
client.model.update({
|
128
|
+
uuid: "uuid1-xxxx",
|
129
|
+
label: "New Test Model Label"
|
130
|
+
})
|
131
|
+
|
132
|
+
# DELETE /model/{UUID}
|
133
|
+
client.model.destroy("uuid1-xxxx")
|
134
|
+
```
|
135
|
+
|
136
|
+
### <a name="usage-node"></a> Node
|
137
|
+
|
138
|
+
* Razor
|
139
|
+
[node](https://github.com/puppetlabs/Razor/wiki/node)
|
140
|
+
documentation
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
require 'safety_razor'
|
144
|
+
|
145
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
146
|
+
|
147
|
+
# POST /node/register?[registration_param_list]
|
148
|
+
client.node.register({
|
149
|
+
hw_id: "000C29291C95",
|
150
|
+
last_state: "idle",
|
151
|
+
attributes_hash: {
|
152
|
+
attr1: "val1"
|
153
|
+
}
|
154
|
+
})
|
155
|
+
|
156
|
+
# POST /node/checkin?[checkin_param_list]
|
157
|
+
client.node.checkin({
|
158
|
+
hw_id: "000C29291C95",
|
159
|
+
last_state: "idle"
|
160
|
+
})
|
161
|
+
|
162
|
+
# GET /node/{UUID}
|
163
|
+
client.node.get("uuid1-xxxx")
|
164
|
+
|
165
|
+
# GET /node/{UUID}?field=attributes
|
166
|
+
client.node.get_attributes("uuid1-xxxx")
|
167
|
+
|
168
|
+
# GET /node/{UUID}?field=hardware_ids
|
169
|
+
client.node.get_hardware_ids("uuid1-xxxx")
|
170
|
+
|
171
|
+
# GET /node
|
172
|
+
client.node.all
|
173
|
+
```
|
174
|
+
|
175
|
+
### <a name="usage-policy"></a> Policy
|
176
|
+
|
177
|
+
* Razor
|
178
|
+
[policy](https://github.com/puppetlabs/Razor/wiki/policy)
|
179
|
+
documentation
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
require 'safety_razor'
|
183
|
+
|
184
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
185
|
+
|
186
|
+
# POST /policy?json_hash=(JSON_STR)
|
187
|
+
client.policy.create({
|
188
|
+
label: "Test Policy",
|
189
|
+
model_uuid: "uuid2-yyyy",
|
190
|
+
template: "linux_deploy",
|
191
|
+
tags: "two_disks,memsize_1GiB,nics_2"
|
192
|
+
})
|
193
|
+
|
194
|
+
# GET /policy/{UUID}
|
195
|
+
client.policy.get("uuid1-xxxx")
|
196
|
+
|
197
|
+
# GET /policy
|
198
|
+
client.policy.all
|
199
|
+
|
200
|
+
# GET /policy/templates
|
201
|
+
client.policy.templates
|
202
|
+
|
203
|
+
# PUT /policy/{UUID}?json_hash=(JSON_STR)
|
204
|
+
client.policy.update({
|
205
|
+
uuid: "uuid1-xxxx",
|
206
|
+
tags: "one,two,three"
|
207
|
+
})
|
208
|
+
|
209
|
+
# DELETE /policy/{UUID}
|
210
|
+
client.policy.destroy("uuid1-xxxx")
|
211
|
+
|
212
|
+
policy = client.policy.get("uuid1-xxxx")
|
213
|
+
client.policy.destroy(policy)
|
214
|
+
```
|
215
|
+
|
216
|
+
### <a name="usage-tag"></a> Tag
|
217
|
+
|
218
|
+
* Razor
|
219
|
+
[tag](https://github.com/puppetlabs/Razor/wiki/tag)
|
220
|
+
documentation
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
require 'safety_razor'
|
224
|
+
|
225
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
226
|
+
|
227
|
+
# POST /tag?json_hash=(JSON_STR)
|
228
|
+
client.tag.create({
|
229
|
+
name: "Test Tag",
|
230
|
+
tag: "test_tag"
|
231
|
+
})
|
232
|
+
|
233
|
+
# GET /tag/{UUID}
|
234
|
+
client.tag.get("uuid1-xxxx")
|
235
|
+
|
236
|
+
# GET /tag
|
237
|
+
client.tag.all
|
238
|
+
|
239
|
+
# PUT /tag/{UUID}?json_hash=(JSON_STR)
|
240
|
+
client.tag.update({
|
241
|
+
uuid: "uuid1-xxxx",
|
242
|
+
tag: "prod_tag"
|
243
|
+
})
|
244
|
+
|
245
|
+
# DELETE /tag/{UUID}
|
246
|
+
client.tag.destroy("uuid1-xxxx")
|
247
|
+
|
248
|
+
tag = client.tag.get("uuid1-xxxx")
|
249
|
+
client.tag.destroy(tag)
|
250
|
+
```
|
251
|
+
|
252
|
+
### <a name="usage-tag-matcher"></a> Tag Matcher
|
253
|
+
|
254
|
+
* Razor
|
255
|
+
[tag](https://github.com/puppetlabs/Razor/wiki/tag)
|
256
|
+
documentation (contains tag matcher details)
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
require 'safety_razor'
|
260
|
+
|
261
|
+
client = SafetyRazor::Client.new(uri: 'http://10.0.10.1')
|
262
|
+
|
263
|
+
# POST /tag/{T_UUID}/matcher?json_hash=(JSON_STR)
|
264
|
+
client.tag_matcher.create("uuid1-xxxx", {
|
265
|
+
key: "mk_hw_nic_count",
|
266
|
+
compare: "equal",
|
267
|
+
value: "2"
|
268
|
+
})
|
269
|
+
|
270
|
+
# GET /tag/{T_UUID}/matcher/{UUID}
|
271
|
+
# get(tag_uuid, tag_matcher_uuid)
|
272
|
+
client.tag_matcher.get("uuid1-xxxx", "uuid2-yyyy")
|
273
|
+
|
274
|
+
# PUT /tag/{T_UUID}/matcher/{UUID}?json_hash=(JSON_STR)
|
275
|
+
client.tag_matcher.update("uuid1-xxxx", {
|
276
|
+
uuid: "uuid2-yyyy",
|
277
|
+
key: "mk_special_sauce"
|
278
|
+
})
|
279
|
+
|
280
|
+
# DELETE /tag/{T_UUID}/matcher/{UUID}
|
281
|
+
client.tag_matcher.destroy("uuid1-xxxx", "uuid2-yyyy")
|
282
|
+
```
|
283
|
+
|
284
|
+
## <a name="testing"></a> Testing
|
285
|
+
|
286
|
+
To run the unit tests and quality suite:
|
287
|
+
|
288
|
+
./script/bootstrap
|
289
|
+
rake
|
290
|
+
|
291
|
+
The acceptance suite requires a Razor service, therefore this projects ships
|
292
|
+
with a Vagrant VM providing a Razor instance. To run the acceptance suite:
|
293
|
+
|
294
|
+
./script/bootstrap
|
295
|
+
vagrant up
|
296
|
+
rake acceptance
|
297
|
+
vagrant destroy
|
298
|
+
|
299
|
+
## <a name="development"></a> Development
|
300
|
+
|
301
|
+
* Source hosted at [GitHub][repo]
|
302
|
+
* Report issues/questions/feature requests on [GitHub Issues][issues]
|
303
|
+
|
304
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
305
|
+
Ideally create a topic branch for every separate change you make. For
|
306
|
+
example:
|
307
|
+
|
308
|
+
1. Fork the repo
|
309
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
310
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
311
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
312
|
+
5. Create new Pull Request
|
313
|
+
|
314
|
+
## <a name="authors"></a> Authors
|
315
|
+
|
316
|
+
Created by [Fletcher Nichol][fnichol] (<fnichol@nichol.ca>), and maintained
|
317
|
+
by [Blue Box Group][bluebox].
|
318
|
+
|
319
|
+
## <a name="license"></a> License
|
320
|
+
|
321
|
+
MIT (see [LICENSE][license])
|
322
|
+
|
323
|
+
[bluebox]: http://bluebox.net
|
324
|
+
[fnichol]: https://github.com/fnichol
|
325
|
+
[license]: https://github.com/blueboxgroup/safety_razor/blob/master/LICENSE
|
326
|
+
[repo]: https://github.com/blueboxgroup/safety_razor
|
327
|
+
[issues]: https://github.com/blueboxgroup/safety_razor/issues
|
328
|
+
[contributors]: https://github.com/blueboxgroup/safety_razor/contributors
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require 'cane/rake_task'
|
4
|
+
require 'tailor/rake_task'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:unit) do |t|
|
7
|
+
t.libs.push "lib"
|
8
|
+
t.test_files = FileList['spec/unit/**/*_spec.rb']
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::TestTask.new(:acceptance) do |t|
|
13
|
+
t.libs.push "lib"
|
14
|
+
t.test_files = FileList['spec/acceptance/**/*_spec.rb']
|
15
|
+
t.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run cane to check quality metrics"
|
19
|
+
Cane::RakeTask.new do |cane|
|
20
|
+
cane.canefile = './.cane'
|
21
|
+
end
|
22
|
+
|
23
|
+
Tailor::RakeTask.new
|
24
|
+
|
25
|
+
desc "Display LOC stats"
|
26
|
+
task :stats do
|
27
|
+
puts "\n## Production Code Stats"
|
28
|
+
sh "countloc -r lib"
|
29
|
+
puts "\n## Test Code Stats"
|
30
|
+
sh "countloc -r spec"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Run all test suites"
|
34
|
+
task :test => [:unit, :acceptance]
|
35
|
+
|
36
|
+
desc "Run all quality tasks"
|
37
|
+
task :quality => [:cane, :tailor, :stats]
|
38
|
+
|
39
|
+
task :default => [:unit, :quality]
|