예제 #1
0
def putinput(optionname):
    iop={
        "serviceid": "",
        "task":""
        }
    serviceid=request.json["serviceid"]
    task=request.json["task"]
    step=getoption(serviceid,optionname)
    stepjson=step["body"]
    try:
        for stepid in stepjson["steporder"]:
            for steptask in stepjson[stepid]["tasks"]:
                if steptask["taskname"]==task["taskname"]:
                    inputjson=task["input_options"]
                    steptask["input_options"]=inputjson
                    taskinputpath="deploy/"+serviceid+"/"+optionname+"/"+stepid+"/task"+str(task["taskno"])+"/"+stepid.lower()+"/inputoption.json"
                    status,statusmessage,taskwrite=datafile.write_s3_file(taskinputpath,inputjson)
                    if status == "error":
                        message={"statusCode":400,"errorMessage":statusmessage}
                        return(message)
                    task["formfill"]=False
                    steptask["formfill"]=False
        optionpath="deploy/"+serviceid+"/"+optionname+"/"+optionname+".json"
        status,statusmessage,stepput=datafile.write_s3_file(optionpath,stepjson)
        if status == "error":
            message={"statusCode":400,"errorMessage":statusmessage}
            return(message)
        message={"statusCode":200,"body":task}
        return(message)
    except Exception as e:
        message={"statusCode":400,"errorMessage":str(e)}
        return(message)
예제 #2
0
def createdeploy(productid,serviceid):
    try:
        templatepath="/home/app/web/archeplay/template"
        servicepath= "services/"+productid+"/services.json"
        status,statusmessage,services=datafile.load_s3_file(servicepath)
        if status == "error":
            message={"statusCode":400,"errorMessage":statusmessage,"Error":services}
            return(message)
        for svc in services:
            if svc["serviceid"] == serviceid:
                servicetype=svc["servicetype"]
                svc["status"]="published"
        writestatus,writestatusmessage,srvswrite=datafile.write_s3_file(servicepath,services)
        if writestatus == "error":
            message={"statusCode":400,"errorMessage":writestatusmessage,"Error":srvswrite}
            return(message)
        svctemplatepath=templatepath+"/servicetemplates/"+servicetype+".json"
        with open(svctemplatepath,"r") as f:
            stepdata=f.read()
            stepjson=json.loads(stepdata)
        optionname=stepjson["optionname"]
        optionjson=getfiles(stepjson,serviceid,templatepath)
        optionpath="deploy/"+serviceid+"/"+optionname+"/"+optionname+".json"
        status,statusmessage,optionput=datafile.write_s3_file(optionpath,optionjson)
        if status == "success":
            message={"statusCode":200,"body":optionjson}
        else:
            message={"statusCode":400,"errorMessage":optionput}
        return(message)
    except Exception as e:
        message={"statusCode":400,"errorMessage":str(e)}
        return(message)
예제 #3
0
def createtable(serviceid, dbid):
    iop = {"tablename": ""}
    tablename = request.json["tablename"]
    json_dict = request.get_json()
    dbpath = "servicedesigns/" + serviceid + "/data/" + dbid + "/config.json"
    status, statusmessage, database = datafile.load_s3_file(dbpath)
    if status == "success":
        if database["tables"] == []:
            tableid = uniqid("tb")
        elif database["tables"] != []:
            a = True
            while a is True:
                tableid = uniqid('tb')
                if tableid in database["tables"]:
                    a = True
                else:
                    a = False
        database["tables"].append(tableid)
        status, statusmessage, response = datafile.write_s3_file(
            dbpath, database)
        tablejson = {
            "tableid": tableid,
            "tablename": tablename,
            "dbtype": database["DBType"],
            "schema": [],
            "indexes": {}
        }
        if "description" in json_dict:
            tablejson["description"] = request.json["description"]
        tablepath = "servicedesigns/" + serviceid + "/data/" + dbid + "/tables/" + tableid + "/config.json"
        status, statusmessage, table = datafile.write_s3_file(
            tablepath, tablejson)
        if status == "success":
            message = {
                "statusCode": 200,
                "message": "Table Created",
                "body": tablejson
            }
        else:
            message = {
                "statusCode": 400,
                "errorMessage": statusmessage,
                "Error": table
            }
    else:
        message = {
            "statusCode": 400,
            "errorMessage": statusmessage,
            "Error": database
        }
    return (message)
예제 #4
0
def createdb(serviceid, versionid, resourceid):
    json_dict = request.get_json()
    resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
    status, statusmessage, resource = datafile.load_s3_file(resourcepath)
    if status == "success":
        for data in resource["data"]:
            if data["db"] == []:
                dbid = uniqid("db")
                db = {"Ref": dbid}
                data["db"].append(db)
            elif data["db"] != []:
                dbids = []
                for db in data["db"]:
                    dbids.append(db["Ref"])
                a = True
                while a is True:
                    dbid = uniqid('db')
                    if dbid in dbids:
                        a = True
                    else:
                        a = False
                db = {"Ref": dbid}
                data["db"].append(db)
        resstatus, resstatusmessage, res = datafile.write_s3_file(
            resourcepath, resource)
        dbjson = {
            "dbid": dbid,
            "CreateType": "IMPORT|NEW",
            "import": {
                "Ref": dbid
            },
            "DBType": "DYNAMODB",
            "type": "dynamodb",
            "deploy": {
                "type": "mock"
            },
            "tables": []
        }
        if "description" in json_dict:
            dbjson["description"] = request.json["description"]
        datapath = "servicedesigns/" + serviceid + "/data/" + dbid + "/config.json"
        status, statusmessage, response = datafile.write_s3_file(
            datapath, dbjson)
        if status == "success":
            message = {"statusCode": 200, "body": dbjson}
        else:
            message = {"statusCode": 400, "errorMessage": statusmessage}
    else:
        message = {"errorMessage": statusmessage, "Error": resource}
    return (message)
예제 #5
0
def addtestcases(productid, serviceid, apiid, versionid, resourceid):
    testcasename = request.json["testcasename"]
    testcaseid = uniqid("tc_")
    methodid = request.json["methodid"]
    methodpath = request.json["methodpath"]
    methodtype = request.json["methodtype"]
    testcasedata = {
        "body": "",
        "pathparameters": {},
        "queryparameters": "",
        "headers": "",
        "testcasename": testcasename,
        "testcaseid": testcaseid,
        "methodid": methodid,
        "methodpath": methodpath,
        "methodtype": methodtype
    }
    testcasepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/testcases/" + methodid + "/" + testcaseid + ".json"
    testcasestatus, testcasestatusmessage, testres = datafile.write_s3_file(
        testcasepath, testcasedata)
    if testcasestatus == "success":
        message = {"statusCode": 200, "body": testcasedata}
    else:
        message = {"statusCode": 400, "errorMessage": testres}
    return (message)
예제 #6
0
def deleteresource(productid, serviceid, apiid, versionid, resourceid):
    apipath = "servicedesigns/" + serviceid + "/api/config.json"
    status, statusmessage, api = datafile.load_s3_file(apipath)
    if status == "success":
        for ver in api['versions']:
            if ver["versionid"] == versionid:
                if resourceid in ver["resources"]:
                    resourceprefix = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid
                    delstatus, statusmessage = datafile.delete_folders(
                        resourceprefix)
                    ver["resources"].remove(resourceid)
                    status, statusmessage, response = datafile.write_s3_file(
                        apipath, api)
                    if delstatus == "success" and status == "success":
                        message = {
                            "statusCode": 200,
                            "message": "resource deleted"
                        }
                    else:
                        message = {
                            "statusCode": 400,
                            "errorMessage": "resource deletion failed"
                        }
                else:
                    message = {
                        "statusCode": 400,
                        "errorMessage": "resourceid does not exist"
                    }
    else:
        message = {"statusCode": 400, 'errorMessage': api}
    return (message)
