Skip to content

Commit

Permalink
Add regions to aqua
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukhanskyi committed Jul 10, 2024
1 parent f7d9bff commit 37ca11d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tasks/connectors/aqua/lib/aqua_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 37ca11d

Please sign in to comment.