Sha256: 8192f015dc1fdba705a67fdea17359b1fa330494d2dd90019d306580425c108f

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Checkpoint::DB
  module Query
    # A query object based on agents, credentials, and resources.
    #
    # This query mirrors the essence of the Checkpoint semantics; that is, it
    # finds grants for any supplied agents, for any supplied credentials, for
    # any supplied resources.
    #
    # It can take single items or arrays and converts them all to their tokens
    # for query purposes.
    class ACR < CartesianSelect
      attr_reader :agents, :credentials, :resources

      def initialize(agents, credentials, resources, scope: Grant)
        super(scope: scope)
        @agents      = tokenize(agents)
        @credentials = tokenize(credentials)
        @resources   = tokenize(resources)
      end

      def conditions
        super.merge(
          agent_token:      agent_params.placeholders,
          credential_token: credential_params.placeholders,
          resource_token:   resource_params.placeholders
        )
      end

      def parameters
        super.merge(Hash[
          agent_params.values +
          credential_params.values +
          resource_params.values
        ])
      end

      protected

      def agent_params
        Params.new(agents, 'at')
      end

      def credential_params
        Params.new(credentials, 'ct')
      end

      def resource_params
        Params.new(resources, 'rt')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
checkpoint-1.1.3 lib/checkpoint/db/query/acr.rb
checkpoint-1.1.2 lib/checkpoint/db/query/acr.rb
checkpoint-1.1.1 lib/checkpoint/db/query/acr.rb
checkpoint-1.1.0 lib/checkpoint/db/query/acr.rb