Class: Orchestrator_api
- Inherits:
-
Object
show all
- Defined in:
- lib/orchestrator_api.rb
Defined Under Namespace
Classes: Command, Environments, Error, Jobs
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Orchestrator_api.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/orchestrator_api.rb', line 14
def initialize(settings = {})
@config = { 'token_path' => File.join(Dir.home, '.puppetlabs', 'token'),
}.merge(settings)
if @config['token']
@token = @config['token']
else
@token = File.read(@config['token_path'])
end
if @config['service-url'].nil?
raise "Configuration error: 'service-url' must specify the server running the Orchestration services and cannot be empty"
end
if @config['ca_cert'].nil?
raise "Configuration error: 'ca_cert' must specify a path to the CA certificate used for communications with the server and cannot be empty"
end
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
12
13
14
|
# File 'lib/orchestrator_api.rb', line 12
def config
@config
end
|
#token ⇒ Object
Returns the value of attribute token.
12
13
14
|
# File 'lib/orchestrator_api.rb', line 12
def token
@token
end
|
Instance Method Details
#create_http(uri) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/orchestrator_api.rb', line 37
def create_http(uri)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.ssl_version = :TLSv1
http.ca_file = config['ca_cert']
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http
end
|
#get(location) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/orchestrator_api.rb', line 46
def get(location)
uri = URI.parse(location)
https = create_http(uri)
req = Net::HTTP::Get.new(uri.request_uri)
req['Content-Type'] = "application/json"
req.add_field('X-Authentication', token)
res = https.request(req)
if res.code != "200"
raise Orchestrator_api::Error.make_error_from_response(res)
end
JSON.parse(res.body)
end
|
#post(location, body) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/orchestrator_api.rb', line 62
def post(location, body)
uri = URI.parse(location)
https = create_http(uri)
req = Net::HTTP::Post.new(uri.request_uri)
req['Content-Type'] = "application/json"
req.add_field('X-Authentication', token)
req.body = body.to_json
res = https.request(req)
if res.code != "202"
raise Orchestrator_api::Error.make_error_from_response(res)
end
JSON.parse(res.body)
end
|
#root ⇒ Object
91
92
93
|
# File 'lib/orchestrator_api.rb', line 91
def root
get(url)
end
|
#url ⇒ Object
33
34
35
|
# File 'lib/orchestrator_api.rb', line 33
def url
config['service-url']
end
|