Sha256: cbd7b06953cbb8eac70bbb1d68e994d760b42d223bc92a5f62037bfa7d593a39

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

module Conjur::DSL2
  module Executor
    # Builds a list of execution actions for a statement. The statement
    # is an object from Conjur::DSL2::Types. Each execution action is
    # an HTTP method, a request path, and request parameters.
    class Base
      include Conjur::DSL2::Logger
      
      attr_reader :statement, :actions
      
      def initialize statement, actions
        @statement = statement
        @actions = actions
      end
      
      def action obj
        @actions.push obj
      end
      
      def execute
        raise "execute not implemented in #{self.class.name}"
      end
      
      def resource_path record = nil
        record ||= self.statement
        [ "authz", record.account, "resources", record.resource_kind, record.id ].join('/')
      end

      def role_path record = nil
        record ||= self.statement
        [ "authz", record.account, "roles", record.role_kind, record.id ].join('/')
      end
    end
    
    module Annotate
      def annotate
        Array(annotate_record.annotations).each do |k,v|
          action({
            'method' => 'put',
            'path' => update_annotation_path,
            'parameters' => { "name" => k, "value" => v }
          })
        end
      end
      
      def update_annotation_path
        [ "authz", annotate_record.account,
            "annotations",
            annotate_record.resource_kind,
            CGI.escape(annotate_record.id) ].join('/')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
conjur-asset-dsl2-0.6.1 lib/conjur/dsl2/executor/base.rb
conjur-asset-dsl2-0.6.0 lib/conjur/dsl2/executor/base.rb
conjur-asset-dsl2-0.5.0 lib/conjur/dsl2/executor/base.rb