class Orchestrator_api
Attributes
config[RW]
token[RW]
Public Class Methods
new(settings = {})
click to toggle source
# 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
Public Instance Methods
command()
click to toggle source
# File lib/orchestrator_api.rb, line 79 def command @command ||= Orchestrator_api::Command.new(self, url) end
create_http(uri)
click to toggle source
# 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
environments()
click to toggle source
# File lib/orchestrator_api.rb, line 83 def environments @environments ||= Orchestrator_api::Environments.new(self, url) end
get(location)
click to toggle source
# 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
jobs()
click to toggle source
# File lib/orchestrator_api.rb, line 87 def jobs @jobs ||= Orchestrator_api::Jobs.new(self, url) end
post(location, body)
click to toggle source
# 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()
click to toggle source
# File lib/orchestrator_api.rb, line 91 def root get(url) end
url()
click to toggle source
# File lib/orchestrator_api.rb, line 33 def url config['service-url'] end