-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add
make check-config
command (#875)
* wip * Add check config * uncomment poetry command * test * uncomment * update lock poetry
- Loading branch information
1 parent
8a5c4c8
commit 6fc3a08
Showing
14 changed files
with
316 additions
and
212 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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
6 changes: 3 additions & 3 deletions
6
src/backend/cli/prompts.py → src/backend/scripts/cli/prompts.py
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
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
Empty file.
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,27 @@ | ||
from backend.scripts.config.constants import ( | ||
CONFIG_FILE_PATH, | ||
CONFIG_TEMPLATE_PATH, | ||
SECRETS_FILE_PATH, | ||
SECRETS_TEMPLATE_PATH, | ||
) | ||
from backend.scripts.config.utils import find_missing_keys, print_styled, read_yaml | ||
|
||
|
||
def check_config(): | ||
# Check configuration files | ||
config_yaml = read_yaml(CONFIG_FILE_PATH) | ||
config_template_yaml = read_yaml(CONFIG_TEMPLATE_PATH) | ||
config_keys_missing = find_missing_keys(config_yaml, config_template_yaml) | ||
|
||
# Check secrets files | ||
secrets_yaml = read_yaml(SECRETS_FILE_PATH) | ||
secrets_template_yaml = read_yaml(SECRETS_TEMPLATE_PATH) | ||
secrets_keys_missing = find_missing_keys(secrets_yaml, secrets_template_yaml) | ||
|
||
if config_keys_missing: | ||
print_styled(f"Warning: Your configuration.yaml is missing the following keys: {config_keys_missing}") | ||
|
||
if secrets_keys_missing: | ||
print_styled(f"Warning: Your secrets.yaml is missing the following keys: {secrets_keys_missing}") | ||
|
||
check_config() |
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,5 @@ | ||
BASE_CONFIG_PATH = "src/backend/config" | ||
CONFIG_FILE_PATH = f"{BASE_CONFIG_PATH}/configuration.yaml" | ||
CONFIG_TEMPLATE_PATH = f"{BASE_CONFIG_PATH}/configuration.template.yaml" | ||
SECRETS_FILE_PATH = f"{BASE_CONFIG_PATH}/secrets.yaml" | ||
SECRETS_TEMPLATE_PATH = f"{BASE_CONFIG_PATH}/secrets.template.yaml" |
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,54 @@ | ||
import yaml | ||
|
||
|
||
class bcolors: | ||
FAIL = "\033[91m" | ||
ENDC = "\033[0m" | ||
|
||
def print_styled(text: str, color: str = bcolors.FAIL): | ||
print(color + text + bcolors.ENDC) | ||
|
||
def read_yaml(file_path: str): | ||
""" | ||
Loads a YAML file. | ||
Args: | ||
file_path (str): File path to a YAML file. | ||
Returns: | ||
dict: Dictionary representation of the YAML file. | ||
""" | ||
with open(file_path, "r") as file: | ||
return yaml.safe_load(file) | ||
|
||
def find_missing_keys(dict_a, dict_b, parent_key=''): | ||
""" | ||
Recursively checks for keys in dict_b that are missing in dict_a. | ||
Args: | ||
dict_a (dict): The base dictionary to compare against. | ||
dict_b (dict): The dictionary to check for missing keys. | ||
parent_key (str): Used for tracking nested keys. | ||
Returns: | ||
list: A list of missing keys. | ||
""" | ||
missing_keys = [] | ||
|
||
for key, value in dict_b.items(): | ||
# Construct the full key path for nested keys | ||
full_key = f"{parent_key}.{key}" if parent_key else key | ||
|
||
if isinstance(value, dict): | ||
# If both dictionaries contain this key, go deeper | ||
if isinstance(dict_a.get(key), dict): | ||
missing_keys.extend(find_missing_keys(dict_a[key], value, full_key)) | ||
else: | ||
# If dict_a has the key but it's not a dictionary, treat all nested keys as missing | ||
missing_keys.extend(find_missing_keys({}, value, full_key)) | ||
else: | ||
if key not in dict_a: | ||
# If the key itself is missing in dict_a | ||
missing_keys.append(full_key) | ||
|
||
return missing_keys |
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