Sha256: 5024076582069efa9025c65f9fea642755a695275e61e874899587b72981695d

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

module ThreeScaleToolbox
  module Tasks
    class UpdateServiceSettingsTask
      attr_reader :source, :target, :target_system_name

      def initialize(source:, target:, target_name:)
        @source = source
        @target = target
        @target_system_name = target_name
      end

      def call
        source_obj = source.show_service
        svc_obj = update_service target_service_params(source_obj)
        if (errors = svc_obj['errors'])
          raise ThreeScaleToolbox::Error, "Service has not been saved. Errors: #{errors}" \
        end

        puts "updated service settings for service id #{source.id}..."
      end

      private

      def update_service(service)
        svc_obj = target.update_service service

        # Source and target remotes might not allow same set of deployment options
        # Invalid deployment option check
        # use default deployment_option
        if (errors = svc_obj['errors']) &&
           ThreeScaleToolbox::Helper.service_invalid_deployment_option?(errors)
          service.delete('deployment_option')
          svc_obj = target.update_service(service)
        end

        svc_obj
      end

      # system name only included when specified from options
      def target_service_params(source)
        target_svc_obj = ThreeScaleToolbox::Helper.filter_params(Entities::Service::VALID_PARAMS, source)
        target_svc_obj.delete('system_name')
        target_svc_obj.tap do |hash|
          hash['system_name'] = target_system_name unless target_system_name.nil?
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
3scale_toolbox-0.9.0 lib/3scale_toolbox/tasks/update_service_settings_task.rb
3scale_toolbox-0.8.0 lib/3scale_toolbox/tasks/update_service_settings_task.rb