-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from 3scale/backend-from-oas
backend from OAS
- Loading branch information
Showing
36 changed files
with
724 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ThreeScaleToolbox | ||
module CLI | ||
class NullPrinter | ||
def print_record(record) | ||
end | ||
|
||
def print_collection(collection) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/3scale_toolbox/commands/import_command/openapi/create_backend_mapping_rule_step.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module ThreeScaleToolbox | ||
module Commands | ||
module ImportCommand | ||
module OpenAPI | ||
class CreateBackendMappingRulesStep | ||
include Step | ||
|
||
def call | ||
backend.mapping_rules.each(&:delete) | ||
|
||
report['mapping_rules'] = {} | ||
operations.each do |op| | ||
b_m_r = Entities::BackendMappingRule.create(backend: backend, attrs: op.mapping_rule) | ||
report['mapping_rules'][op.friendly_name] = op.mapping_rule | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
lib/3scale_toolbox/commands/import_command/openapi/create_backend_method_step.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module ThreeScaleToolbox | ||
module Commands | ||
module ImportCommand | ||
module OpenAPI | ||
class CreateBackendMethodsStep | ||
include Step | ||
|
||
def call | ||
missing_operations.each do |op| | ||
method = Entities::BackendMethod.create(backend: backend, attrs: op.method) | ||
op.set(:metric_id, method.id) | ||
end | ||
|
||
existing_operations.each do |op| | ||
method_attrs = methods_index.fetch(op.method['system_name']).attrs | ||
method = Entities::BackendMethod.new(id: method_attrs.fetch('id'), backend: backend) | ||
method.update(op.method) | ||
op.set(:metric_id, method.id) | ||
end | ||
end | ||
|
||
private | ||
|
||
def methods_index | ||
@methods_index ||= backend.methods.each_with_object({}) do |method, acc| | ||
acc[method.system_name] = method | ||
end | ||
end | ||
|
||
def missing_operations | ||
operations.reject { |op| methods_index.key? op.method['system_name'] } | ||
end | ||
|
||
def existing_operations | ||
operations.select { |op| methods_index.key? op.method['system_name'] } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
62 changes: 62 additions & 0 deletions
62
lib/3scale_toolbox/commands/import_command/openapi/create_backend_step.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module ThreeScaleToolbox | ||
module Commands | ||
module ImportCommand | ||
module OpenAPI | ||
class CreateBackendStep | ||
include Step | ||
|
||
## | ||
# Creates backend with a given system_name | ||
# If the backend already exists, update basic settings like name and description | ||
def call | ||
# Update backend and update context | ||
self.backend = Entities::Backend.find_by_system_name(remote: threescale_client, | ||
system_name: system_name) | ||
if backend.nil? | ||
# Create service and update context | ||
self.backend = Entities::Backend.create(remote: threescale_client, | ||
attrs: create_attrs) | ||
else | ||
backend.update(update_attrs) | ||
end | ||
|
||
report['id'] = backend.id | ||
report['system_name'] = backend.system_name | ||
report['private_endpoint'] = backend.private_endpoint | ||
end | ||
|
||
private | ||
|
||
def create_attrs | ||
{ | ||
'name' => title, | ||
'system_name' => system_name, | ||
'description' => description, | ||
'private_endpoint' => private_endpoint | ||
} | ||
end | ||
|
||
def update_attrs | ||
{ | ||
'name' => title, | ||
'description' => description, | ||
'private_endpoint' => private_endpoint | ||
} | ||
end | ||
|
||
def system_name | ||
target_system_name || title.downcase.gsub(/[^\w]/, '_') | ||
end | ||
|
||
def title | ||
api_spec.title | ||
end | ||
|
||
def description | ||
api_spec.description | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.