class ThreeScaleToolbox::Commands::ImportCommand::OpenAPI::CreateServiceStep

Public Instance Methods

call() click to toggle source

Creates service with a given system_name If service already exists, update basic settings like name and description

# File lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb, line 11
def call
  # Update service and update context
  self.service = Entities::Service.find_by_system_name(remote: threescale_client,
                                                       system_name: service_system_name)
  if service.nil?
    # Create service and update context
    self.service = Entities::Service.create(remote: threescale_client,
                                            service_params: service_settings)
    puts "Created service id: #{service.id}, name: #{service_name}"
  else
    service.update(service_settings)
    puts "Updated service id: #{service.id}, name: #{service_name}"
  end
end

Private Instance Methods

default_service_settings() click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb, line 42
def default_service_settings
  {}
end
service_description() click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb, line 50
def service_description
  api_spec.description
end
service_name() click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb, line 46
def service_name
  api_spec.title
end
service_settings() click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb, line 32
def service_settings
  default_service_settings.tap do |svc|
    svc['name'] = service_name
    svc['description'] = service_description
    svc['backend_version'] = api_spec.service_backend_version
    svc['system_name'] = service_system_name
    svc['deployment_option'] = 'self_managed' if !production_public_base_url.nil? || !staging_public_base_url.nil?
  end
end
service_system_name() click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb, line 28
def service_system_name
  target_system_name || service_name.downcase.gsub(/[^\w]/, '_')
end