| 18 | |
| 19 | # Read secret from file |
| 20 | def _read_secret(secret_name: str, default: str | None = None) -> str | None: |
| 21 | try: |
| 22 | f = open('/run/secrets/' + secret_name, 'r', encoding='utf-8') |
| 23 | except EnvironmentError: |
| 24 | return default |
| 25 | else: |
| 26 | with f: |
| 27 | return f.readline().strip() |
| 28 | |
| 29 | # If the `map_fn` isn't defined, then the value that is read from the environment (or the default value if not found) is returned. |
| 30 | # If the `map_fn` is defined, then `map_fn` is invoked and the value (that was read from the environment or the default value if not found) |