Ravn::Tactical::ServiceInfra::

Operations module

Task queue operation endpoints for the Ravn-Tactical infrastructure service.

Public Class Methods

included( app )

Add nodes-related routes to the given app.

   # File lib/ravn/tactical/service_infra/operations.rb
20 def self::included( app )
21     super
22 
23     self.log.info "Mounting kit endpoints."
24     self.mount( app )
25 end
mount( app )

Mount mission endpoints in the given app.

   # File lib/ravn/tactical/service_infra/operations.rb
29 def self::mount( app )
30     app.hash_branch( :infra, 'operation' ) do |r|
31 
32         auth( scheme: :pkey )
33 
34         # POST /api/infra/operation/:type
35         r.on( /(\w{2,50})/ ) do |op_type|
36             r.post { self.run_operation(op_type) }
37         end
38 
39     end
40 end

Public Instance Methods

run_operation( op_type )

Run the specified operation

   # File lib/ravn/tactical/service_infra/operations.rb
48 def run_operation( op_type )
49     unless Ravn::Tactical::Operation.valid_type?( op_type )
50         self.log.error "request for unsupported operation %p" % [ op_type ]
51         response.status = :not_found
52         return { error: 'No such operation' }
53     end
54 
55     op_class = Ravn::Tactical::Operation.get_subclass( op_type ) or
56         raise "Failed to fetch operation subclass for %p" % [ op_type ]
57     validator = op_class.param_validator
58 
59     params = typecast_params.convert!( symbolize: true, &validator )
60 
61     op = op_class.new( **params )
62     result = op.run( self, request )
63     result = Array( result ) unless result.is_a?( Array ) || result.is_a?( Hash )
64 
65     return result
66 end