Sha256: 389681f1b2cc1970f516c5ff85ef8d27f3ab27c99badc327bcd2dec922a68e48

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby
#
# ruby example/auth_test_2.rb inside omf_common dir
#
require 'bundler'
Bundler.require

require 'omf_common'

env_opts = {
  environment: 'development',
  communication: {
    local_address: 'adam',
    url: 'amqp://localhost',
    auth: {
      authenticate: true,
      pdp: {
        require: 'omf_common/auth/pdp/job_service',
        constructor: 'OmfCommon::Auth::PDP::JobService',
        slice: 'slice_a'
      }
    }
  },
  logging: {
    level: { default: 'debug' },
    appenders: {
      stdout: {
        level: :info,
        date_pattern: '%H:%M:%S',
        pattern: '%d %5l %c{2}: %m\n',
        color_scheme: 'default'
      }
    }
  }
}

def init_auth_store
  root_ca = OmfCommon::Auth::Certificate.create_root

  root_ca.create_for_resource 'god', :authoriser
  root_ca.create_for_resource 'adam', :requester
  root_ca.create_for_resource 'eve', :requester
end


OmfCommon.init(:development, env_opts) do |event_loop|
  OmfCommon.comm.on_connected do |comm|
    init_auth_store

    # Can generate a new assertion
    #
    assert_str = OmfCommon::Auth::Assertion.generate(
      'adam can use slice slice_a', iss: 'god'
    ).to_s

    # OR parse from an existing one
    #
    assert = OmfCommon::Auth::Assertion.parse(assert_str)

    comm.subscribe(:test) do |topic|
      topic.on_message do |msg|
        info "MSG >> #{msg}"
      end

      topic.configure(
        { foo: 1 },
        { issuer: 'adam',
          assert: assert }
      )

      event_loop.after(1) do
        topic.configure(
          { foo: 2 },
          { issuer: 'eve' }
        )
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
omf_common-6.2.3 example/auth_test_assertion.rb
omf_common-6.2.2 example/auth_test_assertion.rb
omf_common-6.2.1 example/auth_test_assertion.rb
omf_common-6.2.0 example/auth_test_assertion.rb
omf_common-6.2.0.pre.2 example/auth_test_assertion.rb
omf_common-6.2.0.pre.1 example/auth_test_assertion.rb
omf_common-6.1.14.pre.2 example/auth_test_assertion.rb
omf_common-6.1.14.pre.1 example/auth_test_assertion.rb