예제 #7
0
def deletemethod(productid, serviceid, apiid, versionid, resourceid, methodid):
    resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
    status, statusmessage, resource = datafile.load_s3_file(resourcepath)
    if status == "success":
        methodids = []
        for method in resource["methods"]:
            methodids.append(method["Ref"])
        if methodid in methodids:
            for method in resource["methods"]:
                if method["Ref"] == methodid:
                    resource["methods"].remove(method)
                    resstatus, resstatusmessage, res = datafile.write_s3_file(
                        resourcepath, resource)
            methodprefix = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid
            methodpath = methodprefix + ".json"
            status, statusmessage, delmeth = datafile.delete_s3_file(
                methodpath)
            delstatus, delstatusmessage = datafile.delete_folders(methodprefix)
            if status == "success" and delstatus == "success":
                message = {"statusCode": 200, "message": "method deleted"}
            else:
                message = {"statusCode": 400, "message": delstatusmessage}
        else:
            message = {"statusCode": 400, "message": "methodid does not exist"}
    else:
        message = {"errorMessage": statusmessage, "Error": resource}
    return (message)
예제 #8
0
def deleteversion(productid, serviceid, apiid, versionid):
    apipath = "servicedesigns/" + serviceid + "/api/config.json"
    status, statusmessage, api = datafile.load_s3_file(apipath)
    if status == "success":
        versionids = []
        for version in api["versions"]:
            versionids.append(version["versionid"])
        if versionid in versionids:
            for version in api["versions"]:
                if version["versionid"] == versionid:
                    api["versions"].remove(version)
                    status, statusmessage, response = datafile.write_s3_file(
                        apipath, api)
                    versionprefix = "servicedesigns/" + serviceid + "/api/" + versionid
                    delstatus, delstatusmessage = datafile.delete_folders(
                        versionprefix)
            message = {"statusCode": 200, "message": "Version Deleted"}
        else:
            message = {
                "statusCode": 400,
                "errorMessage": "versionid does not exist"
            }
    else:
        message = {"errorMessage": statusmessage, "Error": api}
    return (message)
예제 #9
0
def updateservicebyid(productid, serviceid):
    servicepath = "services/" + productid + "/services.json"
    status, statusmessage, services = datafile.load_s3_file(servicepath)
    if status == "success":
        serviceids = []
        for svc in services:
            serviceids.append(svc["serviceid"])
        if serviceid in serviceids:
            service = {}
            for svc in services:
                if svc["serviceid"] == serviceid:
                    svc["status"] = "design"
                    service = svc
            status, statusmessage, writeservice = datafile.write_s3_file(
                servicepath, services)
            if status == "error":
                message = {"statusCode": 400, "errorMessage": statusmessage}
                return (message)
            message = {"statusCode": 200, "body": service}
        else:
            message = {
                "statusCode": 400,
                "errorMessage": "serviceid does not exist"
            }
    else:
        message = {"statusCode": 400, "errorMessage": services}
    return (message)
예제 #10
0
def deleteservice(productid, serviceid):
    servicepath = "services/" + productid + "/services.json"
    status, statusmessage, services = datafile.load_s3_file(servicepath)
    if status == "success":
        serviceids = []
        for svc in services:
            serviceids.append(svc["serviceid"])
        if serviceid in serviceids:
            for svc in services:
                if svc["serviceid"] == serviceid:
                    services.remove(svc)
                    svcprefix = "servicedesigns/" + serviceid
                    delstatus, delstatusmessage = datafile.delete_folders(
                        svcprefix)
            status, statusmessage, response = datafile.write_s3_file(
                servicepath, services)
            message = {"statusCode": 200, 'message': 'Service Deleted'}
        else:
            message = {
                "statusCode": 400,
                "errorMessage": "serviceid does not exist"
            }
    else:
        message = {"errorMessage": statusmessage, "Error": services}
    return (message)
예제 #11
0
def deletetable(serviceid, dbid, tableid):
    dbpath = "servicedesigns/" + serviceid + "/data/" + dbid + "/config.json"
    status, statusmessage, data = datafile.load_s3_file(dbpath)
    if status == "success":
        if tableid in data["tables"]:
            tablepathprefix = "servicedesigns/" + serviceid + "/data/" + dbid + "/tables/" + tableid
            data["tables"].remove(tableid)
            status, statusmessage = datafile.delete_folders(tablepathprefix)
            datastatus, datamessage, datawrite = datafile.write_s3_file(
                dbpath, data)
            if status == "success":
                message = {"statusCode": 200, "message": "Table Deleted"}
            else:
                message = {
                    "statusCode": 400,
                    "errorMessage": "Table deletion failed"
                }
        else:
            message = {
                "statusCode": 400,
                "errorMessage": "tableid does not exist"
            }
    else:
        message = {"errorMessage": statusmessage, "Error": data}
    return (message)
예제 #12
0
def createresource(productid, serviceid, apiid, versionid):
    iop = {"resourcename": ""}
    resourcename = request.json["resourcename"]
    apipath = "servicedesigns/" + serviceid + "/api/config.json"
    status, statusmessage, api = datafile.load_s3_file(apipath)
    if status == "success":
        for ver in api['versions']:
            if ver['versionid'] == versionid:
                version = ver
                a = True
                while a is True:
                    resourceid = uniqid('res')
                    if resourceid in ver["resources"]:
                        a = True
                    else:
                        a = False
                resource = {
                    "resourceid": resourceid,
                    "resourcename": resourcename,
                    "methods": [],
                    "data": [{
                        "db": []
                    }]
                }
                version['resources'].append(resourceid)
                status, statusmessage, response = datafile.write_s3_file(
                    apipath, api)
                resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
                status, statusmessage, resources = datafile.write_s3_file(
                    resourcepath, resource)
                message = {
                    "statusCode": 200,
                    'message': "Resource Created",
                    'body': resource
                }
            else:
                message = {
                    "statusCode": 400,
                    'message': "versionid does not exist"
                }
    else:
        message = {
            "statusCode": 400,
            'message': statusmessage,
            'errorMessage': api
        }
    return (message)
예제 #13
0
def updatetable(serviceid, dbid, tableid):
    json_dict = request.get_json()
    tablepath = "servicedesigns/" + serviceid + "/data/" + dbid + "/tables/" + tableid + "/config.json"
    status, statusmessage, table = datafile.load_s3_file(tablepath)
    if status == "success":
        if "addschema" in json_dict:
            for sch in request.json['addschema']:
                if all(sch['attributename'] != tbh['attributename']
                       for tbh in table['schema']):
                    table['schema'].append(sch)
            # table['schema']=table['schema']+request['addschema']
        if "deleteschema" in json_dict:
            for sch in request.json['deleteschema']:
                for schema in table['schema']:
                    if sch['attributename'] == schema['attributename']:
                        if sch['attributename'] not in str(table['indexes']):
                            table['schema'].remove(schema)
        if "editschema" in json_dict:
            for schema in table['schema']:
                for sch in request.json['editschema']:
                    if sch['attributename'] == schema['attributename']:
                        table['schema'][table['schema'].index(schema)] = sch
        if "indexes" in json_dict:
            table['indexes'] = request.json['indexes']
        if "updatepath" in json_dict:
            request.json['updatevalue'] = json.loads(
                request.json['updatevalue'])
            path = request.json['updatepath'].split("/")
            myd = table
            for i in path[:-1]:
                myd = myd[i]
            if "[" in path[-1]:
                path[-1] = path[-1].replace("]", "")
                p = path[-1].split("[")
                if p[0] not in myd:
                    myd[p[0]] = []
                if int(p[1]) >= len(myd[p[0]]):
                    myd[p[0]].append(request.json['updatevalue'])
                else:
                    myd[p[0]][int(p[1])] = request.json['updatevalue']
            else:
                myd[path[-1]] = request.json['updatevalue']
        status, statusmessage, response = datafile.write_s3_file(
            tablepath, table)
        if status == "success":
            message = {"statusCode": 200, "body": table}
        else:
            message = {"statusCode": 400, "errorMessage": statusmessage}
    else:
        message = {"errorMessage": statusmessage, "Error": table}
    return (message)
예제 #14
0
def template_pull():
    iop = {
        "connectiontype": "",
        "templategiturl": "",
        "templategitpassword": "",
        "templategitusername": "",
        "templategitbranch": ""
    }
    connectiontype = request.json["connectiontype"]
    templategiturl = request.json["templategiturl"]
    templategitpassword = request.json["templategitpassword"]
    templategitusername = t = request.json["templategitusername"]
    branch = request.json["templategitbranch"]
    try:
        machine = templategiturl.split("/")[2]
        gitcred = "machine " + machine + " login " + templategitusername + " password " + templategitpassword + "\n"
        secretpath = os.getenv("NETRC")
        datawrite = writefile(secretpath, gitcred)
        destinationpath = "/home/app/.netrc"
        directory = os.path.dirname(destinationpath)
        if not os.path.exists(directory):
            os.makedirs(directory)
        copyfile(secretpath, destinationpath)
        folderpath = "/home/app/web/archeplay/template"
        archetemplatepath = "/home/app/web/archeplay/" + uniqid(
            "localtemplate")
        status, statusmessage = template_clone(templategiturl, branch,
                                               folderpath, archetemplatepath,
                                               templategitusername)
        if status == "error":
            message = {"statusCode": 400, "errormessage": statusmessage}
            return (message)
        templatecred = {
            "connectiontype": connectiontype,
            "templategiturl": templategiturl,
            "templategitpassword": templategitpassword,
            "templategitusername": templategitusername,
            "templategitbranch": branch
        }
        templaterepoconfigpath = "templateconfig/config.json"
        status, statusmessage, templaterepoconf = datafile.write_s3_file(
            templaterepoconfigpath, templatecred)
        if status == "error":
            message = {"statusCode": 400, "errorMessage": "write error"}
            return (message)
        message = {"statusCode": 200, "message": "template git cloned"}
        return (message)
    except Exception as e:
        message = {"statusCode": 400, "errorMessage": "final error"}
        return (message)
예제 #15
0
def updatemethod(productid, serviceid, apiid, versionid, resourceid, methodid):
    json_dict = request.get_json()
    methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
    status, statusmessage, method = datafile.load_s3_file(methodpath)
    req_string = ""
    if status == "success":
        snippetid = request.json["snippetid"]
        if "inputschema" in json_dict:
            method['inputschema'] = request.json['inputschema']
        if "outputschema" in json_dict:
            method['outputschema'] = request.json['outputschema']
        if "requirements" in json_dict:
            method["snippets"][snippetid]['requirements'] = request.json[
                'requirements']
        if "import_code" in json_dict:
            method["snippets"][snippetid]["import_code"] = request.json[
                "import_code"]
        if "function_code" in json_dict:
            method["snippets"][snippetid]["function_code"] = request.json[
                "function_code"]
        if "function_call" in json_dict:
            method["snippets"][snippetid]["function_call"] = request.json[
                "function_call"]
        if "data_code" in json_dict:
            method["snippets"][snippetid]["data_code"] = request.json[
                "data_code"]
        codestring, requirements = consolidate_code(method)
        # codestring=method["snippets"][snippetid]["import_code"]+"\n"+method["snippets"][snippetid]["data_code"]+"\n"+method["snippets"][snippetid]["function_code"]+"\n"+method["snippets"][snippetid]["function_call"] + "\n" +method["type_code"]
        codepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/" + methodid + ".py"
        codestatus, codestatusmessage, code = datafile.write_txt_file(
            codepath, codestring)
        for requirement in requirements:
            req_string = req_string + requirement + '\n'
            requirementpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/requirement.txt"
            reqwritestatus, reqwritestatusmessage, req = datafile.write_txt_file(
                requirementpath, req_string)
        writestatus, statusmessage, response = datafile.write_s3_file(
            methodpath, method)
        if writestatus == "success" and codestatus == "success":
            message = {
                "statusCode": 200,
                'body': method["snippets"][snippetid]
            }
        else:
            message = {"statusCode": 400, "errorMessage": response}
    else:
        message = {"errorMessage": statusmessage, "Error": method}
    return (message)
예제 #16
0
def deletesnippet(productid, serviceid, apiid, versionid, resourceid, methodid,
                  snippetid):
    methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
    status, statusmessage, methodjson = datafile.load_s3_file(methodpath)
    del methodjson["snippets"][snippetid]
    snippetorder = methodjson["snippets"]["snippetorder"]
    count = 0
    for item in snippetorder:
        if item["snippetid"] == snippetid:
            break
        else:
            count = count + 1
    snippetorder.pop(count)
    methodjson["snippets"].update({"snippetorder": snippetorder})
    methodjson["methodpath"] = methodjson["methodpath"].replace("{", "<")
    methodjson["methodpath"] = methodjson["methodpath"].replace("}", ">")
    # if methodjson["methodpath"]!="":
    # 	apicallpath="/"+versionname+"/"+resource["resourcename"]+methodjson["methodpath"]
    # else:
    # 	apicallpath="/"+versionname+"/"+resource["resourcename"]
    # methodpath="servicedesigns/"+serviceid+"/api/"+versionid+"/resources/"+resourceid+"/methods/"+methodid+".json"
    # methodjson["type_code"]=methodjson["type_code"].replace("METHODID",methodid)
    # methodjson["type_code"]=methodjson["type_code"].replace("METHODPATH",apicallpath)
    codestring, requirement = consolidate_code(methodjson)
    codepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/" + methodid + ".py"
    codestatus, codestatusmessage, code = datafile.write_txt_file(
        codepath, codestring)
    if codestatus == "error":
        message = {"statusCode": 400, "errorMessage": code}
        return (message)
    reqstring = ""
    for i in requirement:
        reqstring = reqstring + i + "\n"
    # act["requirements"]=reqstring
    requirementpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/requirement.txt"
    requirementstatus, requirementstatusmessage, req = datafile.write_txt_file(
        requirementpath, reqstring)
    if requirementstatus == "error":
        message = {"statusCode": 400, "errorMessage": req}
        return (message)
    methstatus, methstatusmessage, methres = datafile.write_s3_file(
        methodpath, methodjson)
    if methstatus == "error":
        message = {"statusCode": 400, "errorMessage": code}
        return (message)
    if methstatus == "success" and codestatus == "success" and requirementstatus == "success":
        message = {"statusCode": 200, "body": methodjson}
    return (message)
예제 #17
0
def design_push():
    iop = {"commitmessage": "", "tagname": ""}
    try:
        coderepoconfigpath = "repoconfig/config.json"
        status, statusmessage, codecred = datafile.load_s3_file(
            coderepoconfigpath)
        if status == "error":
            message = {
                "statusCode": 400,
                "errorMessage": statusmessage,
                "Error": codecred
            }
            return (message)
        branch = codecred["mybranch"]["Branchname"]
        foldername = codecred["mybranch"]["Name"]
        gitrepourl = codecred["gitrepourl"]
        gitusername = codecred["gitusername"]
        commitmessage = request.json["commitmessage"]
        tagname = request.json["tagname"]
        srcfolder = "/home/app/web/archeplay/data"
        destfolder = "/home/app/web/archeplay/" + foldername
        copy_tree(srcfolder, destfolder)
        output_files = glob.glob(destfolder + "/**/*output.json",
                                 recursive=True)
        for file in output_files:
            os.remove(file)
        log_files = glob.glob(destfolder + "/**/*log.json", recursive=True)
        for file in log_files:
            os.remove(file)
        status, statusmessage = git_push(destfolder, gitrepourl, branch,
                                         gitusername, destfolder,
                                         commitmessage, tagname)
        if status == "error":
            message = {"statusCode": 400, "errorMessage": statusmessage}
            return (message)
        codecred["mybranch"]["Tags"].append(tagname)
        writestatus, writestatusmessage, mybranchtag = datafile.write_s3_file(
            coderepoconfigpath, codecred)
        if writestatus == "error":
            message = {"statusCode": 400, "errorMessage": writestatusmessage}
            return (message)
        message = {"statusCode": 200, "message": statusmessage}
        return (message)
    except Exception as e:
        message = {"statusCode": 400, "errorMessage": str(e)}
        return (message)
예제 #18
0
def createproduct():
    iop = {"userid": "", "productname": ""}
    userid = request.headers["userid"]
    productname = request.json["productname"]
    json_dict = request.get_json()
    productpath = "products/products.json"
    status, statusmessage, products = datafile.load_s3_file(productpath)
    if status != "success":
        products = []
    productids = []
    for prod in products:
        productids.append(prod["productid"])
    a = True
    while a is True:
        productid = uniqid('prod')
        if productid in productids:
            a = True
        else:
            a = False
    product = {
        'productid': productid,
        'userid': userid,
        'productname': productname
    }
    if "description" in json_dict:
        product["description"] = request.json["description"]
    products.append(product)
    status, statusmessage, response = datafile.write_s3_file(
        productpath, products)
    if status == "success":
        message = {
            "statusCode": 200,
            "message": "New Product Created",
            "body": product
        }
    else:
        message = {
            "statusCode": 400,
            "errorMessage": statusmessage,
            "Error": response
        }
    return (message)
예제 #19
0
def store_cred():
    try:
        coderepoconfigpath = "repoconfig/config.json"
        connectiontype = request.json["connectiontype"]
        gitrepourl = request.json["gitrepourl"]
        gitusername = request.json["gitusername"]
        gitpassword = request.json["gitpassword"]
        codecred = {
            "connectiontype": connectiontype,
            "gitrepourl": gitrepourl,
            "gitusername": gitusername,
            "gitpassword": gitpassword,
            "mybranch": {},
            "sharedbranch": [],
            "environmentdeploybranch": []
        }
        machine = gitrepourl.split("/")[2]
        gitcred = "machine " + machine + " login " + gitusername + " password " + gitpassword + "\n"
        status, statusmessage, coderepoconf = datafile.write_s3_file(
            coderepoconfigpath, codecred)
        if status == "error":
            message = {"statusCode": 400, "errorMessage": coderepoconf}
            return (message)
        secretpath = os.getenv("NETRC")
        datawrite = writefile(secretpath, gitcred)
        destinationpath = "/home/app/.netrc"
        directory = os.path.dirname(destinationpath)
        if not os.path.exists(directory):
            os.makedirs(directory)
        copyfile(secretpath, destinationpath)
        message = {
            "statusCode": 200,
            "message": "credentials added",
            "body": codecred
        }
        return (message)
    except Exception as e:
        message = {"statusCode": 400, "errorMessage": str(e)}
        return (message)
예제 #20
0
def deletedata(serviceid, versionid, resourceid, dbid):
    resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
    status, statusmessage, resource = datafile.load_s3_file(resourcepath)
    if status == "success":
        for data in resource["data"]:
            if data["db"] != []:
                dbids = []
                for db in data["db"]:
                    dbids.append(db["Ref"])
                if dbid in dbids:
                    for db in data["db"]:
                        if db["Ref"] == dbid:
                            data["db"].remove(db)
                            status, statusmessage, response = datafile.write_s3_file(
                                resourcepath, resource)
                    datapath = "servicedesigns/" + serviceid + "/data/" + dbid + "/config.json"
                    delstatus, delstatusmessage, delres = datafile.delete_s3_file(
                        datapath)
                    datapathprefix = "servicedesigns/" + serviceid + "/data/" + dbid
                    delstatus, delstatusmessage = datafile.delete_folders(
                        datapathprefix)
                    message = {
                        "statusCode": 200,
                        "message": "database deleted"
                    }
                else:
                    message = {
                        "statusCode": 400,
                        "errorMessage": "dbid does not exist"
                    }
            else:
                message = {
                    "statusCode": 400,
                    "errorMessage": "no database present"
                }
    else:
        message = {"errorMessage": statusmessage, "Error": resource}
    return (message)
예제 #21
0
def createversion(productid, serviceid, apiid):
    iop = {"versionname": ""}
    versionname = request.json["versionname"]
    json_dict = request.get_json()
    apipath = "servicedesigns/" + serviceid + "/api/config.json"
    status, statusmessage, api = datafile.load_s3_file(apipath)
    if status == "success":
        version = {
            'versionname': versionname,
            'versionid': uniqid('v-'),
            'resources': []
        }
        if 'description' in json_dict:
            version['description'] = request.json['description']
        api['versions'].append(version)
        writestatus, writestatusmessage, response = datafile.write_s3_file(
            apipath, api)
        if writestatus == "success":
            message = {"statusCode": 200, "body": api}
        else:
            message = {"errorMessage": writestatusmessage, "Error": response}
    else:
        message = {"errorMessage": statusmessage, "Error": api}
    return (message)
예제 #22
0
def updatetestcases(productid, serviceid, apiid, versionid, resourceid,
                    methodid, testcaseid):
    json_dict = request.get_json()
    testcasepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/testcases/" + methodid + "/" + testcaseid + ".json"
    status, statusmessage, testcase = datafile.load_s3_file(testcasepath)
    if status == "success":
        if "body" in json_dict:
            testcase["body"] = request.json["body"]
        if "headers" in json_dict:
            testcase["headers"] = request.json["headers"]
        if "pathparameters" in json_dict:
            testcase["pathparameters"] = request.json["pathparameters"]
        if "queryparameters" in json_dict:
            testcase["queryparameters"] = request.json["queryparameters"]
        if "testcasename" in json_dict:
            testcase["testcasename"] = request.json["testcasename"]
    testcasepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/testcases/" + methodid + "/" + testcaseid + ".json"
    testcasestatus, testcasestatusmessage, testres = datafile.write_s3_file(
        testcasepath, testcase)
    if testcasestatus == "success":
        message = {"statusCode": 200, "body": testcase}
    else:
        message = {"statusCode": 400, "errorMessage": testres}
    return (message)
예제 #23
0
def deleteproduct(productid):
    productpath = "products/products.json"
    status, statusmessage, products = datafile.load_s3_file(productpath)
    if status == "success":
        productids = []
        for prod in products:
            productids.append(prod["productid"])
        if productid in productids:
            for prod in products:
                if prod["productid"] == productid:
                    products.remove(prod)
            status, statusmessage, response = datafile.write_s3_file(
                productpath, products)
            prodprefix = "services/" + productid
            delstatus, delmessage = datafile.delete_folders(prodprefix)
            message = {"statusCode": 200, 'message': 'Product Deleted'}
        else:
            message = {
                "statusCode": 400,
                "errorMessage": "productid does not exist"
            }
    else:
        message = {"statusCode": 400, "errorMessage": products}
    return (message)
예제 #24
0
def publish_push(serviceid, optionname):
    iop = {"commitmessage": "", "Branchname": "", "Name": ""}
    try:
        commitmessage = request.json["commitmessage"]
        branch = request.json["Branchname"]
        foldername = request.json["Name"]
        coderepoconfigpath = "repoconfig/config.json"
        status, statusmessage, codecred = datafile.load_s3_file(
            coderepoconfigpath)
        if status == "error":
            message = {
                "statusCode": 400,
                "errorMessage": statusmessage,
                "Error": codecred
            }
            return (message)
        gitrepourl = codecred["gitrepourl"]
        gitusername = codecred["gitusername"]

        ###commands###
        pullcommand = "git clone -b " + branch + " " + gitrepourl + " archedeploy\nexport CLONE_PATH=$PWD/archedeploy"
        optionpath = "deploy/" + serviceid + "/" + optionname + "/" + optionname + ".json"
        status, statusmessage, optionjson = datafile.load_s3_file(optionpath)
        if status == "error":
            message = {"statusCode": 400, "errorMessage": statusmessage}
            return (message)
        createshcommand = "bash " + "$CLONE_PATH/deploy/" + serviceid + "/" + optionname + "/createscript.sh"
        updateshcommand = "bash " + "$CLONE_PATH/deploy/" + serviceid + "/" + optionname + "/updatescript.sh"
        deleteshcommand = "bash " + "$CLONE_PATH/deploy/" + serviceid + "/" + optionname + "/deletescript.sh"
        finalstep = {
            "deploy": {
                "description":
                "Run the command below to deploy resources",
                "tasks": [{
                    "taskno": 1.0,
                    "description": "Clone Code repo",
                    "taskname": "Clone",
                    "initscript": pullcommand
                }, {
                    "taskno": 2.0,
                    "description": "Deploy the resources",
                    "taskname": "Deploy",
                    "initscript": createshcommand
                }, {
                    "taskno": 3.0,
                    "description": "Update the resources",
                    "taskname": "UpdateDeploy",
                    "initscript": updateshcommand
                }, {
                    "taskno": 4.0,
                    "description": "Delete the resources",
                    "taskname": "Deletedeploy",
                    "initscript": deleteshcommand
                }]
            }
        }
        optionjson[optionname] = finalstep
        status, statusmessage, writeoptionjson = datafile.write_s3_file(
            optionpath, optionjson)
        if status == "error":
            message = {"statusCode": 400, "errorMessage": statusmessage}
            return (message)

        ###pushing to git####
        srcfolder = "/home/app/web/archeplay/data"
        destfolder = "/home/app/web/archeplay/" + foldername
        pushfolder = "deploy/*"
        copy_tree(srcfolder, destfolder)
        count = 1
        push = True
        while push:
            tagname = serviceid + ".v" + str(count)
            status, statusmessage = git_push(destfolder, gitrepourl, branch,
                                             gitusername, pushfolder,
                                             commitmessage, tagname)
            if status == "success":
                push = False
            else:
                if "already exists" in statusmessage:
                    count = count + 1
                else:
                    message = {
                        "statusCode": 400,
                        "errorMessage": statusmessage
                    }
                    return (message)
        message = {"statusCode": 200, "body": optionjson}
        return (message)
    except Exception as e:
        message = {"statusCode": 400, "errorMessage": str(e)}
        return (message)
예제 #25
0
def shared_design_push(productid, serviceid):
    iop = {
        "commitmessage": "",
        "Branchname": "",
        "Name": "",
        "SourceBranchName": "",
        "SourceName": "",
        "Tag": ""
    }
    try:
        commitmessage = request.json["commitmessage"]
        branch = request.json["Branchname"]
        foldername = request.json["Name"]
        sourcebranch = request.json["SourceBranchName"]
        sourcefoldername = request.json["SourceName"]
        Tag = request.json["Tag"]
        coderepoconfigpath = "repoconfig/config.json"
        status, statusmessage, codecred = datafile.load_s3_file(
            coderepoconfigpath)
        if status == "error":
            message = {
                "statusCode": 400,
                "errorMessage": statusmessage,
                "Error": codecred
            }
            return (message)
        gitrepourl = codecred["gitrepourl"]
        gitusername = codecred["gitusername"]

        ##pulling source tag
        localsorcepath = "/home/app/web/archeplay/" + uniqid("localgit")
        repo = git.Repo.clone_from(gitrepourl,
                                   localsourcepath,
                                   branch=sourcebranch)
        repo.config_writer().set_value("user", "name", gitusername).release()
        repo.config_writer().set_value("user", "email", gitusername).release()
        giturl = repo.git
        giturl.pull('origin', sourcebranch, '--allow-unrelated-histories')
        giturl.checkout('tags/' + Tag)

        ###copying product json###
        productpath = localsourcepath + "/products/products.json"
        prodstatus, prodstatusmessage, products = datafile.load_copy_file(
            productpath)
        if prodstatus == "error":
            message = {
                "statusCode": 400,
                "errormessage": prodstatusmessage,
                "Error": products
            }
            return (message)
        copyproductpath = "/home/app/web/archeplay/" + foldername + "/products/products.json"
        prodstatus, prodstatusmessage, copyproduct = datafile.load_copy_file(
            copyproductpath)
        if prodstatus == "error":
            copyproduct = []
        for prod in products:
            if prod["productid"] == productid:
                copyproduct.append(prod)
        copyproductpath = "/home/app/web/archeplay/" + foldername + "/products/products.json"
        prodstatus, prodstatusmessage, copyprod = datafile.write_copy_file(
            copyproductpath, copyproduct)
        if prodstatus == "error":
            message = {
                "statusCode": 400,
                "errorMessage": prodstatusmessage,
                "Error": copyprod
            }
            return (message)

        ###copying service json#####
        servicepath = localsourcepath + "/services/" + productid + "/services.json"
        srvstatus, srvstatusmessage, services = datafile.load_copy_file(
            servicepath)
        if srvstatus == "error":
            message = {
                "statusCode": 400,
                "errorMessage": srvstatusmessage,
                "Error": services
            }
            return (message)
        copyservicepath = "/home/app/web/archeplay/" + foldername + "/services/" + productid + "/services.json"
        svcstatus, svcstatusmessage, copyservice = datafile.load_copy_file(
            copyservicepath)
        if svcstatus == "error":
            copyservice = []
        for svc in services:
            if svc["serviceid"] == serviceid:
                copyservice.append(svc)
        copyservicepath = "/home/app/web/archeplay/" + foldername + "/services/" + productid + "/services.json"
        svcstatus, svcstatusmessage, copysvc = datafile.write_copy_file(
            copyservicepath, copyservice)
        if svcstatus == "error":
            message = {
                "statusCode": 400,
                "errorMessage": svcstatusmessage,
                "Error": copysvc
            }
            return (message)

        ###copying design data###
        designdatapath = localsourcepath + "/servicedesigns/" + serviceid
        destfolder = "/home/app/web/archeplay/" + foldername + "/servicedesigns/" + serviceid
        directory = os.path.dirname(destfolder)
        if not os.path.exists(directory):
            os.makedirs(directory)
        copy_tree(designdatapath, destfolder)

        ###copying repoconfig####
        coderepoconfigpath = localsourcepath + "/repoconfig/config.json"
        destpath = "/home/app/web/archeplay/" + foldername + "/repoconfig/config.json"
        directory = os.path.dirname(destpath)
        if not os.path.exists(directory):
            os.makedirs(directory)
        copyfile(coderepoconfigpath, destpath)

        ###copying templateconfig####
        templaterepoconfigpath = localsourcepath + "/templateconfig/config.json"
        destpath = "/home/app/web/archeplay/" + foldername + "/templateconfig/config.json"
        directory = os.path.dirname(destpath)
        if not os.path.exists(directory):
            os.makedirs(directory)
        copyfile(templaterepoconfigpath, destpath)

        ###pushing to git###
        pushfolder = "/home/app/web/archeplay/" + foldername
        output_files = glob.glob(pushfolder + "/**/*output.json",
                                 recursive=True)
        for file in output_files:
            os.remove(file)
        log_files = glob.glob(pushfolder + "/**/*log.json", recursive=True)
        for file in log_files:
            os.remove(file)
        count = 1
        push = True
        while push:
            tagname = serviceid + ".v" + str(count)
            status, statusmessage = git_push(pushfolder, gitrepourl, branch,
                                             gitusername, pushfolder,
                                             commitmessage, tagname)
            if status == "success":
                for svc in services:
                    if svc["serviceid"] == serviceid:
                        svc["tagnames"].append(tagname)
                        svc["Branchname"] = branch
                        svc["Name"] = foldername
                srvstatus, srvstatusmessage, svcupdate = datafile.write_s3_file(
                    servicepath, services)
                if srvstatus == "error":
                    message = {
                        "statusCode": 400,
                        "errorMessage": srvstatusmessage,
                        "Error": svcupdate
                    }
                    return (message)
                copysvcstatus, copysvcstatusmessage, copysvc = datafile.load_copy_file(
                    copyservicepath)
                if copysvcstatus == "error":
                    message = {
                        "statusCode": 400,
                        "errormessage": copysvcstatusmessage
                    }
                    return (message)
                for cpsvc in copysvc:
                    if cpsvc["serviceid"] == serviceid:
                        cpsvc["tagnames"].append(tagname)
                        cpsvc["Branchname"] = branch
                        cpsvc["Name"] = foldername
                writecpsvcstatus, writecpsvcstatusmessage, cpsrvice = datafile.write_copy_file(
                    copyservicepath, copysvc)
                if writecpsvcstatus == "error":
                    message = {
                        "statusCode": 400,
                        "errorMessage": writecpsvcstatusmessage
                    }
                    return (message)
                push = False
            else:
                if "already exists" in statusmessage:
                    count = count + 1
                else:
                    message = {
                        "statusCode": 400,
                        "errorMessage": statusmessage
                    }
                    return (message)
        message = {"statusCode": 200, "message": statusmessage}
        return (message)
    except Exception as e:
        message = {"statusCode": 400, "errorMessage": str(e)}
        return (message)
예제 #26
0
def create_branches():
    iop = {
        "mybranch": {
            "Name": "",
            "Branchname": ""
        },
        "sharedbranch": [{
            "Name": "",
            "Branchname": ""
        }, {
            "Name": "",
            "Branchname": ""
        }],
        "environmentdeploybranch": [{
            "Name": "",
            "Branchname": ""
        }, {
            "Name": "prod",
            "Branchname": ""
        }]
    }
    try:
        branches = request.json["branches"]
        mybranch = branches["mybranch"]
        compsharedbranch = comparelistitems(branches["sharedbranch"])
        if compsharedbranch["statusCode"] == 400:
            return (compsharedbranch)
        compenvbranch = comparelistitems(branches["environmentdeploybranch"])
        if compenvbranch["statusCode"] == 400:
            return (compenvbranch)
        for sharedbranchitem in branches["sharedbranch"]:
            for envbranchitem in branches["environmentdeploybranch"]:
                if sharedbranchitem["Name"] == envbranchitem[
                        "Name"] or sharedbranchitem[
                            "Branchname"] == envbranchitem["Branchname"]:
                    message = {
                        "statusCode":
                        400,
                        "errorMessage":
                        "Not unique name in environmentdeploybranch and sharedbranch"
                    }
                    return (message)
        for sharedbranchitem in branches["sharedbranch"]:
            if sharedbranchitem["Name"] == mybranch["Name"] or sharedbranchitem[
                    "Branchname"] == mybranch["Branchname"]:
                message = {
                    "statusCode": 400,
                    "errorMessage":
                    "Not unique name in mybranch and sharedbranch"
                }
                return (message)
        for envbranchitem in branches["environmentdeploybranch"]:
            if envbranchitem["Name"] == mybranch["Name"] or envbranchitem[
                    "Branchname"] == mybranch["Branchname"]:
                message = {
                    "statusCode":
                    400,
                    "errorMessage":
                    "Not unique name in environmentdeploybranch and mybranch"
                }
                return (message)
        coderepoconfigpath = "repoconfig/config.json"
        status, statusmessage, codecred = datafile.load_s3_file(
            coderepoconfigpath)
        if status == "error":
            message = {"statusCode": 400, "errorMessage": statusmessage}
            return (message)
        gitrepourl = codecred["gitrepourl"]
        gitusername = codecred["gitusername"]
        codecred["mybranch"] = branches["mybranch"]
        codecred["mybranch"]["Tags"] = []
        codecred["sharedbranch"] = branches["sharedbranch"]
        codecred["environmentdeploybranch"] = branches[
            "environmentdeploybranch"]
        secretpath = os.getenv("NETRC")
        destinationpath = "/home/app/.netrc"
        directory = os.path.dirname(destinationpath)
        if not os.path.exists(directory):
            os.makedirs(directory)
        copyfile(secretpath, destinationpath)
        writestatus, writestatusmessage, repoupdatebranch = datafile.write_s3_file(
            coderepoconfigpath, codecred)
        if writestatus == "error":
            message = {"statusCode": 400, "errorMessage": writestatusmessage}
            return (message)
        getbranch = get_branches()
        if getbranch["statusCode"] == 400:
            return (getbranch)
        branchnames = getbranch["body"]
        devdesignbranch = branches["mybranch"]["Branchname"]
        devdesignfoldername = branches["mybranch"]["Name"]
        archepath = "/home/app/web/archeplay"
        archedesignpath = archepath + "/" + devdesignfoldername
        mybranchstatus = create_branch(devdesignbranch, branchnames,
                                       gitrepourl, archedesignpath,
                                       gitusername)
        if mybranchstatus["statusCode"] == 400:
            return (mybranchstatus)
        for sharedbranch in branches["sharedbranch"]:
            branch = sharedbranch["Branchname"]
            sharedfoldername = sharedbranch["Name"]
            folderpath = archepath + "/" + sharedfoldername
            sharedbranchstatus = shared_branch(branch, branchnames, gitrepourl,
                                               folderpath, gitusername)
            if sharedbranchstatus["statusCode"] == 400:
                return (sharedbranchstatus)
        for envbranch in branches["environmentdeploybranch"]:
            branch = envbranch["Branchname"]
            envfoldername = envbranch["Name"]
            folderpath = archepath + "/" + envfoldername
            envbranchstatus = create_branch(branch, branchnames, gitrepourl,
                                            folderpath, gitusername)
            if envbranchstatus["statusCode"] == 400:
                return (envbranchstatus)
        message = {"statusCode": 200, "body": codecred}
        return (message)
    except Exception as e:
        message = {"statusCode": 400, "errorMessage": str(e)}
        return (message)
예제 #27
0
def createservice(productid):
    iop = {
        "servicename": "",
        "description": "",
        "servicetype": "",
        "optionname": ""
    }
    userid = request.headers["userid"]
    servicename = request.json["servicename"]
    servicetype = request.json["servicetype"]
    optionname = request.json["optionname"]
    json_dict = request.get_json()
    servicepath = "services/" + productid + "/services.json"
    status, statusmessage, services = datafile.load_s3_file(servicepath)
    if status != "success":
        services = []
    serviceids = []
    for svc in services:
        serviceids.append(svc["serviceid"])
    a = True
    while a is True:
        serviceid = uniqid('service')
        if serviceid in serviceids:
            a = True
        else:
            a = False
    service = {
        'productid': productid,
        'serviceid': serviceid,
        'userid': userid,
        'servicename': servicename,
        'servicetype': servicetype,
        'optionname': optionname,
        'tagnames': []
    }
    if "description" in json_dict:
        service["description"] = request.json["description"]
    apiid = uniqid('api')
    api = {
        'productid':
        productid,
        'serviceid':
        serviceid,
        'apiid':
        apiid,
        'userid':
        userid,
        'apiname':
        request.json['servicename'],
        'versions': [{
            'versionname': 'v1',
            'versionid': uniqid('v-'),
            'description': 'default version',
            'resources': []
        }],
        'deploy': {
            'cloud': 'aws',
            'deployplatform': 'eks',
            'image': 'docker',
            'imagerepo': 'ecr'
        }
    }
    if 'description' in json_dict:
        api['description'] = request.json['description']
    service['apiid'] = api['apiid']
    services.append(service)
    status, statusmessage, response = datafile.write_s3_file(
        servicepath, services)
    apipath = "servicedesigns/" + serviceid + "/api/config.json"
    statusapi, statusmessageapi, resapi = datafile.write_s3_file(apipath, api)
    if status == "success":
        message = {
            "statusCode": 200,
            'message': 'New Service Created',
            'body': service
        }
    else:
        message = {
            "statusCode": 400,
            'message': statusmessage,
            'Error': response
        }
    return (message)
예제 #28
0
def generatemethod(productid, serviceid, apiid, versionid, resourceid):
    resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
    status, statusmessage, resource = datafile.load_s3_file(resourcepath)
    actions = request.json["actions"]
    versionname = request.json["versionname"]
    methodmessage = getmethod(productid, serviceid, apiid, versionid,
                              resourceid)
    if methodmessage["statusCode"] == 200:
        if methodmessage["body"] != []:
            for method in methodmessage["body"]:
                for action in actions:
                    action["methodpath"] = action["methodpath"].replace(
                        "{", "<")
                    action["methodpath"] = action["methodpath"].replace(
                        "}", ">")
                    if action["methodpath"] == method["methodpath"] and action[
                            "methodtype"] == method["methodtype"]:
                        actions.remove(action)
    else:
        return (methodmessage)
    autopoppulate = {
        "resourceid": resourceid,
        "serviceid": serviceid,
        "versionid": versionid,
        "actions": actions
    }
    actionlist = []
    for act in autopoppulate["actions"]:
        methodid = uniqid("meth")
        act["methodid"] = methodid
        act["methodpath"] = act["methodpath"].replace("{", "<")
        act["methodpath"] = act["methodpath"].replace("}", ">")
        if act["methodpath"] != "":
            apicallpath = "/" + versionname + "/" + resource[
                "resourcename"] + act["methodpath"]
        else:
            apicallpath = "/" + versionname + "/" + resource["resourcename"]
        method = {"Ref": methodid}
        resource["methods"].append(method)
        resstatus, resstatusmessage, res = datafile.write_s3_file(
            resourcepath, resource)
        if resstatus == "error":
            message = {"statusCode": 400, "errorMessage": res}
            return (message)
        methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
        full_code = consolidate_code(act, requirements)
        # act["import_code"]=act["import_code"].replace("METHODID",methodid)
        # act["import_code"]=act["import_code"].replace("METHODPATH",apicallpath)
        # act["function_code"]=act["function_code"].replace("METHODID",methodid)
        # act["function_code"]=act["function_code"].replace("METHODPATH",apicallpath)
        # act["main_code"]=act["main_code"].replace("METHODID",methodid)
        # act["main_code"]=act["main_code"].replace("METHODPATH",apicallpath)
        # act["type_code"]=act["type_code"].replace("METHODID",methodid)
        # act["type_code"]=act["type_code"].replace("METHODPATH",apicallpath)
        # codestring=act["import_code"]+"\n"+act["function_code"]+"\n"+act["main_code"]+"\n"+act["type_code"]
        codepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/" + methodid + ".py"
        codestatus, codestatusmessage, code = datafile.write_txt_file(
            codepath, codestring)
        if codestatus == "error":
            message = {"statusCode": 400, "errorMessage": code}
            return (message)
        requirement = act["requirements"]
        reqstring = ""
        for i in requirement:
            reqstring = reqstring + i + "\n"
        # act["requirements"]=reqstring
        requirementpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/requirement.txt"
        requirementstatus, requirementstatusmessage, req = datafile.write_txt_file(
            requirementpath, reqstring)
        if requirementstatus == "error":
            message = {"statusCode": 400, "errorMessage": req}
            return (message)
        methstatus, methstatusmessage, methres = datafile.write_s3_file(
            methodpath, act)
        if methstatus == "error":
            message = {"statusCode": 400, "errorMessage": code}
            return (message)
        if methstatus == "success" and codestatus == "success" and requirementstatus == "success":
            actionlist.append(act)
    message = {"statusCode": 200, "body": actionlist}
    return (message)
예제 #29
0
def createmethod(productid, serviceid, apiid, versionid, resourceid):
    iop = {"methodtype": "", "path": ""}
    methodtype = request.json["methodtype"]
    json_dict = request.get_json()
    resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
    status, statusmessage, resource = datafile.load_s3_file(resourcepath)
    if status == "success":
        if resource["methods"] == []:
            methodid = uniqid('meth')
            method = {"Ref": methodid}
            resource["methods"].append(method)
        elif resource["methods"] != []:
            methodids = []
            for method in resource["methods"]:
                methodids.append(method["Ref"])
            a = True
            while a is True:
                methodid = uniqid('meth')
                if methodid in methodids:
                    a = True
                else:
                    a = False
            method = {"Ref": methodid}
            resource["methods"].append(method)
        resstatus, resstatusmessage, res = datafile.write_s3_file(
            resourcepath, resource)
        methodjson = {
            "methodtype": methodtype,
            "methodid": methodid,
            "codetype": "python",
            "language": "python3.6",
            "servicetype": "dynamodb_eks_flask",
            "requirements": "",
            "import_code": "",
            "function_code": "",
            "main_code": "",
            "type_code": ""
        }
        if "path" in json_dict:
            methodjson["methodpath"] = request.json["path"]
        if "description" in json_dict:
            methodjson["description"] = request.json["description"]
        methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
        codestring = methodjson["import_code"] + "\n" + methodjson[
            "function_code"] + "\n" + methodjson[
                "main_code"] + "\n" + methodjson["type_code"]
        codepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/" + methodid + ".py"
        codestatus, codestatusmessage, code = datafile.write_txt_file(
            codepath, codestring)
        requirement = methodjson["requirements"]
        requirementpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/requirement.txt"
        requirementstatus, requirementstatusmessage, req = datafile.write_txt_file(
            requirementpath, requirement)
        methstatus, methstatusmessage, methres = datafile.write_s3_file(
            methodpath, methodjson)
        if methstatus == "success" and codestatus == "success" and requirementstatus == "success":
            message = {"statusCode": 200, "body": methodjson}
        else:
            message = {"errorMessage": methstatus, "Error": methres}
    else:
        message = {"errorMessage": statusmessage, "Error": resource}
    return (message)
