aplos-nca-saas-sdk 0.0.12__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 +29 -29
- aplos_nca_saas_sdk/integration_testing/configs/config_sample.json +9 -9
- aplos_nca_saas_sdk/integration_testing/configs/file_upload_config.py +1 -1
- aplos_nca_saas_sdk/integration_testing/configs/login_config.py +15 -14
- aplos_nca_saas_sdk/integration_testing/configs/nca_execution_config.py +1 -1
- aplos_nca_saas_sdk/integration_testing/integration_test_base.py +2 -2
- aplos_nca_saas_sdk/integration_testing/integration_test_configurations.py +9 -5
- 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 +8 -7
- 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 +3 -3
- aplos_nca_saas_sdk/integration_testing/tests/file_upload_test.py +40 -91
- aplos_nca_saas_sdk/integration_testing/tests/nca_analysis_test.py +2 -2
- aplos_nca_saas_sdk/integration_testing/tests/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 +2 -2
- 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 +23 -167
- aplos_nca_saas_sdk/nca_resources/nca_app_configuration.py +4 -4
- aplos_nca_saas_sdk/nca_resources/{nca_login.py → nca_authenticator.py} +23 -20
- 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 +29 -13
- aplos_nca_saas_sdk/utilities/environment_services.py +3 -2
- aplos_nca_saas_sdk/utilities/environment_vars.py +10 -4
- aplos_nca_saas_sdk/utilities/file_utility.py +1 -1
- aplos_nca_saas_sdk/utilities/http_utility.py +1 -26
- aplos_nca_saas_sdk/version.py +1 -1
- {aplos_nca_saas_sdk-0.0.12.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.12.dist-info → aplos_nca_saas_sdk-0.0.13.dist-info}/licenses/LICENSE +1 -1
- aplos_nca_saas_sdk-0.0.12.dist-info/RECORD +0 -47
- /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.12.dist-info → aplos_nca_saas_sdk-0.0.13.dist-info}/WHEEL +0 -0
@@ -1,5 +1,5 @@
|
|
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
|
"""
|
@@ -48,7 +48,7 @@ class NCAAnalysisTest(IntegrationTestBase):
|
|
48
48
|
try:
|
49
49
|
# Create new NCA Execution
|
50
50
|
nca_execution: NCAAnalysis = NCAAnalysis(
|
51
|
-
nca_execution_config.login.
|
51
|
+
nca_execution_config.login.host
|
52
52
|
)
|
53
53
|
|
54
54
|
# Initialize Configuration Data
|
@@ -0,0 +1,44 @@
|
|
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
|
+
from typing import Any
|
8
|
+
|
9
|
+
|
10
|
+
from aplos_nca_saas_sdk.nca_resources.nca_authenticator import NCAAuthenticator
|
11
|
+
from aplos_nca_saas_sdk.nca_resources.nca_endpoints import NCAEndpoints
|
12
|
+
|
13
|
+
|
14
|
+
class NCAApiBaseClass:
|
15
|
+
"""NCA Api Base Class"""
|
16
|
+
|
17
|
+
def __init__(self, host: str) -> None:
|
18
|
+
self.host = host
|
19
|
+
self.__authenticator: NCAAuthenticator = NCAAuthenticator(host=host)
|
20
|
+
self.__endpoints: NCAEndpoints = NCAEndpoints(host=host)
|
21
|
+
if not host:
|
22
|
+
raise ValueError("Missing Aplos Api Domain")
|
23
|
+
|
24
|
+
@property
|
25
|
+
def authenticator(self) -> NCAAuthenticator:
|
26
|
+
"""Gets the authenticator"""
|
27
|
+
|
28
|
+
return self.__authenticator
|
29
|
+
|
30
|
+
@authenticator.setter
|
31
|
+
def authenticator(self, value: Any) -> None:
|
32
|
+
"""Sets the authenticator"""
|
33
|
+
|
34
|
+
self.__authenticator = value
|
35
|
+
|
36
|
+
@property
|
37
|
+
def endpoints(self) -> NCAEndpoints:
|
38
|
+
"""Gets the endpoints"""
|
39
|
+
|
40
|
+
if self.authenticator.cognito.jwt:
|
41
|
+
self.__endpoints.tenant_id = self.authenticator.cognito.tenant_id
|
42
|
+
self.__endpoints.user_id = self.authenticator.cognito.user_id
|
43
|
+
|
44
|
+
return self.__endpoints
|
@@ -1,5 +1,5 @@
|
|
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
|
"""
|
@@ -79,7 +79,7 @@ class CognitoAuthentication:
|
|
79
79
|
- or the Aplos Domain (which can get the clientId and region)
|
80
80
|
"""
|
81
81
|
if self.__client_id is None and self.__aplos_domain is not None:
|
82
|
-
self.__config = NCAAppConfiguration(
|
82
|
+
self.__config = NCAAppConfiguration(host=self.__aplos_domain)
|
83
83
|
self.__client_id = self.__config.cognito_client_id
|
84
84
|
self.__region = self.__config.cognito_region
|
85
85
|
|
@@ -1,12 +1,12 @@
|
|
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
|
|
8
|
-
class
|
9
|
-
"""
|
8
|
+
class S3PresignedUrlPayload:
|
9
|
+
"""S3 Presigned Url Payload"""
|
10
10
|
|
11
11
|
def __init__(self, payload: dict | None = None) -> None:
|
12
12
|
self.url: str | None = None
|
@@ -1,5 +1,5 @@
|
|
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
|
"""
|
@@ -9,20 +9,23 @@ import os
|
|
9
9
|
from typing import Any, Dict
|
10
10
|
|
11
11
|
import requests
|
12
|
-
from aplos_nca_saas_sdk.
|
13
|
-
|
12
|
+
from aplos_nca_saas_sdk.nca_resources.aws_s3_presigned_payload import (
|
13
|
+
S3PresignedUrlPayload,
|
14
14
|
)
|
15
|
-
from aplos_nca_saas_sdk.utilities.http_utility import HttpUtilities
|
15
|
+
from aplos_nca_saas_sdk.utilities.http_utility import HttpUtilities
|
16
|
+
from aplos_nca_saas_sdk.nca_resources._api_base import NCAApiBaseClass
|
16
17
|
|
17
18
|
|
18
|
-
class
|
19
|
-
"""
|
19
|
+
class S3PresignedUrlUpload(NCAApiBaseClass):
|
20
|
+
"""S3PresignedUrlUpload"""
|
20
21
|
|
21
|
-
def __init__(self,
|
22
|
-
|
23
|
-
self.jwt = jwt
|
22
|
+
def __init__(self, host: str) -> None:
|
23
|
+
super().__init__(host)
|
24
24
|
|
25
|
-
def upload_file(
|
25
|
+
def upload_file(
|
26
|
+
self,
|
27
|
+
input_file: str,
|
28
|
+
) -> Dict[str, Any]:
|
26
29
|
"""
|
27
30
|
Uploads a file to your Aplos Cloud Account in AWS
|
28
31
|
|
@@ -34,15 +37,17 @@ class S3PresignedUpload:
|
|
34
37
|
"""
|
35
38
|
|
36
39
|
# get the presigned url for uploading
|
37
|
-
paylod:
|
38
|
-
input_file=input_file
|
40
|
+
paylod: S3PresignedUrlPayload = self.__get_presigned_upload_info(
|
41
|
+
input_file=input_file, jwt=self.authenticator.cognito.jwt
|
39
42
|
)
|
40
43
|
# upload the files
|
41
44
|
upload_response = self.__upload_file_to_s3(paylod, input_file=input_file)
|
42
45
|
|
43
46
|
return upload_response
|
44
47
|
|
45
|
-
def __get_presigned_upload_info(
|
48
|
+
def __get_presigned_upload_info(
|
49
|
+
self, input_file: str, jwt: str
|
50
|
+
) -> S3PresignedUrlPayload:
|
46
51
|
"""
|
47
52
|
Performs all the necessary steps for creating a presigned url to upload a file to S3.
|
48
53
|
We're using AWS S3 presigned urls for security as well as allowing for very large files if required.
|
@@ -50,11 +55,11 @@ class S3PresignedUpload:
|
|
50
55
|
input_file (str): the path to the input (analysis) file
|
51
56
|
|
52
57
|
Returns:
|
53
|
-
|
58
|
+
S3PresignedUrlPayload: instance of S3PresignedUrlPayload
|
54
59
|
"""
|
55
60
|
|
56
|
-
url =
|
57
|
-
headers = HttpUtilities.get_headers(
|
61
|
+
url = self.endpoints.files
|
62
|
+
headers = HttpUtilities.get_headers(jwt)
|
58
63
|
|
59
64
|
body = {"file_name": input_file, "method_type": "post"}
|
60
65
|
response = requests.post(
|
@@ -64,29 +69,29 @@ class S3PresignedUpload:
|
|
64
69
|
if response.status_code == 403:
|
65
70
|
raise PermissionError(
|
66
71
|
"Failed to get a presigned url. "
|
67
|
-
f"Status Code: {response.status_code
|
72
|
+
f"Status Code: {response.status_code}"
|
68
73
|
f"Reason: {response.reason} "
|
69
74
|
f"403 Errors can also occur if you have an invalid path."
|
70
75
|
)
|
71
76
|
elif response.status_code != 200:
|
72
77
|
raise RuntimeError(
|
73
78
|
"Failed to get a presigned url. "
|
74
|
-
f"Status Code: {response.status_code
|
79
|
+
f"Status Code: {response.status_code}"
|
75
80
|
f"Reason: {response.reason}"
|
76
81
|
)
|
77
82
|
result = response.json()
|
78
83
|
|
79
|
-
payload:
|
84
|
+
payload: S3PresignedUrlPayload = S3PresignedUrlPayload(result)
|
80
85
|
|
81
86
|
return payload
|
82
87
|
|
83
88
|
def __upload_file_to_s3(
|
84
|
-
self, payload:
|
89
|
+
self, payload: S3PresignedUrlPayload, input_file: str
|
85
90
|
) -> Dict[str, Any]:
|
86
91
|
"""
|
87
92
|
Peforms the actual uploading via a presigned url for S3 bucket storage
|
88
93
|
Args:
|
89
|
-
payload (
|
94
|
+
payload (S3PresignedUrlPayload): instance of S3PresignedUrlPayload with all the data needed
|
90
95
|
input_file (str): the path to a file being uploaded
|
91
96
|
|
92
97
|
Raises:
|
@@ -104,8 +109,9 @@ class S3PresignedUpload:
|
|
104
109
|
with open(input_file, "rb") as file:
|
105
110
|
files = {"file": (input_file, file)}
|
106
111
|
# upload to s3 with the presigned url
|
112
|
+
# authentication is built into the url
|
107
113
|
upload_response = requests.post(
|
108
|
-
str(payload.url), data=payload.form_data, files=files, timeout=
|
114
|
+
str(payload.url), data=payload.form_data, files=files, timeout=60
|
109
115
|
)
|
110
116
|
|
111
117
|
# Check the response: 204 is a success in this case
|
@@ -1,5 +1,5 @@
|
|
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
|
"""
|
@@ -11,61 +11,27 @@ import zipfile
|
|
11
11
|
from datetime import datetime, timedelta
|
12
12
|
from pathlib import Path
|
13
13
|
from typing import Any, Dict
|
14
|
-
|
14
|
+
|
15
15
|
import requests
|
16
|
+
from aws_lambda_powertools import Logger
|
16
17
|
|
17
|
-
from aplos_nca_saas_sdk.
|
18
|
-
from aplos_nca_saas_sdk.
|
19
|
-
|
18
|
+
from aplos_nca_saas_sdk.nca_resources._api_base import NCAApiBaseClass
|
19
|
+
from aplos_nca_saas_sdk.nca_resources.aws_s3_presigned_upload import (
|
20
|
+
S3PresignedUrlUpload,
|
20
21
|
)
|
21
|
-
from aplos_nca_saas_sdk.utilities.commandline_args import CommandlineArgs
|
22
|
-
from aplos_nca_saas_sdk.utilities.http_utility import HttpUtilities, Routes
|
23
22
|
from aplos_nca_saas_sdk.utilities.environment_vars import EnvironmentVars
|
23
|
+
from aplos_nca_saas_sdk.utilities.http_utility import HttpUtilities
|
24
24
|
|
25
25
|
logger = Logger()
|
26
26
|
|
27
27
|
|
28
|
-
class NCAAnalysis:
|
29
|
-
"""NCA Analysis API
|
28
|
+
class NCAAnalysis(NCAApiBaseClass):
|
29
|
+
"""NCA Analysis API"""
|
30
30
|
|
31
|
-
def __init__(self,
|
32
|
-
|
31
|
+
def __init__(self, host: str) -> None:
|
32
|
+
super().__init__(host)
|
33
33
|
|
34
|
-
if not api_domain:
|
35
|
-
raise ValueError("Missing Aplos Api Domain")
|
36
|
-
|
37
|
-
self.__api_domain: str = api_domain
|
38
34
|
self.verbose: bool = False
|
39
|
-
self.__cognito: CognitoAuthentication | None = None
|
40
|
-
|
41
|
-
@property
|
42
|
-
def cognito(self) -> CognitoAuthentication:
|
43
|
-
"""Gets the cognito authentication object"""
|
44
|
-
|
45
|
-
if not self.__api_domain:
|
46
|
-
raise RuntimeError(
|
47
|
-
"Missing Aplos Api Domain. Set the internal property of __api_domain first."
|
48
|
-
"This is required to make an authentication connection"
|
49
|
-
)
|
50
|
-
|
51
|
-
if self.__cognito is None:
|
52
|
-
self.__cognito = CognitoAuthentication(
|
53
|
-
client_id=None, region=None, aplos_domain=self.__api_domain
|
54
|
-
)
|
55
|
-
|
56
|
-
return self.__cognito
|
57
|
-
|
58
|
-
@property
|
59
|
-
def api_root(self) -> str:
|
60
|
-
"""Gets the base url"""
|
61
|
-
if self.__api_domain is None:
|
62
|
-
raise RuntimeError("Missing Aplos Api Domain")
|
63
|
-
|
64
|
-
url = HttpUtilities.build_url(
|
65
|
-
self.__api_domain, self.cognito.tenant_id, self.cognito.user_id
|
66
|
-
)
|
67
|
-
|
68
|
-
return url
|
69
35
|
|
70
36
|
def execute(
|
71
37
|
self,
|
@@ -100,17 +66,13 @@ class NCAAnalysis:
|
|
100
66
|
Dict[str, Any]: The execution response. If you wait for the completion
|
101
67
|
"""
|
102
68
|
|
103
|
-
self.log(f"\tLogging into {self.
|
69
|
+
self.log(f"\tLogging into {self.host}.")
|
104
70
|
|
105
|
-
|
106
|
-
raise ValueError("Missing username. Please provide a valid username.")
|
107
|
-
if not password:
|
108
|
-
raise ValueError("Missing password. Please provide a valid password.")
|
109
|
-
|
110
|
-
self.__jwt = self.cognito.login(username=username, password=password)
|
71
|
+
self.authenticator.authenticate(username=username, password=password)
|
111
72
|
|
112
73
|
self.log("\tUploading the analysis file.")
|
113
|
-
uploader:
|
74
|
+
uploader: S3PresignedUrlUpload = S3PresignedUrlUpload(str(self.host))
|
75
|
+
uploader.authenticator = self.authenticator
|
114
76
|
upload_response: Dict[str, Any] = uploader.upload_file(input_file_path)
|
115
77
|
|
116
78
|
file_id: str = upload_response.get("file_id", "")
|
@@ -188,7 +150,7 @@ class NCAAnalysis:
|
|
188
150
|
raise ValueError(
|
189
151
|
"Missing config_data. Please provide a valid config_data."
|
190
152
|
)
|
191
|
-
headers = HttpUtilities.get_headers(self.
|
153
|
+
headers = HttpUtilities.get_headers(self.authenticator.cognito.jwt)
|
192
154
|
# to start a new execution we need the location of the file (s3 bucket and object key)
|
193
155
|
# you basic configuration
|
194
156
|
# optional meta data
|
@@ -198,9 +160,12 @@ class NCAAnalysis:
|
|
198
160
|
"configuration": config_data,
|
199
161
|
"meta_data": meta_data,
|
200
162
|
}
|
201
|
-
|
163
|
+
|
202
164
|
response: requests.Response = requests.post(
|
203
|
-
|
165
|
+
self.endpoints.executions,
|
166
|
+
headers=headers,
|
167
|
+
data=json.dumps(submission),
|
168
|
+
timeout=30,
|
204
169
|
)
|
205
170
|
json_response: dict = response.json()
|
206
171
|
|
@@ -234,9 +199,9 @@ class NCAAnalysis:
|
|
234
199
|
str | None: on success: a url for download, on failure: None
|
235
200
|
"""
|
236
201
|
|
237
|
-
url = f"{self.
|
202
|
+
url = f"{self.endpoints.execution(execution_id)}"
|
238
203
|
|
239
|
-
headers = HttpUtilities.get_headers(self.
|
204
|
+
headers = HttpUtilities.get_headers(self.authenticator.cognito.jwt)
|
240
205
|
current_time = datetime.now()
|
241
206
|
# Create a timedelta object representing 15 minutes
|
242
207
|
time_delta = timedelta(seconds=max_wait_in_seconds)
|
@@ -337,112 +302,3 @@ class NCAAnalysis:
|
|
337
302
|
|
338
303
|
if self.verbose:
|
339
304
|
print(message)
|
340
|
-
|
341
|
-
|
342
|
-
def main():
|
343
|
-
try:
|
344
|
-
print("Welcome to the NCA Engine Upload & Execution Demo")
|
345
|
-
args = CommandlineArgs()
|
346
|
-
files_path = os.path.join(Path(__file__).parent, "files")
|
347
|
-
|
348
|
-
args.analysis_file_default = os.path.join(files_path, "single_ev.csv")
|
349
|
-
args.config_file_default = os.path.join(
|
350
|
-
files_path, "configuration_single_ev.json"
|
351
|
-
)
|
352
|
-
args.metadata_file_default = os.path.join(files_path, "meta_data.json")
|
353
|
-
if not args.is_valid():
|
354
|
-
print("\n\n")
|
355
|
-
print("Missing some arguments.")
|
356
|
-
exit()
|
357
|
-
|
358
|
-
engine = NCAAnalysis(
|
359
|
-
api_domain=str(args.api_domain),
|
360
|
-
)
|
361
|
-
|
362
|
-
print("\tLoading analysis configurations")
|
363
|
-
print(f"\t\t{args.config_file}")
|
364
|
-
config_data: dict = read_json_file(str(args.config_file))
|
365
|
-
|
366
|
-
print("\tLoading analysis meta data")
|
367
|
-
print(f"\t\t{args.metadata_file}")
|
368
|
-
meta_data = optional_json_loads(read_text_file(str(args.metadata_file)))
|
369
|
-
|
370
|
-
engine.execute(
|
371
|
-
username=str(args.username),
|
372
|
-
password=str(args.password),
|
373
|
-
input_file_path=str(args.analysis_file),
|
374
|
-
config_data=config_data,
|
375
|
-
meta_data=meta_data,
|
376
|
-
output_directory=str(args.output_directory),
|
377
|
-
)
|
378
|
-
print("Thank you for using the NCA Engine Upload and Execution Demo")
|
379
|
-
except Exception as e: # pylint: disable=w0718
|
380
|
-
print("An error occured ... exiting with an error")
|
381
|
-
print(str(e))
|
382
|
-
|
383
|
-
|
384
|
-
def optional_json_loads(data: str | dict) -> str | dict:
|
385
|
-
"""
|
386
|
-
Attempts to load the data as json, fails gracefull and retuns the data is if it fails
|
387
|
-
Args:
|
388
|
-
data (str): data as string
|
389
|
-
|
390
|
-
Returns:
|
391
|
-
str | dict: either the data as is or a converted dictionary/json object
|
392
|
-
"""
|
393
|
-
if isinstance(data, dict):
|
394
|
-
return data
|
395
|
-
|
396
|
-
try:
|
397
|
-
data = json.loads(str(data))
|
398
|
-
finally:
|
399
|
-
pass
|
400
|
-
return data
|
401
|
-
|
402
|
-
|
403
|
-
def read_json_file(file_path: str) -> dict:
|
404
|
-
"""
|
405
|
-
Reads a file and returns the json
|
406
|
-
Args:
|
407
|
-
file_path (str): _description_
|
408
|
-
|
409
|
-
Raises:
|
410
|
-
FileNotFoundError: _description_
|
411
|
-
|
412
|
-
Returns:
|
413
|
-
dict: _description_
|
414
|
-
"""
|
415
|
-
if not os.path.exists(file_path):
|
416
|
-
raise FileNotFoundError(f"File Not Found: {file_path}")
|
417
|
-
|
418
|
-
data = None
|
419
|
-
with open(file_path, mode="r", encoding="utf8") as file:
|
420
|
-
data = json.load(file)
|
421
|
-
|
422
|
-
return data
|
423
|
-
|
424
|
-
|
425
|
-
def read_text_file(file_path: str) -> str:
|
426
|
-
"""
|
427
|
-
Read files contents
|
428
|
-
Args:
|
429
|
-
file_path (str): path to the file
|
430
|
-
|
431
|
-
Raises:
|
432
|
-
FileNotFoundError: if the file is not found
|
433
|
-
|
434
|
-
Returns:
|
435
|
-
str: the files data
|
436
|
-
"""
|
437
|
-
if not os.path.exists(file_path):
|
438
|
-
raise FileNotFoundError(f"File Not Found: {file_path}")
|
439
|
-
|
440
|
-
data = None
|
441
|
-
with open(file_path, mode="r", encoding="utf8") as file:
|
442
|
-
data = file.read()
|
443
|
-
|
444
|
-
return data
|
445
|
-
|
446
|
-
|
447
|
-
if __name__ == "__main__":
|
448
|
-
main()
|
@@ -1,5 +1,5 @@
|
|
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
|
"""
|
@@ -30,8 +30,8 @@ class NCAAppConfiguration:
|
|
30
30
|
|
31
31
|
"""
|
32
32
|
|
33
|
-
def __init__(self,
|
34
|
-
self.
|
33
|
+
def __init__(self, host: str):
|
34
|
+
self.__endpoints: NCAEndpoints = NCAEndpoints(host=host)
|
35
35
|
self.__response: requests.Response | None = None
|
36
36
|
|
37
37
|
def get(self) -> requests.Response:
|
@@ -40,7 +40,7 @@ class NCAAppConfiguration:
|
|
40
40
|
if self.__response is not None:
|
41
41
|
return self.__response
|
42
42
|
|
43
|
-
url = self.
|
43
|
+
url = self.__endpoints.app_configuration
|
44
44
|
self.__response = requests.get(url, timeout=30)
|
45
45
|
if self.__response.status_code != 200:
|
46
46
|
raise RuntimeError("App configuration url is not working.")
|
@@ -1,25 +1,25 @@
|
|
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 Optional
|
8
|
-
from aplos_nca_saas_sdk.
|
8
|
+
from aplos_nca_saas_sdk.nca_resources.aws_cognito import CognitoAuthentication
|
9
9
|
from aplos_nca_saas_sdk.nca_resources.nca_app_configuration import (
|
10
10
|
NCAAppConfiguration,
|
11
11
|
)
|
12
12
|
|
13
13
|
|
14
|
-
class
|
15
|
-
"""NCA
|
14
|
+
class NCAAuthenticator:
|
15
|
+
"""NCA Authenticator"""
|
16
16
|
|
17
17
|
def __init__(
|
18
18
|
self,
|
19
19
|
*,
|
20
20
|
cognito_client_id: Optional[str] = None,
|
21
21
|
cognito_region: Optional[str] = None,
|
22
|
-
|
22
|
+
host: Optional[str] = None,
|
23
23
|
) -> None:
|
24
24
|
"""
|
25
25
|
NCA SaaS Login
|
@@ -27,18 +27,16 @@ class NCALogin:
|
|
27
27
|
Args:
|
28
28
|
cognito_client_id (Optional[str], optional): Cognito Client Id. Defaults to None.
|
29
29
|
cognito_region (Optional[str], optional): Cognito Region. Defaults to None.
|
30
|
-
|
30
|
+
host (Optional[str], optional): Aplos NCA SaaS host. Defaults to None.
|
31
31
|
|
32
32
|
Requirements:
|
33
33
|
Either pass in the cognito_client_id and cognito_region.
|
34
|
-
or set the
|
34
|
+
or set the host to automatically get the client_id and region.
|
35
35
|
"""
|
36
|
-
|
37
|
-
self.access_token: Optional[str] = None
|
38
|
-
self.refresh_token: Optional[str] = None
|
36
|
+
|
39
37
|
self.__cognito_client_id = cognito_client_id
|
40
38
|
self.__region = cognito_region
|
41
|
-
self.
|
39
|
+
self.__host: Optional[str] = host
|
42
40
|
self.__cognito: Optional[CognitoAuthentication] = None
|
43
41
|
self.__config: Optional[NCAAppConfiguration] = None
|
44
42
|
|
@@ -53,19 +51,19 @@ class NCALogin:
|
|
53
51
|
self.__cognito = CognitoAuthentication(
|
54
52
|
client_id=self.__cognito_client_id,
|
55
53
|
region=self.__region,
|
56
|
-
aplos_domain=self.
|
54
|
+
aplos_domain=self.__host,
|
57
55
|
)
|
58
56
|
|
59
57
|
return self.__cognito
|
60
58
|
|
61
59
|
@property
|
62
|
-
def
|
60
|
+
def host(self) -> str | None:
|
63
61
|
"""
|
64
62
|
Domain
|
65
63
|
Returns:
|
66
|
-
str: the
|
64
|
+
str: the host
|
67
65
|
"""
|
68
|
-
return self.
|
66
|
+
return self.__host
|
69
67
|
|
70
68
|
@property
|
71
69
|
def config(self) -> NCAAppConfiguration:
|
@@ -75,13 +73,13 @@ class NCALogin:
|
|
75
73
|
NCAAppConfiguration: object to handle the NCA App Configuration
|
76
74
|
"""
|
77
75
|
if self.__config is None:
|
78
|
-
if self.
|
76
|
+
if self.__host is None:
|
79
77
|
raise RuntimeError(
|
80
78
|
"Failed to get Aplos Configuration. The Domain is not set."
|
81
79
|
)
|
82
80
|
|
83
81
|
self.__config = NCAAppConfiguration(
|
84
|
-
|
82
|
+
host=self.__host,
|
85
83
|
)
|
86
84
|
|
87
85
|
return self.__config
|
@@ -96,9 +94,14 @@ class NCALogin:
|
|
96
94
|
Args:
|
97
95
|
username (str): the username
|
98
96
|
password (str): the users password
|
99
|
-
|
97
|
+
Returns:
|
98
|
+
str: JWT (JSON Web Token)
|
100
99
|
"""
|
100
|
+
if not username:
|
101
|
+
raise ValueError("Missing username. Please provide a valid username.")
|
102
|
+
if not password:
|
103
|
+
raise ValueError("Missing password. Please provide a valid password.")
|
101
104
|
|
102
|
-
self.
|
105
|
+
self.cognito.login(username=username, password=password)
|
103
106
|
|
104
|
-
return self.jwt
|
107
|
+
return self.cognito.jwt
|