Ravn::Tactical::ServiceInfra::
Operations
module
Task queue operation endpoints for the Ravn-Tactical infrastructure service.
Add nodes-related routes to the given app
.
20 def self::included( app )
21 super
22
23 self.log.info "Mounting kit endpoints."
24 self.mount( app )
25 end
Mount mission endpoints in the given app
.
29 def self::mount( app )
30 app.hash_branch( :infra, 'operation' ) do |r|
31
32 auth( scheme: :pkey )
33
34
35 r.on( /(\w{2,50})/ ) do |op_type|
36 r.post { self.run_operation(op_type) }
37 end
38
39 end
40 end
Run the specified operation
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