Sha256: cc45c4ad4d206bd7bed866105c520691169265b87fddeda15c45cba81e466138

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 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

            puts "new service 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

3 entries across 3 versions & 1 rubygems

Version Path
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/service_command/copy_command/create_or_update_service_task.rb