|
1 | 1 | """ |
2 | 2 | This sample demonstrates loading a named environment configuration profile and |
3 | | -overriding its values with environment variables. |
| 3 | +programmatically overriding its values. |
4 | 4 | """ |
5 | 5 |
|
6 | 6 | import asyncio |
|
12 | 12 |
|
13 | 13 | async def main(): |
14 | 14 | """ |
15 | | - Demonstrates loading a named profile and overriding it with env vars. |
| 15 | + Demonstrates loading a named profile and overriding values programmatically. |
16 | 16 | """ |
17 | | - print("--- Loading 'staging' profile with environment variable overrides ---") |
| 17 | + print("--- Loading 'staging' profile with programmatic overrides ---") |
18 | 18 |
|
19 | 19 | config_file = Path(__file__).parent / "config.toml" |
20 | 20 | profile_name = "staging" |
21 | 21 |
|
22 | | - # In a real application, these would be set in your shell or deployment |
23 | | - # environment (e.g., `export TEMPORAL_ADDRESS=localhost:7233`). |
24 | | - # For this sample, we pass them as a dictionary to demonstrate. |
25 | | - override_env = { |
26 | | - "TEMPORAL_ADDRESS": "localhost:7233", |
27 | | - } |
28 | | - print("The 'staging' profile in config.toml has an incorrect address.") |
29 | | - print("Using mock environment variables to override and correct it:") |
30 | | - for key, value in override_env.items(): |
31 | | - print(f" {key}={value}") |
32 | | - |
33 | | - # Load the 'staging' profile and apply environment variable overrides. |
| 22 | + print("The 'staging' profile in config.toml has an incorrect address (localhost:9999).") |
| 23 | + print("We'll programmatically override it to the correct address.") |
| 24 | + |
| 25 | + # Load the 'staging' profile. |
34 | 26 | connect_config = ClientConfig.load_client_connect_config( |
35 | 27 | profile=profile_name, |
36 | 28 | config_file=str(config_file), |
37 | | - override_env_vars=override_env, |
38 | 29 | ) |
39 | 30 |
|
| 31 | + # Override the target host to the correct address. |
| 32 | + # This is the recommended way to override configuration values. |
| 33 | + connect_config["target_host"] = "localhost:7233" |
| 34 | + |
40 | 35 | print(f"\nLoaded '{profile_name}' profile from {config_file} with overrides.") |
41 | | - print(f" Address: {connect_config.get('target_host')}") |
| 36 | + print(f" Address: {connect_config.get('target_host')} (overridden from localhost:9999)") |
42 | 37 | print(f" Namespace: {connect_config.get('namespace')}") |
43 | | - print( |
44 | | - "\nNote how the incorrect address from the file was corrected by the env var." |
45 | | - ) |
46 | 38 |
|
47 | 39 | print("\nAttempting to connect to client...") |
48 | 40 | try: |
|
0 commit comments