aplos-nca-saas-sdk 1.0.0__tar.gz

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.
Files changed (49) hide show
  1. aplos_nca_saas_sdk-1.0.0/.gitignore +13 -0
  2. aplos_nca_saas_sdk-1.0.0/.pypirc +7 -0
  3. aplos_nca_saas_sdk-1.0.0/.vscode/launch.json +57 -0
  4. aplos_nca_saas_sdk-1.0.0/.vscode/settings.json +35 -0
  5. aplos_nca_saas_sdk-1.0.0/PKG-INFO +195 -0
  6. aplos_nca_saas_sdk-1.0.0/README.md +179 -0
  7. aplos_nca_saas_sdk-1.0.0/devops/code_artifacts/check_and_setup.py +44 -0
  8. aplos_nca_saas_sdk-1.0.0/devops/code_artifacts/environment_vars.py +36 -0
  9. aplos_nca_saas_sdk-1.0.0/devops/code_artifacts/local_test_support.py +68 -0
  10. aplos_nca_saas_sdk-1.0.0/devops/code_artifacts/main.py +224 -0
  11. aplos_nca_saas_sdk-1.0.0/devops/code_artifacts/pip_code_artifact_setup.py +66 -0
  12. aplos_nca_saas_sdk-1.0.0/devops/pypi/build.py +128 -0
  13. aplos_nca_saas_sdk-1.0.0/devops/pypi/readme.md +23 -0
  14. aplos_nca_saas_sdk-1.0.0/devops/requirements.txt +4 -0
  15. aplos_nca_saas_sdk-1.0.0/docs/images/API_Configuration_blur.png +0 -0
  16. aplos_nca_saas_sdk-1.0.0/docs/images/aplos-nca-commandline-cropped.png +0 -0
  17. aplos_nca_saas_sdk-1.0.0/docs/images/aplos-nca-commandline.png +0 -0
  18. aplos_nca_saas_sdk-1.0.0/mypy.ini +15 -0
  19. aplos_nca_saas_sdk-1.0.0/mypy_checks.py +25 -0
  20. aplos_nca_saas_sdk-1.0.0/pyproject.toml +30 -0
  21. aplos_nca_saas_sdk-1.0.0/readme.md +179 -0
  22. aplos_nca_saas_sdk-1.0.0/requirements.txt +5 -0
  23. aplos_nca_saas_sdk-1.0.0/run-checks.sh +4 -0
  24. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/__init__.py +0 -0
  25. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/aws_resources/aws_cognito.py +188 -0
  26. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/aws_resources/aws_s3_presigned_payload.py +49 -0
  27. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/aws_resources/aws_s3_presigned_upload.py +116 -0
  28. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/files/analysis_files/single_ev/configuration_single_ev.json +51 -0
  29. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/files/analysis_files/single_ev/meta_data.json +17 -0
  30. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/files/analysis_files/single_ev/single_ev.csv +121 -0
  31. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/integration_test_base.py +34 -0
  32. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/integration_test_factory.py +62 -0
  33. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/integration_test_suite.py +84 -0
  34. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/main.py +28 -0
  35. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/readme.md +18 -0
  36. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/tests/app_configuration_test.py +30 -0
  37. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/tests/app_execution_test.py +5 -0
  38. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/tests/app_login_test.py +32 -0
  39. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/integration_testing/tests/app_validation_test.py +5 -0
  40. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/nca_resources/nca_app_configuration.py +69 -0
  41. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/nca_resources/nca_endpoints.py +54 -0
  42. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/nca_resources/nca_executions.py +378 -0
  43. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/nca_resources/nca_login.py +104 -0
  44. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/utilities/commandline_args.py +332 -0
  45. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/utilities/environment_services.py +81 -0
  46. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/utilities/environment_vars.py +23 -0
  47. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/utilities/http_utility.py +30 -0
  48. aplos_nca_saas_sdk-1.0.0/src/aplos_nca_saas_sdk/version.py +4 -0
  49. aplos_nca_saas_sdk-1.0.0/tests/__init__.py +0 -0
