Sha256: bf028a84705cbd7050e9acd2486037550ed6a673640978e60b13f828a800dfa5

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Import
        class ImportMetricLimitsStep
          include Step
          ##
          # Writes Plan limits
          def call
            # SET semantics
            # First, delete existing limits
            # Second, add new limits
            plan.limits.each do |limit|
              metric_id = limit.fetch('metric_id')
              plan.delete_limit metric_id, limit.fetch('id')
              puts "Deleted existing plan limit: [metric: #{metric_id}, #{limit}]"
            end

            resource_limits_processed.each do |limit|
              metric_id = limit.delete('metric_id')
              plan.create_limit(metric_id, limit)
              puts "Created plan limit: [metric: #{metric_id}, #{limit}]"
            end
          end

          private

          def resource_limits_processed
            resource_limits.map do |limit|
              metric = find_metric_by_system_name(limit.delete('metric_system_name'))
              # this ImportMetricLimitsStep step is assuming all metrics/methods have been created
              # in previous step, so finding metric should always succeed.
              limit.merge('metric_id' => metric.fetch('id'))
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb