Class: PlanExecutor::App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- PlanExecutor::App
- Defined in:
- lib/plan_executor/app.rb
Instance Method Summary collapse
- #create_http(config) ⇒ Object
-
#initialize(config) ⇒ App
constructor
A new instance of App.
- #validate_schema(schema, body) ⇒ Object
Constructor Details
#initialize(config) ⇒ App
Returns a new instance of App.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/plan_executor/app.rb', line 29 def initialize(config) # lazy-load expensive gem code require 'concurrent' @http_client = create_http(config) # Use an empty inventory until we figure out where this data comes from. @inventory = Bolt::Inventory.new(nil) # PAL is not threadsafe. Part of the work of making the plan executor # functional will be making changes to Puppet that remove the need for # global Puppet state. # https://github.com/puppetlabs/bolt/blob/master/lib/bolt/pal.rb#L166 @pal = Bolt::PAL.new(config['modulepath'], nil, nil) @schema = JSON.parse(File.read(File.join(__dir__, 'schemas', 'run_plan.json'))) @worker = Concurrent::SingleThreadExecutor.new @modulepath = config['modulepath'] super(nil) end |
Instance Method Details
#create_http(config) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/plan_executor/app.rb', line 51 def create_http(config) base_url = config['orchestrator-url'].chomp('/') + '/orchestrator/v1/' agent_name = "Bolt/#{Bolt::VERSION}" http = JSONClient.new(base_url: base_url, agent_name: agent_name) http.ssl_config.set_client_cert_file(config['ssl-cert'], config['ssl-key']) http.ssl_config.add_trust_ca(config['ssl-ca-cert']) http end |
#validate_schema(schema, body) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/plan_executor/app.rb', line 60 def validate_schema(schema, body) schema_error = JSON::Validator.fully_validate(schema, body) if schema_error.any? Bolt::Error.new("There was an error validating the request body.", 'boltserver/schema-error', schema_error) end end |