예제 #30
0
def addsnippet(productid, serviceid, apiid, versionid, resourceid, methodid):
    resourcepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/config.json"
    status, statusmessage, resource = datafile.load_s3_file(resourcepath)
    if "snippetname" not in request.json:
        snippet = request.json["snippet"]
        versionname = request.json["versionname"]
        snippetid = uniqid("sn_")
        updated_method = {
            "import_code": snippet["import_code"],
            "function_code": snippet["function_code"],
            "function_call": snippet["function_call"],
            "requirements": snippet["requirements"],
            "version": snippet["version"],
            "name": snippet["name"]
        }
        methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
        status, statusmessage, methodjson = datafile.load_s3_file(methodpath)
        table = request.json["table"]
        if "TABLENAME" in updated_method["function_code"]:
            updated_method["function_code"] = updated_method[
                "function_code"].replace("TABLENAME", table["tablename"])
        if "TABLENAME" in updated_method["function_call"]:
            updated_method["function_call"] = updated_method[
                "function_call"].replace("TABLENAME", table["tablename"])
        if "PRIMARYKEY" in updated_method["function_code"]:
            updated_method["function_code"] = updated_method[
                "function_code"].replace("PRIMARYKEY",
                                         table['indexes']['primary']['key'])
        if "PRIMARYKEY" in updated_method["function_call"]:
            updated_method["function_call"] = updated_method[
                "function_call"].replace("PRIMARYKEY",
                                         table['indexes']['primary']['key'])
        updated_method["function_code"] = updated_method[
            "function_code"].replace("SNIPPETID", snippetid)
        updated_method["function_call"] = updated_method[
            "function_call"].replace("SNIPPETID", snippetid)
        updated_method.update({"snippetid": snippetid})
        methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
        status, statusmessage, methodjson = datafile.load_s3_file(methodpath)
        if status == "success":
            snippetorder = methodjson["snippets"]["snippetorder"]
            snippetorder.append({
                "name": snippet["name"],
                "snippetid": snippetid
            })
            methodjson["snippets"].update({
                snippetid: updated_method,
                "snippetorder": snippetorder
            })
            methodjson["methodpath"] = methodjson["methodpath"].replace(
                "{", "<")
            methodjson["methodpath"] = methodjson["methodpath"].replace(
                "}", ">")
            if methodjson["methodpath"] != "":
                apicallpath = "/" + versionname + "/" + resource[
                    "resourcename"] + methodjson["methodpath"]
            else:
                apicallpath = "/" + versionname + "/" + resource["resourcename"]
            methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
            methodjson["type_code"] = methodjson["type_code"].replace(
                "METHODID", methodid)
            methodjson["type_code"] = methodjson["type_code"].replace(
                "METHODPATH", apicallpath)
            codestring, requirement = consolidate_code(methodjson)
            codepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/" + methodid + ".py"
            codestatus, codestatusmessage, code = datafile.write_txt_file(
                codepath, codestring)
            if codestatus == "error":
                message = {"statusCode": 400, "errorMessage": code}
                return (message)
            reqstring = ""
            for i in requirement:
                reqstring = reqstring + i + "\n"
            # act["requirements"]=reqstring
            requirementpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/requirement.txt"
            requirementstatus, requirementstatusmessage, req = datafile.write_txt_file(
                requirementpath, reqstring)
            if requirementstatus == "error":
                message = {"statusCode": 400, "errorMessage": req}
                return (message)
            methstatus, methstatusmessage, methres = datafile.write_s3_file(
                methodpath, methodjson)
            if methstatus == "error":
                message = {"statusCode": 400, "errorMessage": code}
                return (message)
            if methstatus == "success" and codestatus == "success" and requirementstatus == "success":
                message = {
                    "statusCode": 200,
                    "body": methodjson,
                    "snippetid": snippetid
                }
        return (message)
    else:
        versionname = request.json["versionname"]
        snippetname = request.json["snippetname"]
        functionname = request.json["functionname"]
        import_code = "import boto3,json\n"
        function_code = "def " + functionname + "():\r\n  # Write your code here\r\n  return()\r\n"
        data_code = ""
        methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
        status, statusmessage, methodjson = datafile.load_s3_file(methodpath)
        dbtype = methodjson["dbtype"]
        if dbtype == "dynamodb":
            data_code = "dynamodb=boto3.resource('dynamodb',region_name='us-east-1')\n"
        function_call = ""
        snippetid = uniqid("sn_")
        custom_snippet = {
            "import_code": import_code,
            "data_code": data_code,
            "function_code": function_code,
            "function_call": function_call,
            "name": snippetname + functionname,
            "snippetid": snippetid,
            "requirements": []
        }
        snippetorder = methodjson["snippets"]["snippetorder"]
        snippetorder.append({
            "name": custom_snippet["name"],
            "snippetid": snippetid
        })
        methodjson["snippets"].update({
            snippetid: custom_snippet,
            "snippetorder": snippetorder
        })
        methodjson["methodpath"] = methodjson["methodpath"].replace("{", "<")
        methodjson["methodpath"] = methodjson["methodpath"].replace("}", ">")
        if methodjson["methodpath"] != "":
            apicallpath = "/" + versionname + "/" + resource[
                "resourcename"] + methodjson["methodpath"]
        else:
            apicallpath = "/" + versionname + "/" + resource["resourcename"]
        methodpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + ".json"
        methodjson["type_code"] = methodjson["type_code"].replace(
            "METHODID", methodid)
        methodjson["type_code"] = methodjson["type_code"].replace(
            "METHODPATH", apicallpath)
        codestring, requirement = consolidate_code(methodjson)
        codepath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/" + methodid + ".py"
        codestatus, codestatusmessage, code = datafile.write_txt_file(
            codepath, codestring)
        if codestatus == "error":
            message = {"statusCode": 400, "errorMessage": code}
            return (message)
        reqstring = ""
        for i in requirement:
            reqstring = reqstring + i + "\n"
        # act["requirements"]=reqstring
        requirementpath = "servicedesigns/" + serviceid + "/api/" + versionid + "/resources/" + resourceid + "/methods/" + methodid + "/code/requirement.txt"
        requirementstatus, requirementstatusmessage, req = datafile.write_txt_file(
            requirementpath, reqstring)
        if requirementstatus == "error":
            message = {"statusCode": 400, "errorMessage": req}
            return (message)
        methstatus, methstatusmessage, methres = datafile.write_s3_file(
            methodpath, methodjson)
        if methstatus == "error":
            message = {"statusCode": 400, "errorMessage": code}
            return (message)
        if methstatus == "success" and codestatus == "success" and requirementstatus == "success":
            message = {
                "statusCode": 200,
                "body": methodjson,
                "snippetid": snippetid
            }
        return (message)