Sha256: 02fd98f5b73bf5a94ad20727f39cd115947e0f4102107544d4def4873eb35a76

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module ThreeScaleToolbox
  module Tasks
    class CopyLimitsTask
      include CopyTask
      include Helper

      def call
        metrics_map = metrics_mapping(source.metrics, target.metrics)
        plan_mapping = application_plan_mapping(source.plans, target.plans)
        plan_mapping.each do |plan_id, target_plan|
          limits = source.plan_limits(plan_id)
          limits_target = target.plan_limits(target_plan['id'])
          missing_limits = missing_limits(limits, limits_target)
          missing_limits.each do |limit|
            limit.delete('links')
            target.create_application_plan_limit(
              target_plan['id'],
              metrics_map.fetch(limit.fetch('metric_id')),
              limit
            )
          end
          puts "Missing #{missing_limits.size} plan limits from target application plan " \
            "#{target_plan['id']}. Source plan #{plan_id}"
        end
      end

      private

      def missing_limits(source_limits, target_limits)
        ThreeScaleToolbox::Helper.array_difference(source_limits, target_limits) do |limit, target|
          ThreeScaleToolbox::Helper.compare_hashes(limit, target, ['period'])
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
3scale_toolbox-0.8.0 lib/3scale_toolbox/tasks/copy_limits_task.rb
3scale_toolbox-0.7.0 lib/3scale_toolbox/tasks/copy_limits_task.rb