in utils/appverifier_launch_sample.py [0:0]
def launchSample(sample_file, sample_region, sample_secret_endpoint, sample_secret_certificate, sample_secret_private_key, sample_arguments):
print("Attempting to get credentials from secrets using Boto3...")
try:
secrets_client = boto3.client(
"secretsmanager", region_name=sample_region)
sample_endpoint = secrets_client.get_secret_value(
SecretId=sample_secret_endpoint)["SecretString"]
sample_certificate = secrets_client.get_secret_value(
SecretId=sample_secret_certificate)
sample_private_key = secrets_client.get_secret_value(
SecretId=sample_secret_private_key)
except Exception: # lgtm [py/catch-base-exception]
sys.exit("ERROR: Could not get secrets to launch sample!")
current_folder = pathlib.Path(__file__).resolve()
# Remove the name of the python file
current_folder = str(current_folder).replace("appverifier_xml_util.py", "")
print("Saving credentials to file...")
tmp_certificate_file_path = str(current_folder) + "tmp_certificate.pem"
tmp_private_key_path = str(current_folder) + "tmp_privatekey.pem.key"
with open(tmp_certificate_file_path, "w") as file:
file.write(sample_certificate["SecretString"]) # lgtm [py/clear-text-storage-sensitive-data]
with open(tmp_private_key_path, "w") as file:
file.write(sample_private_key["SecretString"]) # lgtm [py/clear-text-storage-sensitive-data]
print("Saved credentials to file...")
print("Processing arguments...")
launch_arguments = []
launch_arguments.append("--endpoint")
launch_arguments.append(sample_endpoint)
launch_arguments.append("--cert")
launch_arguments.append(tmp_certificate_file_path)
launch_arguments.append("--key")
launch_arguments.append(tmp_private_key_path)
sample_arguments_split = sample_arguments.split(" ")
for arg in sample_arguments_split:
launch_arguments.append(arg)
print("Running sample...")
exit_code = 0
sample_return = subprocess.run(
args=launch_arguments, executable=sample_file)
exit_code = sample_return.returncode
print("Deleting credentials files...")
os.remove(tmp_certificate_file_path)
os.remove(tmp_private_key_path)
if (exit_code == 0):
print("SUCCESS: Finished running sample! Exiting with success")
else:
print("ERROR: Sample did not return success! Exit code " + str(exit_code))
return exit_code