Sha256: 46eaed453b96642c890c913d02fbd234493ad964367449a422749047137a7bc3

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ImportCommand
      module OpenAPI
        class CreateServiceStep
          include Step

          ##
          # Creates service with a given system_name
          # If service already exists, update basic settings like name and description
          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: service_settings,
                                                      system_name: service_system_name)
              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

          def service_system_name
            target_system_name || service_name.downcase.gsub(/[^\w]/, '_')
          end

          def service_settings
            default_service_settings.tap do |svc|
              svc['name'] = service_name
              svc['description'] = service_description
              svc['backend_version'] = backend_version
            end
          end

          def default_service_settings
            {}
          end

          def service_name
            api_spec.title
          end

          def service_description
            api_spec.description
          end

          def backend_version
            api_spec.backend_version
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
3scale_toolbox-0.10.0 lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb