Class: OmfCommon::Auth::PDP::JobService

Inherits:
Object
  • Object
show all
Defined in:
omf_common/lib/omf_common/auth/pdp/job_service.rb

Overview

Authorise job service (experiment controller) messages

Instance Method Summary (collapse)

Constructor Details

- (JobService) initialize(opts = {})

Returns a new instance of JobService



7
8
9
# File 'omf_common/lib/omf_common/auth/pdp/job_service.rb', line 7

def initialize(opts = {})
  @slice = opts[:slice]
end

Instance Method Details

- (Object) authorize(msg, &block)



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'omf_common/lib/omf_common/auth/pdp/job_service.rb', line 11

def authorize(msg, &block)
  if msg.assert.nil?
    warn 'No assertion found, drop it'
    return nil
  end

  assert = OmfCommon::Auth::Assertion.new(msg.assert)

  unless assert.verify
    return nil
  else
    info "#{msg.src.address} tells >> #{assert.iss} says >> #{assert.content}"
  end

  # Check current slice with slice specified in assertion
  if assert.content =~ /(.+) can use slice (.+)/ &&
    $1 == msg.src.id.to_s &&
    $2 == @slice.to_s

    block.call(msg) if block
    return msg
  else
    warn 'Drop it'
    return nil
  end
end