class ThreeScaleToolbox::Commands::BackendCommand::CopyCommand::CreateOrUpdateTargetBackendTask

Public Instance Methods

create_attrs() click to toggle source
# File lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb, line 31
def create_attrs
  source_backend.attrs.merge('system_name' => target_backend_ref)
end
run() click to toggle source

entrypoint

# File lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb, line 9
def run
  backend = Entities::Backend.find(remote: target_remote, ref: target_backend_ref)

  if backend.nil?
    backend = Entities::Backend.create(remote: target_remote,
                                       attrs: create_attrs)
  elsif backend == source_backend
    message = 'source and destination backends are the same: ' \
      "ID: #{source_backend.id} system_name: #{source_backend.attrs['system_name']}"
    warn "\e[1m\e[31mWarning: #{message}\e[0m"
  else
    backend.update update_attrs
  end

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

  logger.info "source backend ID: #{source_backend.id} system_name: #{source_backend.system_name}"
  logger.info "target backend ID: #{target_backend.id} system_name: #{target_backend.system_name}"
  report['backend_id'] = target_backend.id
end
target_backend_ref() click to toggle source
# File lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb, line 39
def target_backend_ref
  option_target_system_name || source_backend.attrs.fetch('system_name')
end
update_attrs() click to toggle source
# File lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb, line 35
def update_attrs
  source_backend.attrs.merge('system_name' => target_backend_ref)
end