Sha256: 58dbb90d0f9f720651ea02411b729011e17e33c57fa1e51a7e058ee2deace814

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

require 'conjur/dsl2/plan'
require 'conjur/dsl2/planner/record'
require 'conjur/dsl2/planner/permissions'
require 'conjur/dsl2/planner/grants'

module Conjur
  module DSL2
    module Planner
      class << self
        def plan records, api, options = {}
          namespace = options[:namespace]
          ownerid   = options[:ownerid]
          plan = options[:plan] || Plan.new
          plan.tap do |plan|
            plan.namespace = namespace if namespace
            plan.ownerid = ownerid if ownerid
            Array(records).map{ |record| planner_for(record, api) }.sort.each do |planner|
              planner.plan = plan
              planner.log { %Q(Planning "#{planner.record} using #{planner.class}") }
              begin
                planner.do_plan
                planner.log { "\tFinished \"#{planner.record}\"" }
              ensure
                planner.plan = nil
              end
            end        
          end
        end
        
        def planner_for record, api
          cls = begin
            const_get record.class.name.split("::")[-1]
          rescue NameError
            Record
          end
          cls.new record, api
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conjur-asset-dsl2-0.4.4 lib/conjur/dsl2/planner.rb
conjur-asset-dsl2-0.4.3 lib/conjur/dsl2/planner.rb