Skip to content

Commit e1fd8f4

Browse files
doc: document the Configuration system
1 parent 7a2f6b1 commit e1fd8f4

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

docs/tutorials/cosmotech-api.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,38 @@ Keycloak authentication requires these environment variables:
9898
!!! warning "API Client Lifecycle"
9999
Always close the API client when you're done using it to release resources. The best practice is to use a `try`/`finally` block to ensure the client is closed even if an error occurs.
100100

101+
## Configuration
102+
103+
The CoAL configuration system is based on a centralized data dictionary used to manage platform settings and behaviors dynamically. It allows scripts to run without requiring users to manually define connection or output specifics every single time. Data is primarily sourced from a TOML file loaded into a Kubernetes ConfigMap.
104+
105+
### Core mechanics
106+
107+
- The Configuration singleton: CoAL provides a `ENVIRONMENT_CONFIGURATION` singleton that users can import this into their scripts (`from cosmotech.coal.utils.configuration import ENVIRONMENT_CONFIGURATION as EC`) to access properties using dot-notation, such as `EC.cosmotech.runner_id`.
108+
109+
- Kubernetes (K8s) ConfigMap integration: To supply configuration inside a pod launched via a workflow, CoAL mounts a K8s ConfigMap containing the configuration file directly inside the container.
110+
111+
- Automatic path loading: CoAL automatically attempts to load the TOML file at the specific path `/mnt/coal/coal-config.toml`, making K8s ConfigMap auto-mounts seamless.
112+
113+
### Syntax
114+
115+
The configuration uses the TOML format to support specific features:
116+
117+
- **secrets**: Environment variables (e.g. credentials, `TWIN_CACHE_HOST`, or `IDP_BASE_URL`) that are loaded at startup. At import, they are initialized and then removed from the final configuration dictionary, so variables like `run_template_id` are accessed directly under `EC.cosmotech` rather than a "secrets" sub-dictionary. CosmoTech environment variables provided by the API are always loaded.
118+
119+
- **env.**: Fetches environment variables dynamically at runtime (e.g. `env.POSTGRES_USER_PASSWORD`), unlike "secrets" which are resolved statically at import.
120+
121+
- **Internal References ($)**: Allows configuration keys to reference other values in the same TOML file (e.g. `$postgres.host`).
122+
123+
- **[[outputs]]**: Uses TOML double-bracket list syntax to define a series of output destinations (such as PostgreSQL, S3, or Azure Blob Storage) utilized by the ChannelSplitter to direct simulation results.
124+
125+
- **Error handling**: CoAL handles of internal configuration references (like `$config.path`) with proper error reporting such as the `ReferenceKeyError` exception for missing configuration references.
126+
127+
### Configuration dictionary
128+
129+
```toml title="Configuration TOML file" linenums="1"
130+
--8<-- 'tutorial/cosmotech-api/coal-config.toml'
131+
```
132+
101133
## Working with Workspaces
102134

103135
Workspaces in the CosmoTech platform provide a way to organize and share files. `WorkspaceApi` offers methods for listing, downloading, and uploading files.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This an exemple of a coal-config.toml
2+
3+
# the double [[ section indicate a list. This allows to define multiple outputs
4+
# Each output define its type (currently supported: s3, az_storage, postgres)
5+
# For each output, the configuration defines value needed to interact with a storage. Mandatory value are mark with a [M]
6+
7+
[[outputs]]
8+
type = "s3" # indicate the output channel to use
9+
[outputs.conf.s3]
10+
endpoint_url = # [M] url of the s3 server
11+
access_key_id = # [M] the id used to connect (equivalent to a username)
12+
secret_access_key = # [M] the key to connect (equivalent to a password)
13+
bucket_name = # [M] name of the bucket. s3 bucket is a concept that define a ressource that holds data.
14+
bucket_prefix = # This is a prefix that will be add in front of each upload file
15+
# (this can allow to store in subfolder by adding a prefix ending with "/")
16+
outputs_type = # indicate the type of the data push. Can be .parquet or .csv (default: .csv)
17+
use_ssl = # indicate the use of ssl (default: True)
18+
ssl_cert_bundle = # in case of a s3 using custom SSL certification; here is where to put the path to the custom pem bundle.
19+
# (Can also be set to False to not verify SSL certificat)
20+
21+
[[outputs]]
22+
type = "az_storage" # indicate the output channel to use
23+
[outputs.conf.azure]
24+
account_name = # use to build azure storage URL
25+
tenant_id = # Azure tenant ID
26+
client_id = # Azure client ID
27+
client_secret = # Azure secret
28+
container_name = # Name of the container (equivalent to AWS Bucket name)
29+
outputs_type = # indicate the type of the data push. Can be .parquet or .csv (default: .csv)
30+
file_prefix = # This is a prefix that will be add in front of each upload file
31+
# (this can allow to store in subfolder by adding a prefix ending with "/")
32+
33+
[[outputs]]
34+
type = "postgres"
35+
[outputs.conf.postgres]
36+
host = # Host URL of postgres server
37+
port = # Port expose by postgres server
38+
db_name = # Postgres db name
39+
db_schema = # Postgres db schema
40+
user_name = # postgres username
41+
user_password = # posrgres password
42+
table_prefix = # prefix used on table creation (useful in case of using a centralize DB to differentiate)
43+
password_encoding = # boolean indicating if the password should be encoder (default: False) (used for password with special characters)
44+
45+
46+
# The secrets section contains all values that will be replaced by environement variables
47+
# The secrets section is transform at initialisation and then merge to root (the secrets sections no longer exist after transformation)
48+
49+
# The cosmotech sub section is added by default (it's all the environment variables given by the API)"
50+
51+
# # # DON'T ADD THIS IN THE FINAL FILE # # #
52+
53+
[secrets.cosmotech]
54+
dataset_absolute_path = "CSM_DATASET_ABSOLUTE_PATH"
55+
parameters_absolute_path = "CSM_PARAMETERS_ABSOLUTE_PATH"
56+
output_absolute_path = "CSM_OUTPUT_ABSOLUTE_PATH"
57+
tmp_absolute_path = "CSM_TEMP_ABSOLUTE_PATH"
58+
organization_id = "CSM_ORGANIZATION_ID"
59+
workspace_id = "CSM_WORKSPACE_ID"
60+
runner_id = "CSM_RUNNER_ID"
61+
run_id = "CSM_RUN_ID"
62+
run_template_id = "CSM_RUN_TEMPLATE_ID"
63+
64+
[secrets.cosmotech.api]
65+
url = "CSM_API_URL "
66+
scope = "CSM_API_SCOPE"
67+
68+
[secrets.cosmotech.twin_cache]
69+
host = "TWIN_CACHE_HOST"
70+
port = "TWIN_CACHE_PORT"
71+
password = "TWIN_CACHE_PASSWORD"
72+
username = "TWIN_CACHE_USERNAME"
73+
74+
[secrets.cosmotech.idp]
75+
base_url = "IDP_BASE_URL"
76+
tenant_id = "IDP_TENANT_ID"
77+
client_id = "IDP_CLIENT_ID"
78+
client_secret = "IDP_CLIENT_SECRET"

0 commit comments

Comments
 (0)