-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow reading Heroku API key from file
Makes using it in an installed environment much simpler
- Loading branch information
1 parent
538d3a7
commit 1b6dc48
Showing
2 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from typer import get_app_dir | ||
|
||
APP_DIR = Path(get_app_dir("heroku-audit")) | ||
|
||
|
||
def config_env_default( | ||
file_name: str, env_var: str, default: Optional[str] = None | ||
) -> Optional[str]: | ||
""" | ||
Attempt to load a configuration value. | ||
Sources, in order: | ||
1. Environment variable named `env_var` | ||
2. Config file in app dir with name `file_name` | ||
3. `default` | ||
""" | ||
if env_value := os.environ.get(env_var): | ||
return env_value | ||
|
||
config_file = APP_DIR / file_name | ||
if config_file.is_file(): | ||
return config_file.read_text() | ||
|
||
return default |