Sha256: 071839dc0b78f9ad3a3a23a906898597fad6de46be1d0f77f82f59e50a594962

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ServiceCommand
      module CopyCommand
        class CreateOrUpdateTargetServiceTask
          include Task

          def call
            service = Entities::Service.find(remote: target_remote,
                                             ref: target_service_ref)
            if service == source
              raise ThreeScaleToolbox::Error, 'Source and destination services are the same: ' \
                "ID: #{source.id} system_name: #{source.attrs['system_name']}"
            end

            if service.nil?
              service = Entities::Service.create(remote: target_remote,
                                                 service_params: create_attrs)
              # Notify that mapping rules should be deleted before being copied
              force_delete_mapping_rules
            else
              service.update update_attrs
            end

            # assign target service for other tasks to have it available
            self.target = service

            logger.info "new service id #{service.id}"
            report['product_id'] = service.id
          end

          private

          def target_service_ref
            option_target_system_name || source.attrs.fetch('system_name')
          end

          def create_attrs
            source.attrs.merge('system_name' => target_service_ref)
          end

          def update_attrs
            source.attrs.merge('system_name' => target_service_ref)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb