class ThreeScaleToolbox::Commands::ImportCommand::OpenAPI::CreateActiveDocsStep
Public Instance Methods
call()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 8 def call active_doc = { name: api_spec.title, system_name: activedocs_system_name, service_id: service.id, body: JSON.pretty_generate(rewritten_openapi), description: api_spec.description, published: context[:activedocs_published], skip_swagger_validations: context[:skip_openapi_validation] } res = threescale_client.create_activedocs(active_doc) # Make operation indempotent if (errors = res['errors']) raise ThreeScaleToolbox::Error, "ActiveDocs has not been created. #{errors}" \ unless ThreeScaleToolbox::Helper.system_name_already_taken_error? errors # if activedocs system_name exists, ignore error, update activedocs puts 'Activedocs exists, update!' update_res = threescale_client.update_activedocs(find_activedocs_id, active_doc) raise ThreeScaleToolbox::Error, "ActiveDocs has not been updated. #{update_res['errors']}" unless update_res['errors'].nil? end end
Private Instance Methods
activedocs_system_name()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 34 def activedocs_system_name @activedocs_system_name ||= service.attrs['system_name'] end
cleaned_issuer_endpoint()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 68 def cleaned_issuer_endpoint return if oidc_issuer_endpoint.nil? issuer_uri = ThreeScaleToolbox::Helper.parse_uri(oidc_issuer_endpoint) issuer_uri.userinfo = '' issuer_uri.to_s end
find_activedocs_id()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 38 def find_activedocs_id activedocs = get_current_service_activedocs raise ThreeScaleToolbox::Error, "Could not find activedocs with system_name: #{activedocs_system_name}" if activedocs.empty? activedocs.dig(0, 'id') end
get_current_service_activedocs()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 45 def get_current_service_activedocs threescale_client.list_activedocs.select do |activedoc| activedoc['system_name'] == activedocs_system_name end end
rewritten_openapi()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 51 def rewritten_openapi # Updates on copy # Other processing steps can work with original openapi spec Helper.hash_deep_dup(resource).tap do |activedocs| # public production base URL # the basePath field is updated to a new value only when overriden by optional param unless service.proxy['endpoint'].nil? api_spec.set_server_url(activedocs, URI.join(service.proxy.fetch('endpoint'), public_base_path)) end # security definitions # just valid for oauth2 when oidc_issuer_endpoint is supplied if !api_spec.security.nil? && api_spec.security[:type] == 'oauth2' && !oidc_issuer_endpoint.nil? api_spec.set_oauth2_urls(activedocs, api_spec.security[:id], authorization_url, token_url) end end end
token_url()
click to toggle source
# File lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb, line 80 def token_url "#{cleaned_issuer_endpoint}/protocol/openid-connect/token" end