@@ -0,0 +1,13 @@
1
+
2
+ .venv/
3
+ dist/
4
+ .DS_Store
5
+ .env
6
+ *.pyc
7
+
8
+ .coverage
9
+
10
+ .imports/
11
+ # don't track environment files
12
+ .env
13
+ .env.*
@@ -0,0 +1,7 @@
1
+ [distutils]
2
+ index-servers =
3
+ codeartifact
4
+
5
+ [codeartifact]
6
+ repository = https://aplos-nca-974817967438.d.codeartifact.us-east-1.amazonaws.com/pypi/python/
7
+ username = aws
@@ -0,0 +1,57 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Python Debugger: Current File",
9
+ "type": "debugpy",
10
+ "request": "launch",
11
+ "program": "${file}",
12
+ "console": "integratedTerminal",
13
+ "env": {
14
+
15
+ "ENVRIONMENT": "dev",
16
+ "DEBUG_MODE": "True",
17
+ "PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/src:${workspaceFolder}/devops:${workspaceFolder}:${workspaceFolder}/tests"
18
+ }
19
+ },
20
+ {
21
+ "name": "Build & Deploy To PyPi",
22
+ "type": "debugpy",
23
+ "request": "launch",
24
+ "program": "${workspaceFolder}/devops/pypi/build.py",
25
+ "console": "integratedTerminal"
26
+ },
27
+
28
+ {
29
+ "name": "Build & Deploy To Code Artifacts",
30
+ "type": "debugpy",
31
+ "request": "launch",
32
+ "program": "${workspaceFolder}/devops/code_artifacts/main.py",
33
+ "console": "integratedTerminal",
34
+ "env": {
35
+
36
+ "ENVRIONMENT": "dev",
37
+ "DEBUG_MODE": "True",
38
+ "PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/src:${workspaceFolder}/devops:"
39
+ }
40
+ },
41
+ {
42
+ "name": "Run Integration Tests - dev",
43
+ "type": "debugpy",
44
+ "request": "launch",
45
+ "program": "${workspaceFolder}/src/aplos_nca_saas_sdk/integration_testing/main.py",
46
+ "console": "integratedTerminal",
47
+ "env": {
48
+
49
+ "ENVRIONMENT": "dev",
50
+ "ENV_FILE": ".env.development",
51
+ "DEBUG_MODE": "True",
52
+ "PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/src:${workspaceFolder}/devops:${workspaceFolder}/devops"
53
+ }
54
+ },
55
+
56
+ ]
57
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+
3
+ "python.testing.pytestEnabled": false,
4
+ "python.testing.unittestEnabled": true,
5
+ "python.testing.unittestArgs": [
6
+ "-v",
7
+ "-s",
8
+ "./tests",
9
+ "-p",
10
+ "*_test.py"
11
+ ],
12
+ "python.testing.cwd": "${workspaceFolder}",
13
+ "python.analysis.extraPaths": [
14
+ "${workspaceFolder}/src",
15
+ "${workspaceFolder}/src/aplos_nca_saas_sdk",
16
+ "${workspaceFolder}/tests",
17
+ "${workspaceFolder}/devops",
18
+ "${workspaceFolder}/devops/cdk",
19
+
20
+ ],
21
+ "python.analysis.typeCheckingMode": "off",
22
+ "pylint.args": [
23
+ "--max-line-length=150"
24
+ ],
25
+ "[python]": {
26
+
27
+ "editor.formatOnSave": true,
28
+ // "editor.codeActionsOnSave": {
29
+ // "source.fixAll": "explicit",
30
+ // "source.organizeImports": "explicit"
31
+ // },
32
+ "editor.defaultFormatter": "charliermarsh.ruff",
33
+ },
34
+
35
+ }
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.3
2
+ Name: aplos_nca_saas_sdk
3
+ Version: 1.0.0
4
+ Summary: Aplos NCA SaaS SDK
5
+ Author-email: Eric Wilson <eric.wilson@aplosanalytics.com>
6
+ Classifier: License :: Other/Proprietary License
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Programming Language :: Python :: 3
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: aws-lambda-powertools==2.38.1
11
+ Requires-Dist: boto3==1.34.110
12
+ Requires-Dist: pyjwt==2.9.0
13
+ Requires-Dist: python-dotenv==1.0.1
14
+ Requires-Dist: requests==2.31.0
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Aplos NCA SaaS SDK for python
18
+
19
+ You can use 🐍 python to perform analysis with Aplos NCA using API calls via secure HTTPS requests. We have prepared sample scripts to illustrate how this analysis can be performed using python.
20
+
21
+ This was created as a reusable library which was wrapped with commandline parsing. You can use command line switches or simply run it and get prompted for the required input.
22
+
23
+ All the source code can be downloaded from our [docs repo](https://github.com/AplosAnalytics/docs.aplosanalytics.com/tree/main/docs/samples/python/aplos_nca).
24
+
25
+ >[!TIP] We use this for our demos
26
+ > We'll keep this maintained as we use it for our customer demos. So keep coming back for new features.
27
+
28
+
29
+ ## API Settings
30
+
31
+ > [!WARNING] A valid Aplos NCA Account is required.
32
+ > In order to run the executions and connect to our system, you will need a valid account with an active subscription.
33
+ >
34
+ > You'll need your username (email address and a password) a Cognito Client Id
35
+ > which allows the USER_PASSWORD_AUTH flow, and your API URL.
36
+ >
37
+ > The Client Id (aka Cognito Client Key) and API URL can be found in your user account.
38
+ > Your username is your email address and your password would have been provided to you during your
39
+ > onboarding or with a "forgot password" request and reset.
40
+
41
+ ### Access your settings from the UI
42
+ ![API Configuration](/docs/images/API_Configuration_blur.png)
43
+
44
+
45
+ ## Python Environment
46
+ While it's not required, we suggest setting up a virtual environment with your favorite tool.
47
+
48
+ Example. From the project root issue the following command (in mac, linux or windows shell subsystem)
49
+ ```shell
50
+ python -m venv .venv
51
+ source ./.venv/bin/activate
52
+ ```
53
+
54
+ Install the required packages
55
+ ```shell
56
+ # (from the project root)
57
+ pip install -r ./docs/samples/python/aplos_nca/requirements.txt
58
+
59
+ # or if you are in the aplos_nca directory
60
+ pip install -r ./requirements.txt
61
+ ```
62
+
63
+
64
+ ## Required Files for execution (analysis submission)
65
+ To submit something for an analysis, you will need 2 required files and one optional file.
66
+ - Input File (analysis file)
67
+ - Configuration File (configurations on how to run the analysis)
68
+ - Meta Data (optional)
69
+
70
+ Technically only the analysis file is submitted as a file.
71
+
72
+ The other two (configuration and metadata) are submitted as JSON/dictionary objects. However to make things easier for this demo they are stored as files, then read in at runtime and submitted in their normal dictionary form.
73
+
74
+ The files are located `./files` directory of this demo project (`./samples/python/aplos_nca`).
75
+
76
+
77
+ ## Outputs
78
+ Currently, we are outputting the files in a hidden directory (`.output`) which is also excluded from the git commits. This can easily be overridden to your choosing.
79
+
80
+ Located in `./.output`
81
+
82
+
83
+ ## Run the Execution
84
+
85
+ In order to run the execution you need to either:
86
+ - Add environment variables for the required parameter see [Environment Vars](/docs/samples/python-overview.html#environment-vars) later in this document
87
+ - Use the command switch arguments
88
+ - Or simply input the values as you are prompted.
89
+
90
+ > [!TIP] Tip! Use environment vars and override when needed.
91
+ > You can set the environment variables, but still override them during the prompts
92
+
93
+ From the project you you can
94
+ `python .<project-path>/main.py`
95
+
96
+ or navigate to the folder
97
+ `python ./main.py`
98
+
99
+ ## Arguments
100
+
101
+ |short|long|description|
102
+ |---|---|---|
103
+ |-s|--skip|Skip prompts if required values have defaults|
104
+ |-u|--username|Your login username|
105
+ |-p|--password|Your login password|
106
+ |-f|--analyis-file|Path to the analysis file|
107
+ |-c|--config-file|Path to the configuration file|
108
+ |-m|--metadata-file|Path to the metadata file|
109
+ |-a|--api-url|The api url|
110
+ |-i|--client-id|The client id to cognito|
111
+ |-o|-output-directory|The full path to an output directory. If one isn't provided it will default to a local (.aplos-nca-output) directory one level up from the execution directory. |
112
+ |-e|--environment-file|The full path to an environment file (.env file).|
113
+
114
+ ### The `-s` argument (skipping prompts when defaults are available)
115
+ If you have default values specified in code or a `.env` file, specify the `-s` will skip prompting for any parameters that are required but have an associated matching default value.
116
+
117
+
118
+ ### Scripting
119
+ You can create scripts to launch several analyses by providing the runtime arguments. WARNING: you should be careful when exposing your username and password to others.
120
+ For automation, it's best to store them as a secret and retrieve the secret at runtime.
121
+
122
+
123
+ ## Examples:
124
+ Let's assume you have your username, password, and API settings in environment vars. You can use the `-s` to skip those prompts and supply the config, meta, and analysis for different runs.
125
+
126
+ > [!TIP]
127
+ > If you have certain values present the command line tool will prompt to see if you want to use the defaults or override them.
128
+ > If you want to skip the prompt, use `-s` as an argument. This will skip the prompt for any value already set.
129
+
130
+ ### Sample execution
131
+
132
+ If your username, password, client key and API URL are already set, then the only thing you need to do on each run is supply the configuration and the analysis file. The meta-data file is optional. Issuing the `-s` will skip all the extra prompts.
133
+
134
+ ```shell
135
+ # single line execution example
136
+
137
+ python main.py -s -c <config-file> -f <analysis-file> -m <meta-file>
138
+
139
+ ```
140
+
141
+ ### Same example, on multiple lines and with example files
142
+
143
+ ```shell
144
+
145
+ # break into multiple lines for easier readability
146
+ # NOTE: a copy paste of this from code samples doesn't always work right
147
+
148
+ python ./main.py \
149
+ -s \
150
+ -f ./files/single_ev.csv \
151
+ -c ./files/configuration_single_ev.json \
152
+ -m ./files/meta_data.json
153
+
154
+ ```
155
+
156
+ ## Environment Vars
157
+
158
+ To save time and typing you can use environment variables to "pre-load" your execution and then any "unknown" value will be asked by the command line utility.
159
+
160
+ The following environment variables are required for execution. We're using environment vars so that nothing gets accidentally saved into git.
161
+
162
+ If executing the functions via the command line, you need to create the environment variables so that they are available at runtime, like the following.
163
+
164
+ Mac & Linux
165
+ ```shell
166
+ export APLOS_API_DOMAIN="<api-gateway-url>"
167
+ export COGNITO_CLIENT_ID="<client-id>"
168
+ export COGNITO_USER_NAME="<email-address>"
169
+ export COGNITO_PASSWORD="<password>"
170
+ export COGNITO_REGION="<region>"
171
+ ```
172
+ Windows
173
+ ```shell
174
+ SET APLOS_API_DOMAIN="<api-gateway-url>"
175
+ SET COGNITO_CLIENT_ID="<client-id>"
176
+ SET COGNITO_USER_NAME="<email-address>"
177
+ SET COGNITO_PASSWORD="<password>"
178
+ SET COGNITO_REGION="<region>"
179
+ ```
180
+
181
+ > [!TIP]
182
+ > You can also create a `.env` file locally and enter the environment vars there.
183
+
184
+ ```shell
185
+ APLOS_API_DOMAIN="<api-gateway-url>"
186
+ COGNITO_CLIENT_ID="<client-id>"
187
+ COGNITO_USER_NAME="<email-address>"
188
+ COGNITO_PASSWORD="<password>"
189
+ COGNITO_REGION="<region>"
190
+ ```
191
+
192
+ ## The Command Line in Action
193
+ In this example, I have all my settings preloaded in environment vars and I just hit enter several times to accept the defaults.
194
+
195
+ ![Commandline App](/docs/images/aplos-nca-commandline-cropped.png)
@@ -0,0 +1,179 @@
1
+ # Aplos NCA SaaS SDK for python
2
+
3
+ You can use 🐍 python to perform analysis with Aplos NCA using API calls via secure HTTPS requests. We have prepared sample scripts to illustrate how this analysis can be performed using python.
4
+
5
+ This was created as a reusable library which was wrapped with commandline parsing. You can use command line switches or simply run it and get prompted for the required input.
6
+
7
+ All the source code can be downloaded from our [docs repo](https://github.com/AplosAnalytics/docs.aplosanalytics.com/tree/main/docs/samples/python/aplos_nca).
8
+
9
+ >[!TIP] We use this for our demos
10
+ > We'll keep this maintained as we use it for our customer demos. So keep coming back for new features.
11
+
12
+
13
+ ## API Settings
14
+
15
+ > [!WARNING] A valid Aplos NCA Account is required.
16
+ > In order to run the executions and connect to our system, you will need a valid account with an active subscription.
17
+ >
18
+ > You'll need your username (email address and a password) a Cognito Client Id
19
+ > which allows the USER_PASSWORD_AUTH flow, and your API URL.
20
+ >
21
+ > The Client Id (aka Cognito Client Key) and API URL can be found in your user account.
22
+ > Your username is your email address and your password would have been provided to you during your
23
+ > onboarding or with a "forgot password" request and reset.
24
+
25
+ ### Access your settings from the UI
26
+ ![API Configuration](/docs/images/API_Configuration_blur.png)
27
+
28
+
29
+ ## Python Environment
30
+ While it's not required, we suggest setting up a virtual environment with your favorite tool.
31
+
32
+ Example. From the project root issue the following command (in mac, linux or windows shell subsystem)
33
+ ```shell
34
+ python -m venv .venv
35
+ source ./.venv/bin/activate
36
+ ```
37
+
38
+ Install the required packages
39
+ ```shell
40
+ # (from the project root)
41
+ pip install -r ./docs/samples/python/aplos_nca/requirements.txt
42
+
43
+ # or if you are in the aplos_nca directory
44
+ pip install -r ./requirements.txt
45
+ ```
46
+
47
+
48
+ ## Required Files for execution (analysis submission)
49
+ To submit something for an analysis, you will need 2 required files and one optional file.
50
+ - Input File (analysis file)
51
+ - Configuration File (configurations on how to run the analysis)
52
+ - Meta Data (optional)
53
+
54
+ Technically only the analysis file is submitted as a file.
55
+
56
+ The other two (configuration and metadata) are submitted as JSON/dictionary objects. However to make things easier for this demo they are stored as files, then read in at runtime and submitted in their normal dictionary form.
57
+
58
+ The files are located `./files` directory of this demo project (`./samples/python/aplos_nca`).
59
+
60
+
61
+ ## Outputs
62
+ Currently, we are outputting the files in a hidden directory (`.output`) which is also excluded from the git commits. This can easily be overridden to your choosing.
63
+
64
+ Located in `./.output`
65
+
66
+
67
+ ## Run the Execution
68
+
69
+ In order to run the execution you need to either:
70
+ - Add environment variables for the required parameter see [Environment Vars](/docs/samples/python-overview.html#environment-vars) later in this document
71
+ - Use the command switch arguments
72
+ - Or simply input the values as you are prompted.
73
+
74
+ > [!TIP] Tip! Use environment vars and override when needed.
75
+ > You can set the environment variables, but still override them during the prompts
76
+
77
+ From the project you you can
78
+ `python .<project-path>/main.py`
79
+
80
+ or navigate to the folder
81
+ `python ./main.py`
82
+
83
+ ## Arguments
84
+
85
+ |short|long|description|
86
+ |---|---|---|
87
+ |-s|--skip|Skip prompts if required values have defaults|
88
+ |-u|--username|Your login username|
89
+ |-p|--password|Your login password|
90
+ |-f|--analyis-file|Path to the analysis file|
91
+ |-c|--config-file|Path to the configuration file|
92
+ |-m|--metadata-file|Path to the metadata file|
93
+ |-a|--api-url|The api url|
94
+ |-i|--client-id|The client id to cognito|
95
+ |-o|-output-directory|The full path to an output directory. If one isn't provided it will default to a local (.aplos-nca-output) directory one level up from the execution directory. |
96
+ |-e|--environment-file|The full path to an environment file (.env file).|
97
+
98
+ ### The `-s` argument (skipping prompts when defaults are available)
99
+ If you have default values specified in code or a `.env` file, specify the `-s` will skip prompting for any parameters that are required but have an associated matching default value.
100
+
101
+
102
+ ### Scripting
103
+ You can create scripts to launch several analyses by providing the runtime arguments. WARNING: you should be careful when exposing your username and password to others.
104
+ For automation, it's best to store them as a secret and retrieve the secret at runtime.
105
+
106
+
107
+ ## Examples:
108
+ Let's assume you have your username, password, and API settings in environment vars. You can use the `-s` to skip those prompts and supply the config, meta, and analysis for different runs.
109
+
110
+ > [!TIP]
111
+ > If you have certain values present the command line tool will prompt to see if you want to use the defaults or override them.
112
+ > If you want to skip the prompt, use `-s` as an argument. This will skip the prompt for any value already set.
113
+
114
+ ### Sample execution
115
+
116
+ If your username, password, client key and API URL are already set, then the only thing you need to do on each run is supply the configuration and the analysis file. The meta-data file is optional. Issuing the `-s` will skip all the extra prompts.
117
+
118
+ ```shell
119
+ # single line execution example
120
+
121
+ python main.py -s -c <config-file> -f <analysis-file> -m <meta-file>
122
+
123
+ ```
124
+
125
+ ### Same example, on multiple lines and with example files
126
+
127
+ ```shell
128
+
129
+ # break into multiple lines for easier readability
130
+ # NOTE: a copy paste of this from code samples doesn't always work right
131
+
132
+ python ./main.py \
133
+ -s \
134
+ -f ./files/single_ev.csv \
135
+ -c ./files/configuration_single_ev.json \
136
+ -m ./files/meta_data.json
137
+
138
+ ```
139
+
140
+ ## Environment Vars
141
+
142
+ To save time and typing you can use environment variables to "pre-load" your execution and then any "unknown" value will be asked by the command line utility.
143
+
144
+ The following environment variables are required for execution. We're using environment vars so that nothing gets accidentally saved into git.
145
+
146
+ If executing the functions via the command line, you need to create the environment variables so that they are available at runtime, like the following.
147
+
148
+ Mac & Linux
149
+ ```shell
150
+ export APLOS_API_DOMAIN="<api-gateway-url>"
151
+ export COGNITO_CLIENT_ID="<client-id>"
152
+ export COGNITO_USER_NAME="<email-address>"
153
+ export COGNITO_PASSWORD="<password>"
154
+ export COGNITO_REGION="<region>"
155
+ ```
156
+ Windows
157
+ ```shell
158
+ SET APLOS_API_DOMAIN="<api-gateway-url>"
159
+ SET COGNITO_CLIENT_ID="<client-id>"
160
+ SET COGNITO_USER_NAME="<email-address>"
161
+ SET COGNITO_PASSWORD="<password>"
162
+ SET COGNITO_REGION="<region>"
163
+ ```
164
+
165
+ > [!TIP]
166
+ > You can also create a `.env` file locally and enter the environment vars there.
167
+
168
+ ```shell
169
+ APLOS_API_DOMAIN="<api-gateway-url>"
170
+ COGNITO_CLIENT_ID="<client-id>"
171
+ COGNITO_USER_NAME="<email-address>"
172
+ COGNITO_PASSWORD="<password>"
173
+ COGNITO_REGION="<region>"
174
+ ```
175
+
176
+ ## The Command Line in Action
177
+ In this example, I have all my settings preloaded in environment vars and I just hit enter several times to accept the defaults.
178
+
179
+ ![Commandline App](/docs/images/aplos-nca-commandline-cropped.png)
@@ -0,0 +1,44 @@
1
+ import subprocess
2
+ import sys
3
+ import os
4
+ from aws_lambda_powertools import Logger
5
+ from devops.code_artifacts.environment_vars import envrionment_vars
6
+
7
+ logger = Logger()
8
+
9
+
10
+ def is_logged_in():
11
+ """Check to see if i'm logged in"""
12
+ try:
13
+ commands = ["aws", "codeartifact", "list-repositories"]
14
+ profile = envrionment_vars.code_artifact_repository_profile
15
+ if profile:
16
+ commands.append("--profile")
17
+ commands.append(profile)
18
+ result = subprocess.run(
19
+ commands,
20
+ stdout=subprocess.PIPE,
21
+ stderr=subprocess.PIPE,
22
+ text=True,
23
+ check=True,
24
+ )
25
+ return result.returncode == 0
26
+ except Exception as e: # pylint: disable=w0718
27
+ logger.exception(f"Error checking login status: {e}")
28
+ return False
29
+
30
+
31
+ def run_setup():
32
+ """Run the setup"""
33
+ try:
34
+ subprocess.check_call([sys.executable, "./devops/pip_code_artifact_setup.py"])
35
+ except subprocess.CalledProcessError as e:
36
+ logger.exception(f"Setup script failed: {e}")
37
+ sys.exit(1)
38
+
39
+
40
+ if not is_logged_in():
41
+ logger.info("Not logged in to CodeArtifact. Running setup script...")
42
+ run_setup()
43
+ else:
44
+ logger.info("Already logged in to CodeArtifact.")
@@ -0,0 +1,36 @@
1
+ import os
2
+
3
+
4
+ class EnvironmentVars:
5
+ """Environment variables"""
6
+
7
+ def __init__(self):
8
+ pass
9
+
10
+ @property
11
+ def code_artifact_account_number(self):
12
+ """Gets thd code artifacti account number"""
13
+ return os.getenv("CODEARTIFACT_AWS_ACCCOUNT_NUMBER") # "974817967438"
14
+
15
+ @property
16
+ def code_artifact_domain(self):
17
+ """Gets the code artifact domain"""
18
+ return os.getenv("CODEARTIFACT_DOMAIN") # "aplos-nca"
19
+
20
+ @property
21
+ def code_artifact_repository_name(self):
22
+ """Gets the code artifact repository name"""
23
+ return os.getenv("CODEARTIFACT_REPOSITORY_NAME") # "python"
24
+
25
+ @property
26
+ def code_artifact_repository_region(self):
27
+ """Gets the code artifact repository region"""
28
+ return os.getenv("CODEARTIFACT_REPOSITORY_REGION") # "us-east-1"
29
+
30
+ @property
31
+ def code_artifact_repository_profile(self):
32
+ """Gets the code artifact repository profile"""
33
+ return os.getenv("CODEARTIFACT_REPOSITORY_PROFILE")
34
+
35
+
36
+ envrionment_vars = EnvironmentVars()
@@ -0,0 +1,68 @@
1
+ import os
2
+ import json
3
+ from typing import Optional
4
+ from pathlib import Path
5
+ from dotenv import load_dotenv
6
+ from aws_lambda_powertools import Logger
7
+
8
+ logger = Logger()
9
+
10
+
11
+ class LocalTestingSupport:
12
+ def __init__(self) -> None:
13
+ pass
14
+
15
+ def load_local_environment(
16
+ self, *, path: Optional[str] = None, file_name: str = ".env.development"
17
+ ):
18
+ """Loads the local environment"""
19
+ environment_file: str | None = None
20
+ if path:
21
+ environment_file = os.path.join(path, file_name)
22
+ else:
23
+ environment_file = self.__find_env_file(file_name)
24
+
25
+ if environment_file is None:
26
+ raise RuntimeError(f"Failed to locate evnrionment file: {file_name}")
27
+
28
+ if os.path.exists(environment_file):
29
+ logger.debug(f"loading profile: {environment_file}")
30
+ load_dotenv(environment_file, override=True)
31
+
32
+ aws_profile = os.getenv("AWS_PROFILE")
33
+ logger.debug(f"aws_profile: {aws_profile}")
34
+ else:
35
+ raise RuntimeError(
36
+ f"Failed to locate evnrionment file: {file_name} at {environment_file}"
37
+ )
38
+
39
+ def __find_env_file(self, file_name: str) -> Optional[str]:
40
+ """Finds the environment file"""
41
+ for i in range(10):
42
+ path = str(Path(__file__).parents[i].absolute())
43
+ env_file = os.path.join(path, file_name)
44
+ if os.path.exists(env_file):
45
+ return env_file
46
+
47
+ return None
48
+
49
+ def load_event_file(self, full_path: str) -> dict:
50
+ """Loads an event file"""
51
+ if not os.path.exists(full_path):
52
+ raise RuntimeError(f"Failed to locate event file: {full_path}")
53
+
54
+ event: dict = {}
55
+ with open(full_path, mode="r", encoding="utf-8") as json_file:
56
+ event = json.load(json_file)
57
+
58
+ if "message" in event:
59
+ tmp = event.get("message")
60
+ if isinstance(tmp, dict):
61
+ event = tmp
62
+
63
+ if "event" in event:
64
+ tmp = event.get("event")
65
+ if isinstance(tmp, dict):
66
+ event = tmp
67
+
68
+ return event