88import shutil
99import requests
1010import logging
11- from urllib .parse import urlparse
1211from confidential_compute import ConfidentialCompute , ConfigurationMissingError , OperatorKeyPermissionError , OperatorKeyNotFoundError , ConfidentialComputeStartupError
1312from azure .keyvault .secrets import SecretClient
1413from azure .identity import DefaultAzureCredential , CredentialUnavailableError
@@ -22,6 +21,8 @@ class AzureEntryPoint(ConfidentialCompute):
2221 env_name = os .getenv ("DEPLOYMENT_ENVIRONMENT" )
2322 jar_name = os .getenv ("JAR_NAME" , "default-jar-name" )
2423 jar_version = os .getenv ("JAR_VERSION" , "default-jar-version" )
24+ default_core_endpoint = f"https://core-{ env_name } .uidapi.com" .lower ()
25+ default_optout_endpoint = f"https://optout-{ env_name } .uidapi.com" .lower ()
2526
2627 FINAL_CONFIG = "/tmp/final-config.json"
2728
@@ -50,37 +51,25 @@ def __create_final_config(self):
5051 except IOError as e :
5152 logging .error (f"Failed to create { AzureEntryPoint .FINAL_CONFIG } with error: { e } " )
5253 sys .exit (1 )
53-
54- CORE_BASE_URL = os .getenv ("CORE_BASE_URL" )
55- OPTOUT_BASE_URL = os .getenv ("OPTOUT_BASE_URL" )
5654
57- if CORE_BASE_URL and OPTOUT_BASE_URL and AzureEntryPoint .env_name != 'prod' :
58- logging .info (f"-- replacing URLs by { CORE_BASE_URL } and { OPTOUT_BASE_URL } " )
59- with open (AzureEntryPoint .FINAL_CONFIG , "r" ) as file :
60- config = file .read ()
61-
62- config = config .replace ("core-integ.uidapi.com" , urlparse (CORE_BASE_URL ).netloc )
63- config = config .replace ("optout-integ.uidapi.com" , urlparse (OPTOUT_BASE_URL ).netloc )
55+ logging .info (f"-- replacing URLs by { self .configs ["core_base_url" ]} and { self .configs ["optout_base_url" ]} " )
56+ with open (AzureEntryPoint .FINAL_CONFIG , "r" ) as file :
57+ config = file .read ()
6458
65- with open (AzureEntryPoint .FINAL_CONFIG , "w" ) as file :
66- file .write (config )
59+ config = config .replace ("https://core.uidapi.com" , self .configs ["core_base_url" ])
60+ config = config .replace ("https://optout.uidapi.com" , self .configs ["optout_base_url" ])
61+ with open (AzureEntryPoint .FINAL_CONFIG , "w" ) as file :
62+ file .write (config )
6763
6864 with open (AzureEntryPoint .FINAL_CONFIG , "r" ) as file :
6965 logging .info (file .read ())
7066
71- def __set_base_urls (self ):
72- with open (AzureEntryPoint .FINAL_CONFIG , "r" ) as file :
73- jdata = json .load (file )
74- self .configs ["core_base_url" ] = jdata ["core_attest_url" ]
75- self .configs ["optout_base_url" ] = jdata ["optout_api_uri" ]
76-
7767 def __set_operator_key (self ):
7868 try :
7969 credential = DefaultAzureCredential ()
8070 kv_URL = f"https://{ AzureEntryPoint .kv_name } .vault.azure.net"
8171 secret_client = SecretClient (vault_url = kv_URL , credential = credential )
8272 secret = secret_client .get_secret (AzureEntryPoint .secret_name )
83- # print(f"Secret Value: {secret.value}")
8473 self .configs ["operator_key" ] = secret .value
8574
8675 except (CredentialUnavailableError , ClientAuthenticationError ) as auth_error :
@@ -92,14 +81,13 @@ def __set_operator_key(self):
9281
9382
9483 def _set_confidential_config (self , secret_identifier : str = None ):
84+ """Builds and sets ConfidentialComputeConfig"""
9585 self .configs ["skip_validations" ] = os .getenv ("SKIP_VALIDATIONS" , "false" ).lower () == "true"
9686 self .configs ["debug_mode" ] = os .getenv ("DEBUG_MODE" , "false" ).lower () == "true"
9787 self .configs ["environment" ] = AzureEntryPoint .env_name
98-
99- # set self.configs["operator_key"]
88+ self . configs [ "core_base_url" ] = os . getenv ( "CORE_BASE_URL" ) if os . getenv ( "CORE_BASE_URL" ) and AzureEntryPoint . env_name == "integ" else AzureEntryPoint . default_core_endpoint
89+ self .configs ["optout_base_url" ] = os . getenv ( "OPTOUT_BASE_URL" ) if os . getenv ( "OPTOUT_BASE_URL" ) and AzureEntryPoint . env_name == "integ" else AzureEntryPoint . default_optout_endpoint
10090 self .__set_operator_key ()
101- # set base urls from final config file
102- self .__set_base_urls ()
10391
10492 def __run_operator (self ):
10593
@@ -150,10 +138,10 @@ def _validate_auxiliaries(self):
150138 def run_compute (self ) -> None :
151139 """Main execution flow for confidential compute."""
152140 self .__check_env_variables ()
153- self .__create_final_config ()
154141 self ._set_confidential_config ()
155142 if not self .configs .get ("skip_validations" ):
156143 self .validate_configuration ()
144+ self .__create_final_config ()
157145 self ._setup_auxiliaries ()
158146 self .__run_operator ()
159147
0 commit comments