environment_utils
Environment utils are used to manage environemnt dependencies in the application.
get_keys_yaml_file()
Retrieves the KEYS_FILE.yml and returns it as a dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The contents of the KEYS_FILE.yml as a dictionary. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the KEYS_FILE environment variable is not set or not equal to "KEYS_FILE.yml". |
Source code in physical_operations_utils/environment_utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
setup_environment()
Sets up the environment by determining the correct Azure Key Vault name based on
the ENVIRONMENT environment variable. Returns the current environment.
This function:
1. Retrieves the ENVIRONMENT variable from the system (defaults to "nonprod" if not set).
2. Based on the environment, assigns the appropriate Azure Key Vault name:
- "prod" → "axpotn-pro-appl-phys-kv"
- "nonprod" → "axpotn-non-appl-phys-kv"
3. Stores the Key Vault name in the KEY_VAULT_NAME environment variable.
4. Logs a warning with the selected environment and Key Vault name.
5. Returns the environment name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The selected environment ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid environment is set. |
Example
import os
from physical_operations_utils.EnvironmentUtils import setup_environment
os.environ["ENVIRONMENT"] = "prod"
env = setup_environment()
print(env) # Output: "prod"
print(os.environ["KEY_VAULT_NAME"]) # Output: "axpotn-pro-appl-phys-kv"
Source code in physical_operations_utils/environment_utils.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |