def create_a_template(): ''' Goal: create a template for validating data , depending on the initial event, aimed at the /notification [discharge_a_chat]. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of Discharge_a_ChatTemplateBuilder. Using the FieldBuilder class - create an instance of Discharge_a_ChatFieldBuilder. Build the IdField - set proper requisites, using the DataType Requirement, providing the required datatype - int, and lastly build the product - reseting the Builder. Then add the built product/Field to the template , using Discharge_a_ChatTemplateBuilder; Return the instance of the Template class from the builder, thus reseting the Discharge_a_ChatTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' Discharge_a_ChatTemplateBuilder=TemplateBuilder() Discharge_a_ChatFieldBuilder=FieldBuilder() Discharge_a_ChatFieldBuilder.requisites={'key':'id','required':True} Discharge_a_ChatFieldBuilder.add(DataType(int)) Discharge_a_ChatTemplateBuilder.add(Discharge_a_ChatFieldBuilder.product) return Discharge_a_ChatTemplateBuilder.product
def create_a_template(): ''' Goal: create a template for validating data , depending on the initial request, aimed at the DELETE /api/users/<identification>. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of DeleteIdentifiedUserTemplateBuilder. Using the FieldBuilder class - create an instance of DeleteIdentifiedUserFieldBuilder. Build the PasswordField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder. Then add the built product/Field to the template , using DeleteIdentifiedUserTemplateBuilder; [Note regular expression - a string of 64 characters - the sha256 hexdigested hash] Add a neccessary field "password" with proper requirements : a string of at least 64 characters long - expecting hex digest of sha256. Return the instance of the Template class from the builder, thus reseting the DeleteIdentifiedUserTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' DeleteIdentifiedUserTemplateBuilder = TemplateBuilder() DeleteIdentifiedUserFieldBuilder = FieldBuilder() DeleteIdentifiedUserFieldBuilder.requisites = { 'key': 'password', 'required': True } DeleteIdentifiedUserFieldBuilder.add(String('^\w{64}$')) DeleteIdentifiedUserTemplateBuilder.add( DeleteIdentifiedUserFieldBuilder.product) return DeleteIdentifiedUserTemplateBuilder.product
def create_a_template(): ''' Goal: create a template for validating data , depending on the initial event, aimed at the /chat [discharge_messages]. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of Discharge_MessagesTemplateBuilder. Using the FieldBuilder class - create an instance of Discharge_MessagesFieldBuilder. Build the MessagesField - set proper requisites, using the Iterable Requirement, providing the required iterable datatype - list and internal datatype - int, and lastly build the product - reseting the Builder. Then add the built product/Field to the template , using Discharge_MessagesTemplateBuilder; Add a neccessary field "messages" with proper requirements : a list of inner values:int. Return the instance of the Template class from the builder, thus reseting the Discharge_MessagesTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' Discharge_MessagesTemplateBuilder = TemplateBuilder() Discharge_MessagesFieldBuilder = FieldBuilder() Discharge_MessagesFieldBuilder.requisites = { 'key': 'messages', 'required': True } Discharge_MessagesFieldBuilder.add(Iterable(list, int)) Discharge_MessagesTemplateBuilder.add( Discharge_MessagesFieldBuilder.product) return Discharge_MessagesTemplateBuilder.product
def create_a_template(): ''' Goal: create a template for validating data , depending on the initial event, aimed at the /chat [establish_a_message]. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of Establish_a_ChatTemplateBuilder. Using the FieldBuilder class - create an instance of Establish_a_ChatFieldBuilder. Build a ContentField - set proper requisites, using a Nested requirement, provide nested (key:Requiremnt)s: iv: with DataType Requirement of a string; data: with DataType Requirement of a string. [Note] - the content of the message - has to be encrypted, so it shall follow the latter structure - thus the backend is not able to decrypt the content. Therefore in order to accept only properly formed messages,keeping the integrity and the confidentiality intact - the mentioned structure is a set up as a guideline. Return the instance of the Template class from the builder, thus reseting the Establish_a_MessageTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' Establish_a_MessageTemplateBuilder = TemplateBuilder() Establish_a_MessageFieldBuilder = FieldBuilder() nested_requirement = Nested(**{'iv': DataType(str), 'data': DataType(str)}) Establish_a_MessageFieldBuilder.requisites = { 'key': 'content', 'required': True } Establish_a_MessageFieldBuilder.add(nested_requirement) Establish_a_MessageTemplateBuilder.add( Establish_a_MessageFieldBuilder.product) return Establish_a_MessageTemplateBuilder.product
def create_a_template(): ''' Goal: create a template for validating incoming data, aimed at the POST /api/tokens/confirmation. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of PostConfirmationTemplateBuilder. Using the FieldBuilder class - create an instance of PostConfirmationFieldBuilder. 1.Build the ActionField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostConfirmationTemplateBuilder; [Note: action - refers to a goal the requester tries to achieve, which needs the confirmation -> thus actions are delete(terminate) or put(reset)] 2.Return the instance of the Template class from the builder, thus reseting the PostGrantTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' PostConfirmationTemplateBuilder = TemplateBuilder() PostConfirmationFieldBuilder = FieldBuilder() PostConfirmationFieldBuilder.requisites = { 'key': 'action', 'required': True } PostConfirmationFieldBuilder.add(String('^(?:delete|put)$')) PostConfirmationTemplateBuilder.add(PostConfirmationFieldBuilder.product) return PostConfirmationTemplateBuilder.product
def create_a_template(): ''' Goal: create a template for validating data , depending on the initial request, aimed at the PUT /api/users/<identification>. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of PutIdentifiedUserTemplateBuilder. Using the FieldBuilder class - create an instance of PutIdentifiedUserFieldBuilder. Build a ResetField - set proper requisites, using a Nested requirement, provide nested (key:Requiremnt)s: password : a Nested requirement, shall contain (key:Requiremnt)s: current: with String Requirement of 64 characters - sha256 hexdigested; new: with String Requirement of 64 characters - sha256 hexdigested; private_key : a Nested requirement, shall contain (key:Requiremnt)s: iv: with DataType Requirement of a string; data: with DataType Requirement of a string. Return the instance of the Template class from the builder, thus reseting the PutIdentifiedUserTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' PutIdentifiedUserTemplateBuilder = TemplateBuilder() PutIdentifiedUserFieldBuilder = FieldBuilder() nested_requirement = Nested( **{ 'password': Nested(**{ 'current': String('^\w{64}$'), 'new': String('^\w{64}$') }), 'private_key': Nested(**{ 'iv': DataType(str), 'data': DataType(str) }) }) PutIdentifiedUserFieldBuilder.requisites = { 'key': 'reset', 'required': True } PutIdentifiedUserFieldBuilder.add(nested_requirement) PutIdentifiedUserTemplateBuilder.add(PutIdentifiedUserFieldBuilder.product) return PutIdentifiedUserTemplateBuilder.product
def create_a_template(): ''' Goal: create a template for validating data , depending on the initial event, aimed at the /notification [establish_a_chat]. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of Establish_a_ChatTemplateBuilder. Using the FieldBuilder class - create an instance of Establish_a_ChatFieldBuilder. 1.Build the NameField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using Establish_a_ChatTemplateBuilder; [Note regular expression - a string of at least 4 characters/spaces long , 30 characters/spaces max and with at least 4 characters in it] 2.Build the Participant_IdField - set proper requisites(required=False), using the DataType Requirement, providing the required datatype - int, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using Establish_a_ChatTemplateBuilder; [Note - the latter field - "participant_id" is set up as non required, due to the permitions to start chats without any participants] Return the instance of the Template class from the builder, thus reseting the Establish_a_ChatTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. ''' Establish_a_ChatTemplateBuilder = TemplateBuilder() Establish_a_ChatFieldBuilder = FieldBuilder() Establish_a_ChatFieldBuilder.requisites = {'key': 'name', 'required': True} Establish_a_ChatFieldBuilder.add( String('^(?=.*(?:\w.*){4,})[\w\s]{4,30}$')) Establish_a_ChatTemplateBuilder.add(Establish_a_ChatFieldBuilder.product) Establish_a_ChatFieldBuilder.requisites = { 'key': 'participant_id', 'required': False } Establish_a_ChatFieldBuilder.add(DataType(int)) Establish_a_ChatTemplateBuilder.add(Establish_a_ChatFieldBuilder.product) return Establish_a_ChatTemplateBuilder.product
def create_a_template(route): ''' Goal: create a template based on the initial route of the requrest. Arguments: route:str , expecting alternatives = signup/login. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of PostVerificationTemplateBuilder. Using the FieldBuilder class - create an instance of PostVerificationFieldBuilder. If the route is signup: S.1.Build the EmailField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostVerificationTemplateBuilder; [Note regular expression - a proper email structure] S.2.Build the UsernameField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostVerificationTemplateBuilder; [Note regular expression - a username shall only contain word-characters, with a range of [6;30] characters long] S.3.Build the NameField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostVerificationTemplateBuilder; [Note regular expression - a name shall only contain letters, with a range of [3;25] characters long] S.4.Build the AboutField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostVerificationTemplateBuilder; [Note regular expression - an about shall at least contain 5 letters] S.5.Return the instance of the Template class from the builder, thus reseting the PostVerificationTemplateBuilder. Otherwise: L.1.Build the IdentificationField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostVerificationTemplateBuilder; [Note regular expression - a proper email structure or the username pattern] L.2.Return the instance of the Template class from the builder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. Exceptions: Raises: ValueError - if the provided route argument doesn't fall under any of the alternative values. ''' assert any(map(lambda a: route==a,('signup','login'))), ValueError('The route argument shall have a value of "signup" or "login".') PostVerificationTemplateBuilder=TemplateBuilder() PostVerificationFieldBuilder=FieldBuilder() if route=='signup': PostVerificationFieldBuilder.requisites={'key':'email','required':True} PostVerificationFieldBuilder.add(String('^(?=[\w_\-\.]+\@\w+\.\w+)[\w_\-\.@]{5,60}$')) PostVerificationTemplateBuilder.add(PostVerificationFieldBuilder.product) PostVerificationFieldBuilder.requisites={'key':'username','required':True} PostVerificationFieldBuilder.add(String('^\w{6,30}$')) PostVerificationTemplateBuilder.add(PostVerificationFieldBuilder.product) PostVerificationFieldBuilder.requisites={'key':'name','required':True} PostVerificationFieldBuilder.add(String('^[a-zA-Z]{3,25}')) PostVerificationTemplateBuilder.add(PostVerificationFieldBuilder.product) PostVerificationFieldBuilder.requisites={'key':'about','required':True} PostVerificationFieldBuilder.add(String('(?=.*(?:[a-zA-Z].*){5}).+')) PostVerificationTemplateBuilder.add(PostVerificationFieldBuilder.product) else: PostVerificationFieldBuilder.requisites={'key':'identification','required':True} PostVerificationFieldBuilder.add(String('^((?:\w{6,30})|(?:(?=[\w_\-\.]+\@\w+\.\w+)[\w_\-\.@]{5,60}))$')) PostVerificationTemplateBuilder.add(PostVerificationFieldBuilder.product) return PostVerificationTemplateBuilder.product
def create_a_template(route): ''' Goal: create a template for validating data , depending on th initial route, in the post requests aimed at the /api/tokens/grant. Actions: According to the BuilderPattern proceed to build the Fields and the Template: Using the TemplateBuilder class - create an instance of PostGrantTemplateBuilder. Using the FieldBuilder class - create an instance of PostGrantFieldBuilder. 1.Build the PasswordField - set proper requisites, using the String Requirement, providing the required regular expresion, and lastly build the product - reseting the Builder,for the next Field. Then add the built product/Field to the template , using PostGrantTemplateBuilder; [Note regular expression - a string of 64 characters - the sha256 hexdigested hash] If the route is signup: 2.Build the KeyringField - set: Create a 2 Nested Requirements: 1)First Nested requirement shall contain (key:Requiremnt)s : public_key : with DataType Requirement of an integer; g: with DataType Requirement of an integer; m: with DataType Requirement of an integer; private_key : 2) Second Nested requirement, shall contain (key:Requiremnt)s: iv: with DataType Requirement of a string; data: with DataType Requirement of a string. Return the instance of the Template class from the builder, thus reseting the PostGrantTemplateBuilder. Returns: instance of the Template class from the builder, using a property of the TemplateBuilder - product. Exceptions: Raises: ValueError - if the provided route argument doesn't fall under any of the alternative values. ''' assert any(map(lambda a: route == a, ('signup', 'login'))), ValueError( 'The route argument shall have a value of "signup" or "login".') PostGrantTemplateBuilder = TemplateBuilder() PostGrantFieldBuilder = FieldBuilder() PostGrantFieldBuilder.requisites = {'key': 'password', 'required': True} PostGrantFieldBuilder.add(String('^\w{64}$')) PostGrantTemplateBuilder.add(PostGrantFieldBuilder.product) if route == 'signup': nested_requirement = Nested( **{ 'public_key': DataType(int), 'g': DataType(int), 'm': DataType(int), 'private_key': Nested(**{ 'iv': DataType(str), 'data': DataType(str) }) }) PostGrantFieldBuilder.requisites = {'key': 'keyring', 'required': True} PostGrantFieldBuilder.add(nested_requirement) PostGrantTemplateBuilder.add(PostGrantFieldBuilder.product) return PostGrantTemplateBuilder.product