From 37ca11dd5ee84f2c0339a1aa237eed28a437bfaf Mon Sep 17 00:00:00 2001 From: ukhanskyi Date: Wed, 10 Jul 2024 01:05:13 +0300 Subject: [PATCH] Add regions to aqua --- tasks/connectors/aqua/lib/aqua_helper.rb | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tasks/connectors/aqua/lib/aqua_helper.rb b/tasks/connectors/aqua/lib/aqua_helper.rb index 4d8c4986..349dbd5b 100644 --- a/tasks/connectors/aqua/lib/aqua_helper.rb +++ b/tasks/connectors/aqua/lib/aqua_helper.rb @@ -5,10 +5,26 @@ module Kenna module Toolkit module AquaHelper - SAAS_AUTH_URL = "https://api.cloudsploit.com/v2/signin" - WP_URL_API = "https://prov.cloud.aquasec.com/v1/envs" + def select_region_urls(aqua_url) + case aqua_url + when /eu-1\.cloud\.aquasec\.com/ + @saas_auth_url = "https://eu-1.api.cloudsploit.com/v2/signin" + @wp_url_api = "https://prov-eu-1.cloud.aquasec.com/v1/envs" + when /asia-1\.cloud\.aquasec\.com/ + @saas_auth_url = "https://asia-1.api.cloudsploit.com/v2/signin" + @wp_url_api = "https://prov-asia-1.cloud.aquasec.com/v1/envs" + when /ap-2\.cloud\.aquasec\.com/ + @saas_auth_url = "https://ap-2.api.cloudsploit.com/v2/signin" + @wp_url_api = "https://prov-ap-2.cloud.aquasec.com/v1/envs" + else + @saas_auth_url = "https://api.cloudsploit.com/v2/signin" + @wp_url_api = "https://prov.cloud.aquasec.com/v1/envs" + end + end def aqua_get_token(aqua_url, username, password) + select_region_urls(aqua_url) + if cloud_url?(aqua_url) get_token_from_cloud(username, password) else @@ -21,14 +37,14 @@ def get_token_from_on_prem(aqua_url, username, password) end def get_token_from_cloud(username, password) - get_token(SAAS_AUTH_URL, username, password) + get_token(@saas_auth_url, username, password) end def get_token(auth_url, username, password) print_debug "Getting Auth Token from #{auth_url}" headers = { "Content-Type" => "application/json" } - payload = if auth_url == SAAS_AUTH_URL + payload = if auth_url == @saas_auth_url { "email": username, "password": password }.to_json else { "id": username.to_s, "password": password }.to_json @@ -59,7 +75,7 @@ def get_token(auth_url, username, password) def get_wp_url(token) print_debug "Getting Workload Protection URL" headers = { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" } - response = safe_http_get(WP_URL_API, headers) + response = safe_http_get(@wp_url_api, headers) return unless response