121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
"""
|
|
Iterator helper testing
|
|
"""
|
|
|
|
from typing import Any
|
|
from corelibs.debug_handling.dump_data import dump_data
|
|
from corelibs.iterator_handling.dict_mask import mask
|
|
from corelibs.iterator_handling.dict_helpers import set_entry
|
|
|
|
|
|
def __mask():
|
|
data = {
|
|
# "user": "john",
|
|
# "encryption_key": "Secret key",
|
|
# "ENCRYPTION.TEST": "Secret key test",
|
|
# "inside_password_test": "Hide this",
|
|
"password": ["secret1", "secret2"], # List value gets masked
|
|
# "config": {
|
|
# "db_password": {"primary": "secret", "backup": "secret2"}, # Dict value gets masked
|
|
# "api_keys": ["key1", "key2", "key3"] # List value gets masked
|
|
# },
|
|
# "items": [ # List value that doesn't get masked, but gets processed recursively
|
|
# {"name": "item1", "secret_key": "itemsecret"},
|
|
# {"name": "item2", "passwords": ["pass1", "pass2"]}
|
|
# ],
|
|
# "normal_list": ["item1", "item2", "item3"] # Normal list, not masked
|
|
}
|
|
data = {
|
|
"config": {
|
|
# "password": ["secret1", "secret2"],
|
|
# "password_other": {"password": ["secret1", "secret2"]},
|
|
# "database": {
|
|
# "host": "localhost",
|
|
# "password": "db_secret",
|
|
# "users": [
|
|
# {"name": "admin", "password": "admin123"},
|
|
# {"name": "user", "secret_key": "user456"}
|
|
# ]
|
|
# },
|
|
# "api": {
|
|
# # "endpoints": ["api1", "api2"],
|
|
# "encryption_settings": {
|
|
# "enabled": True,
|
|
# "secret": "api_secret"
|
|
# }
|
|
# }
|
|
"secret_key": "normal_value",
|
|
"api_key": "normal_value",
|
|
"my_key_value": "normal_value",
|
|
}
|
|
}
|
|
data = {
|
|
"basic": {
|
|
"log_level_console": "DEBUG",
|
|
"log_level_file": "DEBUG",
|
|
"storage_interface": "sqlite",
|
|
"content_start_date": "2023-1-1",
|
|
"encryption_key": "ENCRYPTION_KEY"
|
|
},
|
|
"email": {
|
|
"alert_email": [
|
|
"test+z-sd@tequila.jp"
|
|
]
|
|
},
|
|
"poller": {
|
|
"max_forks": "1",
|
|
"interface": "Zac"
|
|
},
|
|
"pusher": {
|
|
"max_forks": "3",
|
|
"interface": "Screendragon"
|
|
},
|
|
"api:Zac": {
|
|
"type": "zac",
|
|
"client_id": "oro_zac_demo",
|
|
"client_secret": "CLIENT_SECRET",
|
|
"username": "zacuser",
|
|
"password": "ZACuser3",
|
|
"hostname": "e-gra2.zac.ai",
|
|
"appname": "e-gra2_api_trial",
|
|
"api_path": "b/api/v2"
|
|
},
|
|
"api:Screendragon": {
|
|
"type": "screendragon",
|
|
"client_id": "omniprostaging",
|
|
"encryption_client": "SOME_SECRET",
|
|
"client_encryption": "SOME_SECRET",
|
|
"secret_client": "SOME_SECRET",
|
|
"client_secret": "SOME_SECRET",
|
|
"hostname": "omniprostaging.screendragon.com",
|
|
"appname": "sdapi",
|
|
"api_path": "api"
|
|
}
|
|
}
|
|
result = mask(data)
|
|
print(f"** In: {dump_data(data)}")
|
|
print(f"===> Masked: {dump_data(result)}")
|
|
|
|
|
|
def __set_dict_value_entry():
|
|
|
|
dict_empty: dict[str, Any] = {}
|
|
new = set_entry(dict_empty, 'a.b.c', 1)
|
|
print(f"[1] Set dict entry: {dump_data(new)}")
|
|
new = set_entry(new, 'dict', {'key': 'value'})
|
|
print(f"[2] Set dict entry: {dump_data(new)}")
|
|
new = set_entry(new, 'list', [1, 2, 3])
|
|
print(f"[3] Set dict entry: {dump_data(new)}")
|
|
|
|
|
|
def main():
|
|
"""
|
|
Test: corelibs.string_handling.string_helpers
|
|
"""
|
|
__mask()
|
|
__set_dict_value_entry()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|