diff --git a/buddhi/lib/amp/toolkit/3scale/helper.rb b/buddhi/lib/amp/toolkit/3scale/helper.rb index 377f830..defe249 100644 --- a/buddhi/lib/amp/toolkit/3scale/helper.rb +++ b/buddhi/lib/amp/toolkit/3scale/helper.rb @@ -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. diff --git a/buddhi/lib/amp/toolkit/buddhi/profiles/backend.rb b/buddhi/lib/amp/toolkit/buddhi/profiles/backend.rb index d1b73a2..60ab40f 100644 --- a/buddhi/lib/amp/toolkit/buddhi/profiles/backend.rb +++ b/buddhi/lib/amp/toolkit/buddhi/profiles/backend.rb @@ -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') diff --git a/buddhi/lib/amp/toolkit/buddhi/profiles/simple.rb b/buddhi/lib/amp/toolkit/buddhi/profiles/simple.rb index b3ef31c..f21d137 100644 --- a/buddhi/lib/amp/toolkit/buddhi/profiles/simple.rb +++ b/buddhi/lib/amp/toolkit/buddhi/profiles/simple.rb @@ -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')