From 3b1bade3c59e870c9d2cc4130c5d7fd191f05307 Mon Sep 17 00:00:00 2001 From: Mohanna Shahrad Date: Thu, 25 Aug 2022 16:23:40 +0000 Subject: [PATCH] Added the common directory - common files and functions between all the patterns --- cloud_templates/.gitignore | 2 ++ cloud_templates/aws_cdk/common/__init__.py | 0 .../aws_cdk/common/customExceptions.py | 31 +++++++++++++++++++ .../aws_cdk/common/inputValidation.py | 10 ++++++ 4 files changed, 43 insertions(+) create mode 100644 cloud_templates/.gitignore create mode 100644 cloud_templates/aws_cdk/common/__init__.py create mode 100644 cloud_templates/aws_cdk/common/customExceptions.py create mode 100644 cloud_templates/aws_cdk/common/inputValidation.py diff --git a/cloud_templates/.gitignore b/cloud_templates/.gitignore new file mode 100644 index 0000000..e793802 --- /dev/null +++ b/cloud_templates/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +aws_cdk/common/__pycache__/ diff --git a/cloud_templates/aws_cdk/common/__init__.py b/cloud_templates/aws_cdk/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cloud_templates/aws_cdk/common/customExceptions.py b/cloud_templates/aws_cdk/common/customExceptions.py new file mode 100644 index 0000000..93ca756 --- /dev/null +++ b/cloud_templates/aws_cdk/common/customExceptions.py @@ -0,0 +1,31 @@ +class NoSQL(Exception): + + def __init__(self): + self.message = "No sql statemtnt is provided. Please refer to README.md for more information." + + def __str__(self): + return(repr(self.message)) + +class NoTimestreamDimension(Exception): + + def __init__(self): + self.message = "No dimesnsion is provided. Each record contains an array of dimensions (minimum 1).Please refer to README.md for more information." + + def __str__(self): + return(repr(self.message)) + +class WrongLengthForInput(Exception): + + def __init__(self, message): + self.message = message + + def __str__(self): + return(repr(self.message)) + +class WrongFormattedInput(Exception): + + def __init__(self, message): + self.message = message + + def __str__(self): + return(repr(self.message)) \ No newline at end of file diff --git a/cloud_templates/aws_cdk/common/inputValidation.py b/cloud_templates/aws_cdk/common/inputValidation.py new file mode 100644 index 0000000..ee84eaf --- /dev/null +++ b/cloud_templates/aws_cdk/common/inputValidation.py @@ -0,0 +1,10 @@ +import re +from common.customExceptions import * + +def checkInputLength(self, min_length, max_length, input, resource_name): + if len(input) < min_length or len(input) > max_length: + raise WrongLengthForInput(f"Invalid input length for {resource_name}'s name. Check the README.md file for more details.") + +def checkInputPattern(self, pattern, input, resource_name): + if not re.match(pattern, input): + raise WrongFormattedInput(f"Invalid input pattern for {resource_name}'s name. Check the README.md file for more details.") \ No newline at end of file