aplos-nca-saas-sdk 0.0.11__py3-none-any.whl → 0.0.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aplos_nca_saas_sdk/integration_testing/configs/_config_base.py +7 -2
- aplos_nca_saas_sdk/integration_testing/configs/app_settings_config.py +88 -0
- aplos_nca_saas_sdk/integration_testing/configs/config_sample.json +31 -18
- aplos_nca_saas_sdk/integration_testing/configs/file_upload_config.py +94 -0
- aplos_nca_saas_sdk/integration_testing/configs/{login.py → login_config.py} +36 -23
- aplos_nca_saas_sdk/integration_testing/configs/nca_execution_config.py +186 -0
- aplos_nca_saas_sdk/integration_testing/files/executions/config1.json +46 -0
- aplos_nca_saas_sdk/integration_testing/integration_test_base.py +10 -3
- aplos_nca_saas_sdk/integration_testing/integration_test_configurations.py +15 -7
- aplos_nca_saas_sdk/integration_testing/integration_test_factory.py +1 -1
- aplos_nca_saas_sdk/integration_testing/integration_test_response.py +1 -1
- aplos_nca_saas_sdk/integration_testing/integration_test_suite.py +10 -3
- aplos_nca_saas_sdk/integration_testing/main.py +6 -6
- aplos_nca_saas_sdk/integration_testing/readme.md +1 -1
- aplos_nca_saas_sdk/integration_testing/tests/app_configuration_test.py +3 -3
- aplos_nca_saas_sdk/integration_testing/tests/app_login_test.py +4 -4
- aplos_nca_saas_sdk/integration_testing/tests/file_upload_test.py +44 -92
- aplos_nca_saas_sdk/integration_testing/tests/nca_analysis_test.py +89 -0
- aplos_nca_saas_sdk/integration_testing/tests/{app_execution_test.py → validation_test.py} +1 -1
- aplos_nca_saas_sdk/nca_resources/_api_base.py +44 -0
- aplos_nca_saas_sdk/{aws_resources → nca_resources}/aws_cognito.py +13 -7
- aplos_nca_saas_sdk/{aws_resources → nca_resources}/aws_s3_presigned_payload.py +3 -3
- aplos_nca_saas_sdk/{aws_resources → nca_resources}/aws_s3_presigned_upload.py +28 -22
- aplos_nca_saas_sdk/nca_resources/nca_analysis.py +304 -0
- aplos_nca_saas_sdk/nca_resources/nca_app_configuration.py +4 -4
- aplos_nca_saas_sdk/nca_resources/{nca_login.py → nca_authenticator.py} +26 -23
- aplos_nca_saas_sdk/nca_resources/nca_endpoints.py +56 -30
- aplos_nca_saas_sdk/nca_resources/nca_file_download.py +130 -0
- aplos_nca_saas_sdk/nca_resources/nca_file_upload.py +27 -29
- aplos_nca_saas_sdk/nca_resources/nca_validations.py +34 -0
- aplos_nca_saas_sdk/run_analysis_execution.py +148 -0
- aplos_nca_saas_sdk/utilities/commandline_args.py +32 -38
- aplos_nca_saas_sdk/utilities/environment_services.py +3 -2
- aplos_nca_saas_sdk/utilities/environment_vars.py +17 -4
- aplos_nca_saas_sdk/utilities/file_utility.py +33 -0
- aplos_nca_saas_sdk/utilities/http_utility.py +5 -14
- aplos_nca_saas_sdk/version.py +1 -1
- {aplos_nca_saas_sdk-0.0.11.dist-info → aplos_nca_saas_sdk-0.0.13.dist-info}/METADATA +1 -1
- aplos_nca_saas_sdk-0.0.13.dist-info/RECORD +51 -0
- {aplos_nca_saas_sdk-0.0.11.dist-info → aplos_nca_saas_sdk-0.0.13.dist-info}/licenses/LICENSE +1 -1
- aplos_nca_saas_sdk/integration_testing/configs/app_settings.py +0 -88
- aplos_nca_saas_sdk/integration_testing/configs/file_upload.py +0 -104
- aplos_nca_saas_sdk/integration_testing/tests/app_validation_test.py +0 -5
- aplos_nca_saas_sdk/nca_resources/nca_executions.py +0 -387
- aplos_nca_saas_sdk-0.0.11.dist-info/RECORD +0 -44
- /aplos_nca_saas_sdk/{files/analysis_files/single_ev/configuration_single_ev.json → sample_files/analysis_files/single_ev/config.json} +0 -0
- /aplos_nca_saas_sdk/{files/analysis_files/single_ev/single_ev.csv → sample_files/analysis_files/single_ev/input.csv} +0 -0
- /aplos_nca_saas_sdk/{files → sample_files}/analysis_files/single_ev/meta_data.json +0 -0
- {aplos_nca_saas_sdk-0.0.11.dist-info → aplos_nca_saas_sdk-0.0.13.dist-info}/WHEEL +0 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
|
+
|
7
|
+
import time
|
8
|
+
from typing import Any, Dict, List
|
9
|
+
from datetime import datetime, timedelta
|
10
|
+
from aws_lambda_powertools import Logger
|
11
|
+
from aplos_nca_saas_sdk.nca_resources._api_base import NCAApiBaseClass
|
12
|
+
from aplos_nca_saas_sdk.nca_resources.aws_s3_presigned_upload import (
|
13
|
+
S3PresignedUrlUpload,
|
14
|
+
)
|
15
|
+
|
16
|
+
from aplos_nca_saas_sdk.utilities.http_utility import HttpUtilities
|
17
|
+
import requests
|
18
|
+
|
19
|
+
logger = Logger(service="nca-file-download")
|
20
|
+
|
21
|
+
|
22
|
+
class NCAFileDownload(NCAApiBaseClass):
|
23
|
+
"""NCA File Download"""
|
24
|
+
|
25
|
+
def __init__(self, host: str) -> None:
|
26
|
+
super().__init__(host)
|
27
|
+
|
28
|
+
def upload(
|
29
|
+
self,
|
30
|
+
input_file_path: str,
|
31
|
+
user_name: str | None = None,
|
32
|
+
password: str | None = None,
|
33
|
+
) -> Dict[str, Any]:
|
34
|
+
"""
|
35
|
+
Uploads a file to the Aplos NCA Cloud
|
36
|
+
|
37
|
+
Args:
|
38
|
+
input_file_path (str): local path to the file
|
39
|
+
|
40
|
+
Raises:
|
41
|
+
ValueError: _description_
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
Dict: {"file_id": id, "statu_code": 204}
|
45
|
+
"""
|
46
|
+
if input_file_path is None or not input_file_path:
|
47
|
+
raise ValueError("Valid input_file_path is required.")
|
48
|
+
|
49
|
+
if not self.authenticator.cognito.jwt:
|
50
|
+
if not user_name or not password:
|
51
|
+
raise ValueError(
|
52
|
+
"Valid user_name and password are required or you can set the authenticator object."
|
53
|
+
)
|
54
|
+
self.authenticator.authenticate(username=user_name, password=password)
|
55
|
+
|
56
|
+
uploader: S3PresignedUrlUpload = S3PresignedUrlUpload(self.host)
|
57
|
+
uploader.authenticator = self.authenticator
|
58
|
+
|
59
|
+
upload_response: Dict[str, Any] = uploader.upload_file(
|
60
|
+
input_file=input_file_path
|
61
|
+
)
|
62
|
+
|
63
|
+
return upload_response
|
64
|
+
|
65
|
+
def download(
|
66
|
+
self,
|
67
|
+
file_id: str,
|
68
|
+
user_name: str | None = None,
|
69
|
+
password: str | None = None,
|
70
|
+
) -> Dict[str, Any]:
|
71
|
+
"""
|
72
|
+
Downloads a file from the Aplos NCA Cloud
|
73
|
+
|
74
|
+
Args:
|
75
|
+
file_id (str): the id of the file to download
|
76
|
+
|
77
|
+
Raises:
|
78
|
+
ValueError: _description_
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
Dict: {"file_id": id, "statu_code": 204}
|
82
|
+
"""
|
83
|
+
|
84
|
+
logger.info({"message": "Downloading file", "file_id": file_id})
|
85
|
+
|
86
|
+
file_info_endpoint = self.endpoints.file(
|
87
|
+
file_id,
|
88
|
+
)
|
89
|
+
|
90
|
+
if not self.authenticator.cognito.jwt:
|
91
|
+
if not user_name or not password:
|
92
|
+
raise ValueError(
|
93
|
+
"Valid user_name and password are required or you can set the authenticator object."
|
94
|
+
)
|
95
|
+
self.authenticator.authenticate(username=user_name, password=password)
|
96
|
+
|
97
|
+
max_wait_in_minutes: int = 3
|
98
|
+
headers = HttpUtilities.get_headers(self.authenticator.cognito.jwt)
|
99
|
+
current_time = datetime.now()
|
100
|
+
|
101
|
+
# Create a timedelta object representing 3 minutes
|
102
|
+
time_delta = timedelta(minutes=max_wait_in_minutes)
|
103
|
+
# Add the timedelta to the current time
|
104
|
+
max_time = current_time + time_delta
|
105
|
+
|
106
|
+
complete = False
|
107
|
+
json_response: Dict[str, Any] = {}
|
108
|
+
while not complete:
|
109
|
+
response = requests.get(file_info_endpoint, headers=headers, timeout=60)
|
110
|
+
json_response: dict = response.json()
|
111
|
+
errors: List[Dict[str, Any]] = []
|
112
|
+
errors.extend(json_response.get("errors") or [])
|
113
|
+
status = json_response.get("workable_state")
|
114
|
+
complete = status == "ready"
|
115
|
+
|
116
|
+
if status == "invalid" or len(errors) > 0:
|
117
|
+
break
|
118
|
+
if complete:
|
119
|
+
break
|
120
|
+
if not complete:
|
121
|
+
time.sleep(5)
|
122
|
+
if datetime.now() > max_time:
|
123
|
+
error = (
|
124
|
+
"Timeout attempting to get conversion file status. "
|
125
|
+
f"The current timeout limit is {max_wait_in_minutes} minutes. "
|
126
|
+
"You may need to up the timeout period, or check for errors. "
|
127
|
+
)
|
128
|
+
raise RuntimeError(error)
|
129
|
+
|
130
|
+
return json_response
|
@@ -1,41 +1,28 @@
|
|
1
1
|
"""
|
2
|
-
Copyright 2024 Aplos Analytics
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
3
|
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
4
|
Property of Aplos Analytics, Utah, USA
|
5
5
|
"""
|
6
6
|
|
7
7
|
from typing import Any, Dict
|
8
|
-
from aplos_nca_saas_sdk.
|
9
|
-
from aplos_nca_saas_sdk.nca_resources.
|
10
|
-
|
8
|
+
from aplos_nca_saas_sdk.nca_resources._api_base import NCAApiBaseClass
|
9
|
+
from aplos_nca_saas_sdk.nca_resources.aws_s3_presigned_upload import (
|
10
|
+
S3PresignedUrlUpload,
|
11
|
+
)
|
11
12
|
|
12
13
|
|
13
|
-
class NCAFileUpload:
|
14
|
+
class NCAFileUpload(NCAApiBaseClass):
|
14
15
|
"""NCA File Upload"""
|
15
16
|
|
16
|
-
def __init__(self,
|
17
|
-
|
18
|
-
raise ValueError("Authenticated nca_login is required.")
|
17
|
+
def __init__(self, host: str) -> None:
|
18
|
+
super().__init__(host)
|
19
19
|
|
20
|
-
|
21
|
-
self
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def api_root(self) -> str:
|
27
|
-
"""Gets the base url"""
|
28
|
-
|
29
|
-
if self.__api_domain is None:
|
30
|
-
raise RuntimeError("Missing Aplos Api Domain")
|
31
|
-
|
32
|
-
url = HttpUtilities.build_url(self.__api_domain)
|
33
|
-
if isinstance(url, str):
|
34
|
-
return f"{url}/tenants/{self.__tenant_id}/users/{self.__user_id}"
|
35
|
-
|
36
|
-
raise RuntimeError("Missing Aplos Api Domain")
|
37
|
-
|
38
|
-
def upload(self, input_file_path: str) -> Dict[str, Any]:
|
20
|
+
def upload(
|
21
|
+
self,
|
22
|
+
input_file_path: str,
|
23
|
+
user_name: str | None = None,
|
24
|
+
password: str | None = None,
|
25
|
+
) -> Dict[str, Any]:
|
39
26
|
"""
|
40
27
|
Uploads a file to the Aplos NCA Cloud
|
41
28
|
|
@@ -51,7 +38,18 @@ class NCAFileUpload:
|
|
51
38
|
if input_file_path is None or not input_file_path:
|
52
39
|
raise ValueError("Valid input_file_path is required.")
|
53
40
|
|
54
|
-
|
55
|
-
|
41
|
+
if not self.authenticator.cognito.jwt:
|
42
|
+
if not user_name or not password:
|
43
|
+
raise ValueError(
|
44
|
+
"Valid user_name and password are required or you can set the authenticator object."
|
45
|
+
)
|
46
|
+
self.authenticator.authenticate(username=user_name, password=password)
|
47
|
+
|
48
|
+
uploader: S3PresignedUrlUpload = S3PresignedUrlUpload(self.host)
|
49
|
+
uploader.authenticator = self.authenticator
|
50
|
+
|
51
|
+
upload_response: Dict[str, Any] = uploader.upload_file(
|
52
|
+
input_file=input_file_path
|
53
|
+
)
|
56
54
|
|
57
55
|
return upload_response
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
|
+
|
7
|
+
import requests
|
8
|
+
|
9
|
+
from aplos_nca_saas_sdk.nca_resources._api_base import NCAApiBaseClass
|
10
|
+
|
11
|
+
|
12
|
+
class NCAValidation(NCAApiBaseClass):
|
13
|
+
"""NCA Analysis Validation API"""
|
14
|
+
|
15
|
+
def __init__(self, host: str) -> None:
|
16
|
+
super().__init__(host)
|
17
|
+
|
18
|
+
def validate(self, jwt: str) -> bool:
|
19
|
+
"""
|
20
|
+
Validates the JWT
|
21
|
+
|
22
|
+
Args:
|
23
|
+
jwt (str): JWT
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
bool: True if the JWT is valid
|
27
|
+
"""
|
28
|
+
url = self.endpoints.validations
|
29
|
+
response = requests.post(url, json={"jwt": jwt}, timeout=30)
|
30
|
+
|
31
|
+
if response.status_code != 200:
|
32
|
+
return False
|
33
|
+
|
34
|
+
return True
|
@@ -0,0 +1,148 @@
|
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
|
+
|
7
|
+
import json
|
8
|
+
import os
|
9
|
+
from pathlib import Path
|
10
|
+
|
11
|
+
from aws_lambda_powertools import Logger
|
12
|
+
|
13
|
+
from aplos_nca_saas_sdk.nca_resources.nca_analysis import NCAAnalysis
|
14
|
+
from aplos_nca_saas_sdk.utilities.commandline_args import CommandlineArgs
|
15
|
+
|
16
|
+
logger = Logger()
|
17
|
+
|
18
|
+
|
19
|
+
def main():
|
20
|
+
"""Run Main when then file is run directly"""
|
21
|
+
try:
|
22
|
+
print("Welcome to the NCA Engine Upload & Execution Demo")
|
23
|
+
args = CommandlineArgs()
|
24
|
+
files_path = os.path.join(
|
25
|
+
Path(__file__).parent, "sample_files", "analysis_files", "single_ev"
|
26
|
+
)
|
27
|
+
|
28
|
+
# set up some defaults to make the demos quicker
|
29
|
+
args.analysis_file_default = os.path.join(files_path, "input.csv")
|
30
|
+
args.config_file_default = os.path.join(files_path, "config.json")
|
31
|
+
args.metadata_file_default = os.path.join(files_path, "meta_data.json")
|
32
|
+
args.output_directory_default = os.path.join(files_path, ".output")
|
33
|
+
if not args.is_valid():
|
34
|
+
print("\n\n")
|
35
|
+
print("Missing some arguments.")
|
36
|
+
exit()
|
37
|
+
|
38
|
+
analysis_api = NCAAnalysis(host=str(args.host))
|
39
|
+
analysis_api.verbose = True
|
40
|
+
|
41
|
+
print("\tLoading analysis configurations")
|
42
|
+
print(f"\t\t...{os.path.basename(args.config_file)}")
|
43
|
+
config_data: dict = read_json_file(str(args.config_file))
|
44
|
+
|
45
|
+
print("\tLoading analysis meta data")
|
46
|
+
print(f"\t\t...{os.path.basename(args.metadata_file)}")
|
47
|
+
meta_data = optional_json_loads(read_text_file(str(args.metadata_file)))
|
48
|
+
|
49
|
+
wait_for_results = True
|
50
|
+
max_wait_in_seconds = 900 # 15 minutes
|
51
|
+
resutls = analysis_api.execute(
|
52
|
+
username=str(args.username),
|
53
|
+
password=str(args.password),
|
54
|
+
input_file_path=str(args.analysis_file),
|
55
|
+
config_data=config_data,
|
56
|
+
meta_data=meta_data,
|
57
|
+
output_directory=str(args.output_directory),
|
58
|
+
wait_for_results=wait_for_results,
|
59
|
+
max_wait_in_seconds=max_wait_in_seconds,
|
60
|
+
)
|
61
|
+
|
62
|
+
if not wait_for_results:
|
63
|
+
exec_id = resutls.get("execution", {}).get("execution_id", "")
|
64
|
+
print(
|
65
|
+
"Analysis execution has been queued. We're not waiting for the results."
|
66
|
+
)
|
67
|
+
print(f"Please check your results with execution id {exec_id}.")
|
68
|
+
|
69
|
+
print("🙌 Thank you for using the NCA API for an Analysis Execution Demo. 🙌")
|
70
|
+
except Exception as e: # pylint: disable=w0718
|
71
|
+
print(
|
72
|
+
"🚨 An error occured ... exiting with an error. Please check your settings and try again."
|
73
|
+
)
|
74
|
+
print(
|
75
|
+
"If you believe this is bug please create a support ticket and include the execution id (if available)."
|
76
|
+
)
|
77
|
+
print(
|
78
|
+
"If it's not reported in the error below check your account for the failed execution."
|
79
|
+
)
|
80
|
+
|
81
|
+
print(str(e))
|
82
|
+
|
83
|
+
|
84
|
+
def optional_json_loads(data: str | dict) -> str | dict:
|
85
|
+
"""
|
86
|
+
Attempts to load the data as json, fails gracefull and retuns the data is if it fails
|
87
|
+
Args:
|
88
|
+
data (str): data as string
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
str | dict: either the data as is or a converted dictionary/json object
|
92
|
+
"""
|
93
|
+
if isinstance(data, dict):
|
94
|
+
return data
|
95
|
+
|
96
|
+
try:
|
97
|
+
data = json.loads(str(data))
|
98
|
+
finally:
|
99
|
+
pass
|
100
|
+
return data
|
101
|
+
|
102
|
+
|
103
|
+
def read_json_file(file_path: str) -> dict:
|
104
|
+
"""
|
105
|
+
Reads a file and returns the json
|
106
|
+
Args:
|
107
|
+
file_path (str): _description_
|
108
|
+
|
109
|
+
Raises:
|
110
|
+
FileNotFoundError: _description_
|
111
|
+
|
112
|
+
Returns:
|
113
|
+
dict: _description_
|
114
|
+
"""
|
115
|
+
if not os.path.exists(file_path):
|
116
|
+
raise FileNotFoundError(f"File Not Found: {file_path}")
|
117
|
+
|
118
|
+
data = None
|
119
|
+
with open(file_path, mode="r", encoding="utf8") as file:
|
120
|
+
data = json.load(file)
|
121
|
+
|
122
|
+
return data
|
123
|
+
|
124
|
+
|
125
|
+
def read_text_file(file_path: str) -> str:
|
126
|
+
"""
|
127
|
+
Read files contents
|
128
|
+
Args:
|
129
|
+
file_path (str): path to the file
|
130
|
+
|
131
|
+
Raises:
|
132
|
+
FileNotFoundError: if the file is not found
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
str: the files data
|
136
|
+
"""
|
137
|
+
if not os.path.exists(file_path):
|
138
|
+
raise FileNotFoundError(f"File Not Found: {file_path}")
|
139
|
+
|
140
|
+
data = None
|
141
|
+
with open(file_path, mode="r", encoding="utf8") as file:
|
142
|
+
data = file.read()
|
143
|
+
|
144
|
+
return data
|
145
|
+
|
146
|
+
|
147
|
+
if __name__ == "__main__":
|
148
|
+
main()
|
@@ -1,17 +1,27 @@
|
|
1
|
-
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
|
+
|
2
7
|
import argparse
|
3
8
|
import getpass
|
9
|
+
import os
|
4
10
|
from pathlib import Path
|
5
11
|
from typing import List
|
6
|
-
|
12
|
+
|
7
13
|
from dotenv import load_dotenv
|
8
14
|
|
15
|
+
from aplos_nca_saas_sdk.utilities.environment_vars import EnvironmentVars
|
16
|
+
|
9
17
|
# load the environment (.env) file if any
|
10
18
|
# this may or may not be the desired results
|
11
19
|
load_dotenv(override=True)
|
12
20
|
|
13
21
|
|
14
22
|
class CommandlineArgs:
|
23
|
+
"""Wrapper fro commandline args"""
|
24
|
+
|
15
25
|
def __init__(self) -> None:
|
16
26
|
# command line args
|
17
27
|
self.parser = argparse.ArgumentParser(
|
@@ -35,19 +45,17 @@ class CommandlineArgs:
|
|
35
45
|
"-m", "--metadata-file", required=False, help="Path to the metadata file"
|
36
46
|
)
|
37
47
|
|
38
|
-
self.parser.add_argument("-a", "--api-url", required=False, help="The api url")
|
39
48
|
self.parser.add_argument(
|
40
|
-
"-
|
49
|
+
"-d",
|
50
|
+
"--host",
|
51
|
+
required=False,
|
52
|
+
help="The api host/host. Eg. api.aplos-nca.com, api.tenant.aplos-nca.com",
|
41
53
|
)
|
42
54
|
|
43
55
|
self.parser.add_argument(
|
44
56
|
"-v", "--verbose", required=False, help="Detailed logging information"
|
45
57
|
)
|
46
58
|
|
47
|
-
self.parser.add_argument(
|
48
|
-
"-r", "--region", required=False, help="AWS Region. For Cognito Login"
|
49
|
-
)
|
50
|
-
|
51
59
|
self.parser.add_argument(
|
52
60
|
"-s",
|
53
61
|
"--skip",
|
@@ -69,12 +77,12 @@ class CommandlineArgs:
|
|
69
77
|
help="The full path to an environment file (.env file).",
|
70
78
|
)
|
71
79
|
|
80
|
+
# auth information
|
72
81
|
self.username: str | None = None
|
73
82
|
self.password: str | None = None
|
74
|
-
self.
|
75
|
-
self.cognito_client_id: str | None = None
|
76
|
-
self.aws_region: str | None = None
|
83
|
+
self.host: str | None = None
|
77
84
|
|
85
|
+
# excuction setup
|
78
86
|
self.config_file: str | None = None
|
79
87
|
self.config_file_default: str | None = None
|
80
88
|
self.analysis_file: str | None = None
|
@@ -102,9 +110,8 @@ class CommandlineArgs:
|
|
102
110
|
self.config_file = args.config_file
|
103
111
|
# anything with a dash (in the args) is accessed with an underscore
|
104
112
|
self.analysis_file = args.analyis_file
|
105
|
-
self.
|
106
|
-
|
107
|
-
self.aws_region = args.region
|
113
|
+
self.host = args.host
|
114
|
+
|
108
115
|
self.metadata_file = args.metadata_file
|
109
116
|
self.skip = args.skip
|
110
117
|
self.output_directory = args.output_directory
|
@@ -128,24 +135,12 @@ class CommandlineArgs:
|
|
128
135
|
self.password = self.prompt_for_input(
|
129
136
|
"password", env.password, is_sensitive=True
|
130
137
|
)
|
131
|
-
if not self.aws_region:
|
132
|
-
if self.skip and env.aws_region:
|
133
|
-
self.aws_region = env.aws_region
|
134
|
-
else:
|
135
|
-
self.aws_region = self.prompt_for_input("AWS Region", env.aws_region)
|
136
|
-
if not self.api_domain:
|
137
|
-
if self.skip and env.api_domain:
|
138
|
-
self.api_domain = env.api_domain
|
139
|
-
else:
|
140
|
-
self.api_domain = self.prompt_for_input("Api Domain", env.api_domain)
|
141
138
|
|
142
|
-
if not self.
|
143
|
-
if self.skip and env.
|
144
|
-
self.
|
139
|
+
if not self.host:
|
140
|
+
if self.skip and env.host:
|
141
|
+
self.host = env.host
|
145
142
|
else:
|
146
|
-
self.
|
147
|
-
"Cognito Client Id", env.client_id
|
148
|
-
)
|
143
|
+
self.host = self.prompt_for_input("Api Domain", env.host)
|
149
144
|
|
150
145
|
if not self.analysis_file:
|
151
146
|
if self.skip and self.analysis_file_default or env.analysis_file:
|
@@ -196,11 +191,9 @@ class CommandlineArgs:
|
|
196
191
|
required_fields = [
|
197
192
|
self.username,
|
198
193
|
self.password,
|
199
|
-
self.aws_region,
|
200
|
-
self.cognito_client_id,
|
201
194
|
self.analysis_file,
|
202
195
|
self.config_file,
|
203
|
-
self.
|
196
|
+
self.host,
|
204
197
|
]
|
205
198
|
for field in required_fields:
|
206
199
|
if not field:
|
@@ -314,15 +307,16 @@ def main():
|
|
314
307
|
pwd = "************" if args.password else "empty"
|
315
308
|
print(f"username = {args.username}")
|
316
309
|
print(f"password = {pwd}")
|
317
|
-
|
318
|
-
print(f"
|
319
|
-
print(f"
|
310
|
+
|
311
|
+
print(f"host = {args.host}")
|
312
|
+
print(f"analysis_file = {args.analysis_file}")
|
313
|
+
|
320
314
|
print(f"config_file = {args.config_file}")
|
321
315
|
print(f"metadata_file = {args.metadata_file}")
|
322
|
-
|
316
|
+
|
323
317
|
print(f"output_directory = {args.output_directory}")
|
324
318
|
|
325
|
-
print("
|
319
|
+
print("✅ All required parameters are accounted for.")
|
326
320
|
|
327
321
|
else:
|
328
322
|
print("Missing some required fields.")
|
@@ -1,3 +1,9 @@
|
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
|
+
|
1
7
|
import os
|
2
8
|
|
3
9
|
|
@@ -6,7 +12,7 @@ class EnvironmentVars:
|
|
6
12
|
|
7
13
|
def __init__(self) -> None:
|
8
14
|
# load defaults
|
9
|
-
self.
|
15
|
+
self.host = os.getenv("APLOS_host", "")
|
10
16
|
|
11
17
|
self.aws_region = os.getenv("COGNITO_REGION")
|
12
18
|
self.client_id = os.getenv("COGNITO_CLIENT_ID")
|
@@ -17,7 +23,14 @@ class EnvironmentVars:
|
|
17
23
|
self.metadata_file = os.getenv("METADATA_FILE")
|
18
24
|
self.analysis_file = os.getenv("ANALYSIS_FILE")
|
19
25
|
|
20
|
-
if self.
|
21
|
-
self.
|
26
|
+
if self.host is not None and "https://" in self.host:
|
27
|
+
self.host = self.host.replace("https://", "")
|
28
|
+
|
29
|
+
self.aplos_api_url = f"https://{self.host}"
|
22
30
|
|
23
|
-
|
31
|
+
@staticmethod
|
32
|
+
def is_running_in_aws_lambda():
|
33
|
+
"""
|
34
|
+
A quick way to check if we are running in an AWS Lambda Environment
|
35
|
+
"""
|
36
|
+
return "AWS_LAMBDA_FUNCTION_NAME" in os.environ
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
|
+
|
7
|
+
import os
|
8
|
+
|
9
|
+
|
10
|
+
from aplos_nca_saas_sdk.utilities.environment_services import EnvironmentServices
|
11
|
+
|
12
|
+
|
13
|
+
class FileUtility:
|
14
|
+
"""General File Utilities"""
|
15
|
+
|
16
|
+
@staticmethod
|
17
|
+
def load_filepath(file_path: str) -> str:
|
18
|
+
"""Load the file_path"""
|
19
|
+
if not file_path:
|
20
|
+
raise RuntimeError("file_path is required")
|
21
|
+
elif file_path.startswith("${module}"):
|
22
|
+
# find the path
|
23
|
+
es: EnvironmentServices = EnvironmentServices()
|
24
|
+
root = es.find_module_path()
|
25
|
+
if not root:
|
26
|
+
raise RuntimeError(
|
27
|
+
"Unable to find the module path. Please use the ${module} syntax to define the file path"
|
28
|
+
)
|
29
|
+
file_path = file_path.replace("${module}", root)
|
30
|
+
|
31
|
+
# get the correct os path separator
|
32
|
+
file_path = os.path.normpath(file_path)
|
33
|
+
return file_path
|
@@ -1,22 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"""
|
2
|
+
Copyright 2024-2025 Aplos Analytics
|
3
|
+
All Rights Reserved. www.aplosanalytics.com LICENSED MATERIALS
|
4
|
+
Property of Aplos Analytics, Utah, USA
|
5
|
+
"""
|
6
6
|
|
7
7
|
|
8
8
|
class HttpUtilities:
|
9
9
|
"""Http Utilties"""
|
10
10
|
|
11
|
-
@staticmethod
|
12
|
-
def build_url(domain_name: str) -> str:
|
13
|
-
"""Build the url"""
|
14
|
-
domain_name = domain_name.strip()
|
15
|
-
if domain_name.startswith("http"):
|
16
|
-
return domain_name
|
17
|
-
else:
|
18
|
-
return f"https://{domain_name}"
|
19
|
-
|
20
11
|
@staticmethod
|
21
12
|
def get_headers(jwt: str) -> dict:
|
22
13
|
"""Get the Http Headers"""
|
aplos_nca_saas_sdk/version.py
CHANGED