onering-client 0.0.44 → 0.0.45
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/onering/api.rb +66 -61
- metadata +17 -17
data/lib/onering/api.rb
CHANGED
@@ -78,74 +78,79 @@ module Onering
|
|
78
78
|
# client PEM not present, attempt autoregistration
|
79
79
|
STDERR.puts("Onering client.pem not found, attempting automatic registration...")
|
80
80
|
|
81
|
-
|
82
|
-
(
|
83
|
-
|
84
|
-
|
85
|
-
if @_validation.nil?
|
86
|
-
raise Errors::ClientError.new("Cannot automatically register client, cannot find validation.pem")
|
87
|
-
end
|
88
|
-
|
89
|
-
@_validation = File.read(@_validation)
|
90
|
-
|
91
|
-
@rest = RestClient::Resource.new("#{@_uri.scheme}://#{@_uri.host}:#{@_uri.port || 443}", {
|
92
|
-
:timeout => 120,
|
93
|
-
:open_timeout => 30,
|
94
|
-
:ssl_client_cert => OpenSSL::X509::Certificate.new(@_validation),
|
95
|
-
:ssl_client_key => OpenSSL::PKey::RSA.new(@_validation),
|
96
|
-
:verify_peer => OpenSSL::SSL::VERIFY_PEER
|
97
|
-
})
|
98
|
-
|
81
|
+
begin
|
82
|
+
@_validation = ([options[:validationfile], @_config['validationfile']]+DEFAULT_VALIDATION_PEM).compact.select{|i|
|
83
|
+
(File.exists?((File.expand_path(i) rescue i)) rescue nil)
|
84
|
+
}.compact.first
|
99
85
|
|
100
|
-
|
101
|
-
|
102
|
-
:name => (@_config['id'] || File.read("/etc/hardware.id")).strip.chomp,
|
103
|
-
:keyname => 'system',
|
104
|
-
:autodelete => true
|
105
|
-
},{
|
106
|
-
:path => "~/.onering",
|
107
|
-
:name => ENV['USER'],
|
108
|
-
:keyname => 'cli',
|
109
|
-
:autodelete => false
|
110
|
-
}]
|
111
|
-
|
112
|
-
# attempt to autoregister clients from least specific to most (machine account then user account)
|
113
|
-
clients.each do |client|
|
114
|
-
# determine if we can create this client
|
115
|
-
client[:path] = (File.expand_path(client[:path]) rescue client[:path])
|
116
|
-
next unless File.writable?(File.dirname(client[:path]))
|
117
|
-
Dir.mkdir(client[:path]) unless File.directory?(client[:path])
|
118
|
-
next unless File.writable?(client[:path])
|
119
|
-
|
120
|
-
begin
|
121
|
-
response = @rest["/api/users/#{client[:name]}/keys/#{client[:keyname]}"].get({
|
122
|
-
:params => {
|
123
|
-
:cert => 'pem',
|
124
|
-
:autodelete => client[:autodelete]
|
125
|
-
}
|
126
|
-
})
|
127
|
-
|
128
|
-
rescue RestClient::Forbidden
|
129
|
-
STDERR.puts("Cannot re-download key '#{client[:keyname]}' for client #{client[:name]}. Please remove the client key from Onering and try again.")
|
130
|
-
next
|
131
|
-
|
132
|
-
rescue RestClient::Exception => e
|
133
|
-
raise Errors::ClientError.new("HTTP #{e.http_code}: #{e.message}")
|
86
|
+
if @_validation.nil?
|
87
|
+
raise Errors::ClientError.new("Cannot automatically register client, cannot find validation.pem")
|
134
88
|
end
|
135
89
|
|
90
|
+
@_validation = File.read(@_validation)
|
91
|
+
|
92
|
+
@rest = RestClient::Resource.new("#{@_uri.scheme}://#{@_uri.host}:#{@_uri.port || 443}", {
|
93
|
+
:timeout => 120,
|
94
|
+
:open_timeout => 30,
|
95
|
+
:ssl_client_cert => OpenSSL::X509::Certificate.new(@_validation),
|
96
|
+
:ssl_client_key => OpenSSL::PKey::RSA.new(@_validation),
|
97
|
+
:verify_peer => OpenSSL::SSL::VERIFY_PEER
|
98
|
+
})
|
99
|
+
|
100
|
+
|
101
|
+
clients = [{
|
102
|
+
:path => "/etc/onering",
|
103
|
+
:name => (@_config['id'] || File.read("/etc/hardware.id")).strip.chomp,
|
104
|
+
:keyname => 'system',
|
105
|
+
:autodelete => true
|
106
|
+
},{
|
107
|
+
:path => "~/.onering",
|
108
|
+
:name => ENV['USER'],
|
109
|
+
:keyname => 'cli',
|
110
|
+
:autodelete => false
|
111
|
+
}]
|
112
|
+
|
113
|
+
# attempt to autoregister clients from least specific to most (machine account then user account)
|
114
|
+
clients.each do |client|
|
115
|
+
# determine if we can create this client
|
116
|
+
client[:path] = (File.expand_path(client[:path]) rescue client[:path])
|
117
|
+
next unless File.writable?(File.dirname(client[:path]))
|
118
|
+
Dir.mkdir(client[:path]) unless File.directory?(client[:path])
|
119
|
+
next unless File.writable?(client[:path])
|
120
|
+
|
121
|
+
begin
|
122
|
+
response = @rest["/api/users/#{client[:name]}/keys/#{client[:keyname]}"].get({
|
123
|
+
:params => {
|
124
|
+
:cert => 'pem',
|
125
|
+
:autodelete => client[:autodelete]
|
126
|
+
}
|
127
|
+
})
|
128
|
+
|
129
|
+
rescue RestClient::Forbidden
|
130
|
+
STDERR.puts("Cannot re-download key '#{client[:keyname]}' for client #{client[:name]}. Please remove the client key from Onering and try again.")
|
131
|
+
next
|
132
|
+
|
133
|
+
rescue RestClient::Exception => e
|
134
|
+
raise Errors::ClientError.new("HTTP #{e.http_code}: #{e.message}")
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
File.open("#{client[:path]}/client.pem", "w") do |file|
|
139
|
+
file.puts(response.to_str)
|
140
|
+
STDERR.puts("Successfully registered client key #{client[:name]}:#{client[:keyname]}, key is at #{file.path}")
|
141
|
+
break
|
142
|
+
end
|
143
|
+
end
|
136
144
|
|
137
|
-
|
138
|
-
|
139
|
-
STDERR.puts("Successfully registered client key #{client[:name]}:#{client[:keyname]}, key is at #{file.path}")
|
140
|
-
break
|
145
|
+
if clients.select{|i| p = "#{i[:path]}/client.pem"; File.exists?((File.expand_path(p) rescue p)) }.empty?
|
146
|
+
raise Errors::ClientError.new("Unable to register a Onering client.")
|
141
147
|
end
|
142
|
-
end
|
143
148
|
|
144
|
-
|
145
|
-
raise Errors::ClientError.new("Unable to register a Onering client.")
|
146
|
-
end
|
149
|
+
retry
|
147
150
|
|
148
|
-
|
151
|
+
rescue Exception => e
|
152
|
+
STDERR.puts("Error occurred during autoregistration: #{e.class.name} - #{e.message}")
|
153
|
+
end
|
149
154
|
end
|
150
155
|
|
151
156
|
else
|
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.0.
|
4
|
+
version: 0.0.45
|
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: &15193700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15193700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: subcommander
|
27
|
-
requirement: &
|
27
|
+
requirement: &15214900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15214900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: deep_merge
|
38
|
-
requirement: &
|
38
|
+
requirement: &15214300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *15214300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: addressable
|
49
|
-
requirement: &
|
49
|
+
requirement: &15213720 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *15213720
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rest-client
|
60
|
-
requirement: &
|
60
|
+
requirement: &15213320 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *15213320
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hashlib
|
71
|
-
requirement: &
|
71
|
+
requirement: &15212460 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *15212460
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: multi_json
|
82
|
-
requirement: &
|
82
|
+
requirement: &15211120 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *15211120
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rainbow
|
93
|
-
requirement: &
|
93
|
+
requirement: &15210100 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *15210100
|
102
102
|
description: A Ruby wrapper for Onering
|
103
103
|
email: ghetzel@outbrain.com
|
104
104
|
executables:
|