Skip to content

Commit

Permalink
profiles: fix simple when apiap not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Apr 15, 2020
1 parent 48a1299 commit f4ee4a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 11 additions & 0 deletions buddhi/lib/amp/toolkit/3scale/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ def self.create_backend_method(client, backend)
method_obj
end

def self.update_private_endpoint(client, service, endpoint)
proxy = { api_backend: endpoint }
new_proxy_attrs = client.update_proxy service.fetch('id'), proxy

if (errors = new_proxy_attrs['errors'])
raise "Service proxy not updated: #{errors}"
end

new_proxy_attrs
end

# wait tries a block of code until it returns true, or the timeout is reached.
# timeout give an upper limit to the amount of time this method will run
# Some intervals may be missed if the block takes too long or the time window is too short.
Expand Down
13 changes: 9 additions & 4 deletions buddhi/lib/amp/toolkit/buddhi/profiles/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ def call(client, endpoint:, **_options)
ThreeScale::Helper.create_application(client, plan, account)
ThreeScale::Helper.create_application_plan_limit(client, service, plan)
ThreeScale::Helper.delete_mapping_rules(client, service)
backend = ThreeScale::Helper.create_backend(client, endpoint)
backend_method = ThreeScale::Helper.create_backend_method(client, backend)
ThreeScale::Helper.create_backend_mapping_rule(client, backend, backend_method, '/pets')
ThreeScale::Helper.create_backend_usage(client, service, backend, '/')
begin
backend = ThreeScale::Helper.create_backend(client, endpoint)
backend_method = ThreeScale::Helper.create_backend_method(client, backend)
ThreeScale::Helper.create_backend_mapping_rule(client, backend, backend_method, '/pets')
ThreeScale::Helper.create_backend_usage(client, service, backend, '/')
rescue ::ThreeScale::API::HttpClient::ForbiddenError
raise 'Provider account does not support backend profile. ' \
'Upgrade account to API as Product model or choose another profile.'
end
ThreeScale::Helper.bump_proxy_conf(client, service)
ThreeScale::Helper.promote_proxy_conf(client, service)
return service.fetch('id')
Expand Down
9 changes: 7 additions & 2 deletions buddhi/lib/amp/toolkit/buddhi/profiles/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ def call(client, endpoint:, **_options)
ThreeScale::Helper.create_mapping_rule(client, service, '/pets')
account = ThreeScale::Helper.account(client)
ThreeScale::Helper.create_application(client, plan, account)
backend = ThreeScale::Helper.create_backend(client, endpoint)
ThreeScale::Helper.create_backend_usage(client, service, backend, '/')
begin
backend = ThreeScale::Helper.create_backend(client, endpoint)
ThreeScale::Helper.create_backend_usage(client, service, backend, '/')
rescue ::ThreeScale::API::HttpClient::ForbiddenError
# 3scale Backends not supported
ThreeScale::Helper.update_private_endpoint(client, service, endpoint)
end
ThreeScale::Helper.bump_proxy_conf(client, service)
ThreeScale::Helper.promote_proxy_conf(client, service)
return service.fetch('id')
Expand Down

0 comments on commit f4ee4a1

Please sign in to comment.