def authenticateCredentials(userName, password): accessID = dc.encryptWithSecretKey(userName) password = dc.encryptWithSecretKey(password) status = isAccessIdAuthentic(accessID) if status != False: dbPass = status["password"] if password == dbPass: return 0 else: return 2 else: return 1
def isAccessTokenAuthentic(accessID, accessToken): accountDetails = isAccessIdAuthentic(accessID) if accountDetails != False: try: userName = accountDetails["userName"] password = accountDetails["password"] encodingKey = accountDetails["encodingKey"] credentials = userName + accessID + password + encodingKey internal_accessToken = dc.encryptWithSecretKey(credentials) except Exception as e: print(str(e)) return False if internal_accessToken == accessToken: return True else: print(credentials) print(accessToken) print(internal_accessToken) return False
def loginPage(): loginForm = forms.LoginForm() if request.method == 'POST': if loginForm.validate_on_submit(): print("INFO: ML_GUI: Form Data Validated.") userName = loginForm.userName.data password = loginForm.password.data status = authenticateCredentials(userName, password) if status == 0: print("Username/password combination validated.") accessID = dc.encryptWithSecretKey(userName) encodingKey = dc.generateHash(accessID) accessToken = generateAccessToken(userName, password, accessID, encodingKey) workspaces_url = url_for("mlGUI_bp.showWorkSpace", userName=userName, accessID=accessID, accessToken=accessToken) #workspaces_url = "192.168.0.192:5000" + workspaces_url #print(workspaces_url) return redirect(workspaces_url) elif status == 1: print("Invalid username.") return render_template('login.html', form=loginForm, status="Invalid usename," + userName + " does not exist in database.") elif status == 2: print("Incorrect password.") return render_template( 'login.html', form=loginForm, status="Incorrect password given for user: "******"login.html", form=loginForm) else: return make_response("Invalid http method", 404)
def generateAccessToken(userName, password, accessID, encodingKey): password = dc.encryptWithSecretKey(password) credentials = userName + accessID + password + encodingKey accessToken = dc.encryptWithSecretKey(credentials) print(credentials) return accessToken
def createNewWorkflow(accessID, workFlowName, baseModelID): # declare as global to update the original variable. global REQUEST_ID # generate a new id for each request. REQUEST_ID = str(uuid.uuid4()) userWorkflows = MLC.USER_WORKFLOWS_PATH workflowID = dc.encryptWithSecretKey(workFlowName) # STEP-1 Create new workspace. try: if not os.path.exists("./" + userWorkflows + "/" + str(accessID) + "/" + str(workflowID)): Path("./" + userWorkflows + "/" + str(accessID) + "/" + str(workflowID)).mkdir(parents=True, exist_ok=True) else: pass except Exception as e: print("ERROR: HyAPI_ML_INTERNAL: " + str(e)) return False # STEP-2 Populate workspace with template templateFile = MLC.TF_WORKSPACE_TEMPLATE #print(templateFile) userTfWorkflow = MLDC.getUserTF_workflow(accessID, workflowID) #The template will be extracted to the newly created User's Tensoflow workflow directory if extractZip(templateFile, userTfWorkflow): print( "INFO: HyAPI_ML_INTERNAL: New workflow directory clone successful." ) else: print( "ERROR: HyAPI_ML_INTERNAL: Error cloning new workflow from template." ) return False #TODO: implement other models # STEP-3 Extract selected model in the "pre-trained-model" folder if str(baseModelID) == "01": baseModel = MLC.MODEL_1_ZIP_PATH baseModelName = MLC.MODEL_NAME_1 usrBaseModelPath = MLDC.getBaseModelDirectory(accessID, workflowID) if extractZip(baseModel, usrBaseModelPath): print( "INFO: HyAPI_ML_INTERNAL: Pre-Trained-Model copied successfully." ) else: print( "ERROR: HyAPI_ML_INTERNAL: Error copying pre-trained-model to new workflow." ) return False # STEP-4 create and return response to client print("INFO: HyAPI_ML_INTERNAL: New workflow created successfuly.") #create workflow details as a dict to add in the json db workflowDetails = { "workflow_Name": workFlowName, "workflow_ID": workflowID, "process_ID": "Never Run", "process_Status": "Never Run", "baseModel": baseModelName, "dataSet": "empty", "timeStamp": fh.getTimeStamp() } if MLDC.saveWorkflowDetails(accessID, workflowID, workflowDetails): return True else: print( "ERROR: HyAPI_ML_INTERNAL: Error saving workflow details to db." ) return False else: print( "ERROR: HyAPI_ML_INTERNAL: Wrong parameter for baseModel(acceptable values are 01 & 02)" ) return False
def createNewWorkflow(): # declare as global to update the original variable. global REQUEST_ID # generate a new id for each request. REQUEST_ID = str(uuid.uuid4()) accessID = getAccessId() if fh.isAccessIdAuthentic(accessID): #This is the folder in workspace where all the files generated by services shoudl be stored. #userTfDir = dc.getUserTfDir(accessID) #Get the File IDs from the request parameters newWorkFlowDetails = request.json #Get the data from the json included in the request. try: workFlowName = newWorkFlowDetails["WorkflowName"] try: #TODO: Provision for multiple base models #baseModel = newWorkFlowDetails["BaseModel"] #baseModelID = baseModel baseModel = "01" baseModelID = "01" # 01,02,03,04 except Exception as e: print("ERROR: HyAPI_ML: " + str(e)) baseModel = "x" except Exception as e: print("ERROR: HyAPI_ML: " + str(e)) workFlowName = "x" ####################################################### if baseModel != "x" and workFlowName != "x": userWorkflows = MLC.USER_WORKFLOWS_PATH workflowID = dc.encryptWithSecretKey(workFlowName) # STEP-1 Create new workspace. try: if not os.path.exists("./" + userWorkflows + "/" + str(accessID) + "/" + str(workflowID)): Path("./" + userWorkflows + "/" + str(accessID) + "/" + str(workflowID)).mkdir(parents=True, exist_ok=True) else: pass except Exception as e: print(str(e)) status = "Error creating new workflow directory." print("ERROR: HyAPI_ML: " + status) httpCode = MLC.HTTP_SERVER_ERROR res = createReqDetails_newWorkflow(workFlowName, workflowID, baseModelID, REQUEST_ID, status, httpCode) return make_response(res, httpCode) # STEP-2 Populate workspace with template templateFile = MLC.TF_WORKSPACE_TEMPLATE #print(templateFile) userTfWorkflow = MLDC.getUserTF_workflow(accessID, workflowID) #The template will be extracted to the newly created User's Tensoflow workflow directory if extractZip(templateFile, userTfWorkflow): print( "INFO: HyAPI_ML: New workflow directory clone successful.") else: status = "Error cloning new workflow from template." print("ERROR: HyAPI_ML: " + status) httpCode = MLC.HTTP_SERVER_ERROR res = createReqDetails_newWorkflow(workFlowName, workflowID, baseModelID, REQUEST_ID, status, httpCode) return make_response(res, httpCode) # STEP-3 Extract selected model in the "pre-trained-model" folder if str(baseModel) == "01": baseModel = MLC.MODEL_1_ZIP_PATH baseModelName = MLC.MODEL_NAME_1 usrBaseModelPath = MLDC.getBaseModelDirectory( accessID, workflowID) if extractZip(baseModel, usrBaseModelPath): print(usrBaseModelPath) print( "INFO: HyAPI_ML: Pre-Trained-Model copied successfully." ) else: status = "Error copying pre-trained-model to new workflow." print("ERROR: HyAPI_ML: " + status) httpCode = MLC.HTTP_SERVER_ERROR res = createReqDetails_newWorkflow(workFlowName, workflowID, baseModelID, REQUEST_ID, status, httpCode) return make_response(res, httpCode) # STEP-4 create and return response to client status = "New workflow created successfuly." print("INFO: HyAPI_ML: " + status) httpCode = MLC.HTTP_CREATED #create workflow details as a dict to add in the json db workflowDetails = { "workflow_Name": workFlowName, "workflow_ID": workflowID, "process_ID": "Never Run", "process_Status": "Never Run", "baseModel": baseModelName, "timeStamp": fh.getTimeStamp() } if MLDC.saveWorkflowDetails(accessID, workflowID, workflowDetails): res = createReqDetails_newWorkflow(workFlowName, workflowID, baseModelID, REQUEST_ID, status, httpCode) return make_response(res, httpCode) else: status = "Error saving workflow details to db." print("ERROR: HyAPI_ML: " + status) httpCode = MLC.HTTP_SERVER_ERROR res = createReqDetails_newWorkflow(workFlowName, workflowID, baseModelID, REQUEST_ID, status, httpCode) return make_response(res, httpCode) else: status = "Wrong parameter for baseModel(acceptable values are 01 & 02)" print("ERROR: HyAPI_ML: " + status) httpCode = MLC.HTTP_BAD_REQUEST res = createReqDetails_newWorkflow(workFlowName, workflowID, baseModelID, REQUEST_ID, status, httpCode) return make_response("Error", 400) else: status = "WorkflowName & BaseModel values are required in input json. One or both are missing in the request." print("ERROR: HyAPI_ML: " + status) httpCode = MLC.HTTP_BAD_REQUEST res = createReqDetails_newWorkflow("N/A", "N/A", "N/A", REQUEST_ID, status, httpCode) return make_response(res, httpCode)