-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from JohnGrubba/dev
Config Validator Added
- Loading branch information
Showing
19 changed files
with
424 additions
and
113 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
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from .conf import config, not_updateable_cols_internal | ||
|
||
|
||
class AccountFeaturesConfig: | ||
enable_reset_pswd: bool = config["account_features"]["enable_reset_pswd"] | ||
reset_pswd_conf_mail: bool = config["account_features"]["reset_pswd_conf_mail"] | ||
enable_2fa: bool = config["account_features"]["2fa"]["enable"] | ||
issuer_name_2fa: str = config["account_features"]["2fa"]["issuer_name"] | ||
issuer_image_url_2fa: str = config["account_features"]["2fa"]["issuer_image_url"] | ||
qr_code_endpoint_2fa: bool = config["account_features"]["2fa"]["qr_endpoint"] | ||
|
||
if not isinstance(config["account_features"]["allow_add_fields_on_signup"], list): | ||
raise ValueError( | ||
"account_features.allow_add_fields_on_signup must be a list (got type {})".format( | ||
type(config["account_features"]["allow_add_fields_on_signup"]) | ||
) | ||
) | ||
|
||
allow_add_fields_on_signup: set[str] = set( | ||
config["account_features"]["allow_add_fields_on_signup"] | ||
) - set(not_updateable_cols_internal) | ||
|
||
if not isinstance(config["account_features"]["allow_add_fields_patch_user"], list): | ||
raise ValueError( | ||
"account_features.allow_add_fields_patch_user must be a list (got type {})".format( | ||
type(config["account_features"]["allow_add_fields_patch_user"]) | ||
) | ||
) | ||
|
||
allow_add_fields_patch_user: set[str] = set( | ||
config["account_features"]["allow_add_fields_patch_user"] | ||
) - set(not_updateable_cols_internal) | ||
allow_deletion: bool = config["account_features"]["allow_deletion"] | ||
deletion_pending_minutes: int = config["account_features"][ | ||
"deletion_pending_minutes" | ||
] | ||
|
||
def validate_types(self) -> bool: | ||
"""This is to Type Check the Configuration""" | ||
if not isinstance(self.enable_reset_pswd, bool): | ||
raise ValueError( | ||
"account_features.enable_reset_pswd must be a boolean (got type {})".format( | ||
type(self.enable_reset_pswd) | ||
) | ||
) | ||
if not isinstance(self.reset_pswd_conf_mail, bool): | ||
raise ValueError( | ||
"account_features.reset_pswd_conf_mail must be a boolean (got type {})".format( | ||
type(self.reset_pswd_conf_mail) | ||
) | ||
) | ||
if not isinstance(self.enable_2fa, bool): | ||
raise ValueError( | ||
"account_features.2fa.enable must be a boolean (got type {})".format( | ||
type(self.enable_2fa) | ||
) | ||
) | ||
if not isinstance(self.issuer_name_2fa, str): | ||
raise ValueError( | ||
"account_features.2fa.issuer_name must be a string (got type {})".format( | ||
type(self.issuer_name_2fa) | ||
) | ||
) | ||
if not isinstance(self.issuer_image_url_2fa, str): | ||
raise ValueError( | ||
"account_features.2fa.issuer_image_url must be a string (got type {})".format( | ||
type(self.issuer_image_url_2fa) | ||
) | ||
) | ||
if not isinstance(self.qr_code_endpoint_2fa, bool): | ||
raise ValueError( | ||
"account_features.2fa.qr_endpoint must be a boolean (got type {})".format( | ||
type(self.qr_code_endpoint_2fa) | ||
) | ||
) | ||
if not isinstance(self.allow_deletion, bool): | ||
raise ValueError( | ||
"account_features.allow_deletion must be a boolean (got type {})".format( | ||
type(self.allow_deletion) | ||
) | ||
) | ||
if not isinstance(self.deletion_pending_minutes, int): | ||
raise ValueError( | ||
"account_features.deletion_pending_minutes must be an integer (got type {})".format( | ||
type(self.deletion_pending_minutes) | ||
) | ||
) | ||
|
||
|
||
AccountFeaturesConfig().validate_types() |
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,45 @@ | ||
from .conf import config | ||
|
||
|
||
class EmailConfig: | ||
login_usr: str = config["email"]["login_usr"] | ||
login_pwd: str = config["email"]["login_pwd"] | ||
sender_email: str = config["email"]["sender_email"] | ||
smtp_host: str = config["email"]["smtp_host"] | ||
smtp_port: int = config["email"]["smtp_port"] | ||
|
||
def validate_types(self) -> None: | ||
"""This is to Type Check the Configuration""" | ||
if not isinstance(self.login_usr, str): | ||
raise ValueError( | ||
"email.login_usr must be a string (got type {})".format( | ||
type(self.login_usr) | ||
) | ||
) | ||
if not isinstance(self.login_pwd, str): | ||
raise ValueError( | ||
"email.login_pwd must be a string (got type {})".format( | ||
type(self.login_pwd) | ||
) | ||
) | ||
if not isinstance(self.sender_email, str): | ||
raise ValueError( | ||
"email.sender_email must be a string (got type {})".format( | ||
type(self.sender_email) | ||
) | ||
) | ||
if not isinstance(self.smtp_host, str): | ||
raise ValueError( | ||
"email.smtp_host must be a string (got type {})".format( | ||
type(self.smtp_host) | ||
) | ||
) | ||
if not isinstance(self.smtp_port, int): | ||
raise ValueError( | ||
"email.smtp_port must be an integer (got type {})".format( | ||
type(self.smtp_port) | ||
) | ||
) | ||
|
||
|
||
EmailConfig().validate_types() |
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,41 @@ | ||
from .conf import config, insecure_cols, not_updateable_cols_internal | ||
from collections import ChainMap | ||
|
||
|
||
class InternalConfig: | ||
internal_api_key: str = config["internal"]["internal_api_key"] | ||
# Type Check here because calculations need to be done immediately | ||
if not isinstance(config["internal"]["internal_columns"], list): | ||
raise ValueError( | ||
"internal.internal_columns must be a list (got type {})".format( | ||
type(config["internal"]["internal_columns"]) | ||
) | ||
) | ||
internal_columns: dict = dict( | ||
ChainMap(*[{col: 0} for col in set(config["internal"]["internal_columns"])]) | ||
) | ||
internal_columns.update(insecure_cols) | ||
# Insecure Cols + Internal Cols can't be updated by the user | ||
if not isinstance(config["internal"]["not_updateable_columns"], list): | ||
raise ValueError( | ||
"internal.not_updateable_columns must be a list (got type {})".format( | ||
type(config["internal"]["not_updateable_columns"]) | ||
) | ||
) | ||
not_updateable_columns: set = set( | ||
config["internal"]["not_updateable_columns"] | ||
+ list(internal_columns.keys()) | ||
+ not_updateable_cols_internal | ||
) | ||
|
||
def validate_types(self) -> bool: | ||
"""This is to Type Check the Configuration""" | ||
if not isinstance(self.internal_api_key, str): | ||
raise ValueError( | ||
"internal.internal_api_key must be a string (got type {})".format( | ||
type(self.internal_api_key) | ||
) | ||
) | ||
|
||
|
||
InternalConfig().validate_types() |
Oops, something went wrong.