def removeCreds(type, id): if type == "AWS": cred = AWSCreds.get(AWSCreds.id == id) spaces = SpaceAWS.select().where(SpaceAWS.cid == cred.id) if len(spaces) != 0: return Response.make_error_resp(msg="Please Delete Spaces using these credentials before deleting " "credentials", code=400) else: cred.delete_instance() return Response.make_success_resp("Credentials have been removed") if type == "Openstack": cred = OSCreds.get(OSCreds.id == id) spaces = SpaceOS.select().where(SpaceOS.cid == cred.id) if len(spaces) != 0: return Response.make_error_resp(msg="Please Delete Spaces using these credentials before deleting " "credentials", code=400) else: cred.delete_instance() return Response.make_success_resp("Credentials have been removed") if type == "GCP": cred = GCPCreds.get(GCPCreds.id == id) platforms = Platforms.select().where(Platforms.cid == cred.id) if len(platforms) != 0: return Response.make_error_resp(msg="Please Delete Platforms using these credentials before deleting " "credentials", code=400) else: cred.delete_instance() return Response.make_success_resp("Credentials have been removed") else: return Response.make_error_resp("Invalid Type", code=400)
def removeUser(uid): data = request.json try: user = Users.get(Users.uid == uid) except Users.DoesNotExist: return Response.make_error_resp(msg="No User Found") except: return Response.make_error_resp(msg="Error reading database", code=500) platforms = Platforms.select().where(Platforms.uid == user.uid) awsSpaces = SpaceAWS.select().where(SpaceAWS.uid == user.uid) if len(platforms) != 0 or len(awsSpaces) !=0: return Response.make_error_resp(msg="Please remove all spaces and platforms before deleting account") if 'password' in data: password = data["password"] else: return Response.make_error_resp(msg="Password is required", code=400) # Verify password if pbkdf2_sha256.verify(password, user.password): AWSCreds.delete().where(AWSCreds.uid == user.uid) OSCreds.delete().where(OSCreds.uid == user.uid) GCPCreds.delete().where(GCPCreds.uid == user.uid) user.delete_instance() return Response.make_success_resp("User has been removed")
def removeAWSSpace(id): try: space = SpaceAWS.get(SpaceAWS.id == id) except SpaceAWS.DoesNotExist: return Response.make_error_resp(msg="Space Not Found", code=400) platforms = Platforms.select().where(Platforms.sid == space.id) if len(platforms) != 0: return Response.make_error_resp( msg= "Please remove all platforms in this space before removing space") data = request.json if 'uid' in data: uid = data['uid'] else: return Response.make_error_resp(msg="User ID is required", code=400) try: user = Users.get(Users.uid == uid) except Users.DoesNotExist: return Response.make_error_resp(msg="No User Found") if 'password' in data: password = data['password'] else: return Response.make_error_resp(msg="Password is required", code=400) if not pbkdf2_sha256.verify(password, user.password): return Response.make_error_resp(msg="Password is Incorrect", code=400) creds = AWSCreds.get(AWSCreds.id == space.cid) secretKey = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.secretKey) accessKey = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.accessKey) tf.generateAWSSpaceVars(secretKey, accessKey, "", "", "", space.dir) path = space.dir resultCode = tf.destroy(space.dir) if resultCode != 0: return Response.make_error_resp(msg="Error deleting platform") space.delete_instance() if path != "": shutil.rmtree(path) return Response.make_success_resp(msg="Space Has been removed")
def removeOSSpace(id): try: space = SpaceOS.get(SpaceOS.id == id) except SpaceOS.DoesNotExist: return Response.make_error_resp(msg="Space Not Found", code=400) platforms = Platforms.select().where(Platforms.sid == space.id) if len(platforms) != 0: return Response.make_error_resp( msg= "Please remove all platforms in this space before removing space") data = request.json if 'uid' in data: uid = data['uid'] else: return Response.make_error_resp(msg="User ID is required", code=400) try: user = Users.get(Users.uid == uid) except Users.DoesNotExist: return Response.make_error_resp(msg="No User Found") if 'password' in data: password = data['password'] else: return Response.make_error_resp(msg="Password is required", code=400) if pbkdf2_sha256.verify(password, user.password): space.delete_instance() return Response.make_success_resp("Space Removed") else: return Response.make_error_resp(msg="Password is Incorrect", code=400)
def updateDataProcessing(id): try: platform = Platforms.get(Platforms.id == id) except Platforms.DoesNotExist: return Response.make_error_resp(msg="Platform Not Found", code=400) data = dict(request.form) if 'script' in request.files: script = request.files['script'] else: return Response.make_error_resp(msg="Script not in request", code=400) if 'uid' in data: uid = data['uid'] else: return Response.make_error_resp(msg="User ID is required", code=400) try: user = Users.get(Users.uid == uid) except Users.DoesNotExist: return Response.make_error_resp(msg="No User Found") if 'password' in data: password = data['password'] else: return Response.make_error_resp(msg="Password is required", code=400) if 'packages' in data: packages = data['packages'].replace(" ", "").split(",") else: packages = [] if len(packages) != 0: issue = checkPackages(packages) if issue != "": return Response.make_error_resp(msg=issue + " Package not valid", code=400) exsistingPackages = platform.packageList.split(",") packages = exsistingPackages + packages + [ "pika==1.1.0", "influxdb", "pymongo" ] if not pbkdf2_sha256.verify(password, user.password): return Response.make_error_resp(msg="Password is Incorrect", code=400) privateKey = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=user.privateKey) updateAnsibleFiles = "ansiblePlaybooks/updateProcessing" ansiblePath = os.path.join(platform.dir, "ansible", "updatePlatform") if os.path.exists(ansiblePath): shutil.rmtree(ansiblePath) shutil.copytree(updateAnsibleFiles, ansiblePath) script.save( os.path.join(ansiblePath, "roles", "dmacklin.updateProcessing", "templates", "dataProcessing.py")) ab.generateRequirementsFile(packages, ansiblePath, "dmacklin.updateProcessing") output, error = ab.runPlaybook(platform.ipAddress, privateKey, ansiblePath, "updateProcessing") print(output) print(error) return Response.make_success_resp(msg="Script updated")
def removePlatform(id): try: platform = Platforms.get(Platforms.id == id) except Platforms.DoesNotExist: return Response.make_error_resp(msg="Platform Not Found", code=400) data = request.json if 'uid' in data: uid = data['uid'] else: return Response.make_error_resp(msg="User ID is required", code=400) try: user = Users.get(Users.uid == uid) except Users.DoesNotExist: return Response.make_error_resp(msg="No User Found") if 'password' in data: password = data['password'] else: return Response.make_error_resp(msg="Password is required", code=400) if not pbkdf2_sha256.verify(password, user.password): return Response.make_error_resp(msg="Password is Incorrect", code=400) path = "" if platform.cloudService == "aws": space = SpaceAWS.get((SpaceAWS.id == platform.sid) & (SpaceAWS.uid == uid)) creds = AWSCreds.get(AWSCreds.id == space.cid) secretKey = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.secretKey) accessKey = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.accessKey) tf.generateAWSPlatformVars("", "", "", secretKey, accessKey, 0, "", platform.dir) elif platform.cloudService == "openstack": space = SpaceOS.get((SpaceOS.id == platform.sid) & (SpaceOS.uid == uid)) creds = OSCreds.get(OSCreds.id == space.cid) osUsername = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.username) osPassword = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.password) authUrl = encryption.decryptString(password=password, salt=user.keySalt, resKey=user.resKey, string=creds.authUrl) tf.generateOSPlatformVars(osUsername, osPassword, space.tenantName, authUrl, space.availabilityZone, "", "", "", space.ipPool, space.securityGroup, space.intNetwork, "", "", platform.dir) elif platform.cloudService == "gcp": creds = GCPCreds.get(GCPCreds.id == platform.cid) gcpGenVars(user, password, creds, "", "", platform.name, platform.dir) path = platform.dir resultCode = tf.destroy(platform.dir) if resultCode != 0: return Response.make_error_resp(msg="Error deleting platform") platform.delete_instance() if path != "": shutil.rmtree(path) return Response.make_success_resp(msg="Platform Has been removed")