onering-client 0.0.99 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/onering.rb +1 -1
- data/lib/onering/api.rb +36 -57
- data/lib/onering/config.rb +2 -2
- metadata +27 -27
data/lib/onering.rb
CHANGED
data/lib/onering/api.rb
CHANGED
@@ -212,14 +212,7 @@ module Onering
|
|
212
212
|
# -----------------------------------------------------------------------------
|
213
213
|
def _setup_auth()
|
214
214
|
type = Onering::Config.get('authentication.type', :auto)
|
215
|
-
|
216
|
-
case type.to_sym
|
217
|
-
when :token
|
218
|
-
_setup_auth_token()
|
219
|
-
|
220
|
-
else
|
221
|
-
_setup_auth_ssl()
|
222
|
-
end
|
215
|
+
_setup_auth_token()
|
223
216
|
end
|
224
217
|
|
225
218
|
# -----------------------------------------------------------------------------
|
@@ -230,33 +223,19 @@ module Onering
|
|
230
223
|
end
|
231
224
|
|
232
225
|
# -----------------------------------------------------------------------------
|
233
|
-
def
|
234
|
-
|
235
|
-
Onering::Logger.info("Using SSL authentication mechanism", "Onering::API")
|
236
|
-
|
237
|
-
# get first keyfile found
|
238
|
-
key = (([Onering::Config.get('authentication.keyfile')] + DEFAULT_CLIENT_PEM).compact.select{|i|
|
239
|
-
rv = (File.readable?(File.expand_path(i)) rescue false)
|
240
|
-
Onering::Logger.debug("SSL keyfile found at #{File.expand_path(i)}", "Onering::API") if rv === true
|
241
|
-
rv
|
242
|
-
}).first
|
243
|
-
|
244
|
-
# SSL client key not found, attempt autoregistration...
|
245
|
-
if key.nil?
|
246
|
-
if Onering::Config.get('authentication.autoregister', true)
|
247
|
-
Onering::Logger.warn("SSL keyfile not found, attempting to autoregister client", "Onering::API")
|
248
|
-
|
249
|
-
validation_key = Onering::Config.get('authentication.validation_keyfile', DEFAULT_VALIDATION_PEM)
|
250
|
-
validation_key = (File.expand_path(validation_key) rescue validation_key)
|
226
|
+
def _setup_auth_token()
|
227
|
+
Onering::Logger.info("Using token authentication mechanism", "Onering::API")
|
251
228
|
|
252
|
-
|
253
|
-
|
254
|
-
Onering::Logger.debug("Using validation key at #{validation_key}", "Onering::API")
|
229
|
+
# get first keyfile found
|
230
|
+
key = Onering::Config.get('authentication.key', Onering::Config.get('authentication.keyfile'))
|
255
231
|
|
256
|
-
|
257
|
-
|
232
|
+
if key.nil?
|
233
|
+
if Onering::Config.get('authentication.bootstrap.enabled', true)
|
234
|
+
Onering::Logger.warn("Authentication token not found, attempting to autoregister client", "Onering::API")
|
258
235
|
|
259
|
-
|
236
|
+
if not (bootstrap = Onering::Config.get('authentication.bootstrap.key')).nil?
|
237
|
+
if bootstrap.to_s =~ /[0-9a-f]{32,64}/
|
238
|
+
# attempt to create key.yml from least-specific to most, first writable path wins
|
260
239
|
clients = [{
|
261
240
|
:path => "/etc/onering",
|
262
241
|
:name => fact('hardwareid'),
|
@@ -273,54 +252,54 @@ module Onering
|
|
273
252
|
clients.each do |client|
|
274
253
|
# expand and assemble path
|
275
254
|
client[:path] = (File.expand_path(client[:path]) rescue client[:path])
|
276
|
-
keyfile = File.join(client[:path], '
|
255
|
+
keyfile = File.join(client[:path], 'key.yml')
|
277
256
|
|
278
257
|
# skip this if we can't write to the parent directory
|
279
258
|
next unless File.writable?(client[:path])
|
280
259
|
Dir.mkdir(client[:path]) unless File.directory?(client[:path])
|
281
260
|
next if File.exists?(keyfile)
|
282
261
|
|
262
|
+
self.class.headers({
|
263
|
+
'X-Auth-Bootstrap-Token' => bootstrap
|
264
|
+
})
|
265
|
+
|
283
266
|
# attempt to create/download the keyfile
|
284
|
-
Onering::Logger.debug("Requesting
|
285
|
-
response = self.class.get("/api/users/#{client[:name].strip}/
|
267
|
+
Onering::Logger.debug("Requesting authentication token for #{client[:name].strip}; #{bootstrap}", "Onering::API")
|
268
|
+
response = self.class.get("/api/users/#{client[:name].strip}/tokens/#{client[:keyname]}")
|
286
269
|
|
287
270
|
# if successful, write the file
|
288
271
|
if response.code < 400 and response.body
|
289
|
-
File.open(keyfile, 'w').puts(
|
290
|
-
|
272
|
+
File.open(keyfile, 'w').puts(YAML.dump({
|
273
|
+
'authentication' => {
|
274
|
+
'key' => response.body.strip.chomp
|
275
|
+
}
|
276
|
+
}))
|
277
|
+
|
278
|
+
key = response.body.strip.chomp
|
279
|
+
|
291
280
|
else
|
292
281
|
# all errors are fatal at this stage
|
293
282
|
Onering::Logger.fatal!("Cannot autoregister client: HTTP #{response.code} - #{(response.parsed_response || {}).get('error.message', 'Unknown error')}", "Onering::API")
|
294
283
|
end
|
295
|
-
end
|
296
284
|
|
297
|
-
|
298
|
-
raise Errors::AuthenticationMissing.new("Cannot autoregister client: keyfile not created")
|
285
|
+
self.class.headers({})
|
299
286
|
|
287
|
+
# we're done here...
|
288
|
+
break
|
289
|
+
end
|
300
290
|
else
|
301
|
-
|
302
|
-
raise Errors::AuthenticationMissing.new("Cannot autoregister client: validation keyfile is missing")
|
291
|
+
raise Errors::AuthenticationMissing.new("Autoregistration failed: invalid bootstrap token specified")
|
303
292
|
end
|
293
|
+
|
304
294
|
else
|
305
|
-
raise Errors::AuthenticationMissing.new("
|
295
|
+
raise Errors::AuthenticationMissing.new("Autoregistration failed: no bootstrap token specified")
|
306
296
|
end
|
297
|
+
|
307
298
|
else
|
308
|
-
|
309
|
-
Onering::Logger.debug("Using SSL keyfile #{File.expand_path(key) rescue key}", "Onering::API")
|
299
|
+
raise Errors::AuthenticationMissing.new("Authentication token not found, and autoregistration disabled")
|
310
300
|
end
|
311
|
-
|
312
|
-
rescue Actions::Retry
|
313
|
-
retry
|
314
301
|
end
|
315
|
-
end
|
316
|
-
|
317
302
|
|
318
|
-
# -----------------------------------------------------------------------------
|
319
|
-
def _setup_auth_token()
|
320
|
-
Onering::Logger.info("Using token authentication mechanism", "Onering::API")
|
321
|
-
|
322
|
-
# get first keyfile found
|
323
|
-
key = Onering::Config.get('authentication.key', Onering::Config.get('authentication.keyfile'))
|
324
303
|
raise Errors::AuthenticationMissing.new("Token authentication specified, but cannot find a token config or as a command line argument") if key.nil?
|
325
304
|
|
326
305
|
# set auth mechanism
|
@@ -332,4 +311,4 @@ module Onering
|
|
332
311
|
_default_param(:token, key)
|
333
312
|
end
|
334
313
|
end
|
335
|
-
end
|
314
|
+
end
|
data/lib/onering/config.rb
CHANGED
@@ -5,7 +5,7 @@ module Onering
|
|
5
5
|
class Config
|
6
6
|
class<<self
|
7
7
|
DEFAULT_CONFIG={}
|
8
|
-
DEFAULT_OPTIONS_FILE=["~/.onering/cli.yml", "/etc/onering/cli.yml"]
|
8
|
+
DEFAULT_OPTIONS_FILE=["~/.onering/cli.yml", "~/.onering/key.yml", "/etc/onering/cli.yml", "/etc/onering/key.yml"]
|
9
9
|
|
10
10
|
def load(configfile=nil, config={})
|
11
11
|
if configfile.nil?
|
@@ -56,4 +56,4 @@ module Onering
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onering-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-01-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: facter
|
16
|
-
requirement: &
|
16
|
+
requirement: &24589080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.7.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *24589080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: deep_merge
|
27
|
-
requirement: &
|
27
|
+
requirement: &24588580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *24588580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: addressable
|
38
|
-
requirement: &
|
38
|
+
requirement: &24588080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.3.5
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *24588080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: httparty
|
49
|
-
requirement: &
|
49
|
+
requirement: &24587560 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.11.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *24587560
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: hashlib
|
60
|
-
requirement: &
|
60
|
+
requirement: &24587060 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.0.35
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *24587060
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: multi_json
|
71
|
-
requirement: &
|
71
|
+
requirement: &24586560 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - =
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.7.9
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *24586560
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rainbow
|
82
|
-
requirement: &
|
82
|
+
requirement: &24586080 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - <=
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.1.4
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *24586080
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: trollop
|
93
|
-
requirement: &
|
93
|
+
requirement: &24606560 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - =
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '2.0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *24606560
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: xml-simple
|
104
|
-
requirement: &
|
104
|
+
requirement: &24606100 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - =
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 1.1.2
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *24606100
|
113
113
|
description: A Ruby wrapper for Onering
|
114
114
|
email: ghetzel@outbrain.com
|
115
115
|
executables:
|
@@ -117,22 +117,22 @@ executables:
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
-
- lib/onering.rb
|
120
|
+
- lib/onering/config.rb
|
121
121
|
- lib/onering/logger.rb
|
122
122
|
- lib/onering/cli.rb
|
123
|
-
- lib/onering/config.rb
|
124
|
-
- lib/onering/api.rb
|
125
|
-
- lib/onering/util.rb
|
126
|
-
- lib/onering/plugins/authentication.rb
|
127
|
-
- lib/onering/plugins/reporter.rb
|
128
123
|
- lib/onering/plugins/devices.rb
|
124
|
+
- lib/onering/plugins/reporter.rb
|
125
|
+
- lib/onering/plugins/authentication.rb
|
129
126
|
- lib/onering/plugins/automation.rb
|
130
|
-
- lib/onering/cli/reporter.rb
|
131
127
|
- lib/onering/cli/devices.rb
|
128
|
+
- lib/onering/cli/reporter.rb
|
132
129
|
- lib/onering/cli/config.rb
|
133
|
-
- lib/onering/cli/automation.rb
|
134
130
|
- lib/onering/cli/fact.rb
|
131
|
+
- lib/onering/cli/automation.rb
|
135
132
|
- lib/onering/cli/call.rb
|
133
|
+
- lib/onering/api.rb
|
134
|
+
- lib/onering/util.rb
|
135
|
+
- lib/onering.rb
|
136
136
|
- bin/onering
|
137
137
|
homepage: https://github.com/outbrain/onering-ruby
|
138
138
|
licenses: []
|