Sha256: 13f9b9723fe47e97f540efa2a116540b0ded353d9ccc1e0e8fc614fb96d6fbfb

Contents?: true

Size: 1.34 KB

Versions: 10

Compression:

Stored size: 1.34 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Import
        class ImportMetricLimitsStep
          include Step
          ##
          # Writes Plan limits
          def call
            missing_limits.each do |limit|
              metric_id = limit.delete('metric_id')
              limit_obj = plan.create_limit(metric_id, limit)
              if (errors = limit_obj['errors'])
                raise ThreeScaleToolbox::Error, "Plan limit has not been created. #{errors}"
              end

              puts "Created plan limit: [metric: #{metric_id}, #{limit}]"
            end
          end

          private

          def missing_limits
            ThreeScaleToolbox::Helper.array_difference(resource_limits_processed, plan.limits) do |a, b|
              ThreeScaleToolbox::Helper.compare_hashes(a, b, %w[metric_id period])
            end
          end

          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

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb
3scale_toolbox-0.9.0 lib/3scale_toolbox/commands/plans_command/import/import_plan_limits_step.rb