Пример #1
0
def main():
    description = ""
    description += "Encrypts specified file.\n"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=description)
    parser.add_argument(
        "-c",
        "--credentials",
        metavar="credentials",
        help=
        "Location of credential file. Default location is <home directory>/.plunify/credentials"
    )
    parser.add_argument("-i",
                        "--input",
                        metavar="input",
                        help="Input file to encrypt")
    parser.add_argument("-o",
                        "--output",
                        metavar="output",
                        help="Ouput encrypted file")

    args = parser.parse_args()

    plunify_apiid, plunify_key, plunify_password, plunify_host = plunifyutils.readCredentialsFile(
        args.credentials)

    if not args.input or not args.output:
        print("Please specify input and output file to encrypt")
        sys.exit()

    in_filename = os.path.abspath(args.input)
    out_filename = os.path.abspath(args.output)

    if os.path.isdir(in_filename):
        print("Specified file for encryption {} is a directory".format(
            in_filename))
        sys.exit()

    if not os.path.exists(in_filename):
        print("Specified file for encryption {} does not exist".format(
            in_filename))
        sys.exit()

    print("Encrypting {}".format(in_filename))
    if sys.version_info[0] < 3:
        key = hashlib.md5(bytes(plunify_password)).hexdigest()
    else:
        key = hashlib.md5(bytes(plunify_password, "latin-1")).hexdigest()

    if in_filename == out_filename:
        tmp_filename = out_filename + ".plunify.tmp"
        encryptFile(key, in_filename, tmp_filename)
        copyfile(tmp_filename, in_filename)
        os.remove(tmp_filename)
    else:
        encryptFile(key, in_filename, out_filename)
    print("Done")
Пример #2
0
def main():
    host = "https://prod8api.plunify.com"
    uri = "cloudapi/v1/listjob"

    description = ""
    description += "Return job details.\n"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=description)
    parser.add_argument("-v",
                        help="Increase output verbosity",
                        action="store_true")
    parser.add_argument(
        "-c",
        "--credentials",
        metavar="credentials",
        help=
        "Location of credential file. Default location is <home directory>/.plunify/credentials"
    )
    parser.add_argument(
        "type",
        metavar="type",
        type=validateTypeParameter,
        help=
        "If 'all', all jobs are returned. If 'current', the latest job will be returned. If job id, the job with the job id will be returned."
    )

    args = parser.parse_args()
    v = args.v

    plunify_apiid, plunify_key, plunify_password, plunify_host = plunifyutils.readCredentialsFile(
        args.credentials)
    if plunify_host:
        host = plunify_host
    endpoint = host + "/" + uri

    params = {}
    params["apiid"] = plunify_apiid
    params["key"] = plunify_key
    params["type"] = None

    parseCommandLineParameters(args, params)
    plunifyutils.validateParameters(params)

    url = plunifyutils.getSignedURL(endpoint, params, plunify_password)
    if v: print(url)

    print("Listing jobs ... ")
    response = requests.get(url)
    res = response.json()
    if v: print(json.dumps(res))

    if res["code"] == 0:
        print(json.dumps(res["jobs"], indent=4))
        print("Total jobs: {}".format(res["totaljobs"]))
    else:
        print("Error listing jobs: {}".format(res["message"]))
Пример #3
0
def main():
    host = "https://prod8api.plunify.com"
    uri = "cloudapi/v1/canceljob"

    description = ""
    description += "Cancels the job specified.\n"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=description)
    parser.add_argument("-v",
                        help="Increase output verbosity",
                        action="store_true")
    parser.add_argument(
        "-c",
        "--credentials",
        metavar="credentials",
        help=
        "Location of credential file. Default location is <home directory>/.plunify/credentials"
    )
    parser.add_argument("jobid",
                        metavar="jobid",
                        type=int,
                        help="Cancels the job with the specified Job ID.")

    args = parser.parse_args()
    v = args.v

    plunify_apiid, plunify_key, plunify_password, plunify_host = plunifyutils.readCredentialsFile(
        args.credentials)
    if plunify_host:
        host = plunify_host
    endpoint = host + "/" + uri

    params = {}
    params["apiid"] = plunify_apiid
    params["key"] = plunify_key
    params["jobid"] = None

    parseCommandLineParameters(args, params)
    plunifyutils.validateParameters(params)

    url = plunifyutils.getSignedURL(endpoint, params, plunify_password)
    if v: print(url)

    print("Cancelling job {}".format(params["jobid"]))
    response = requests.get(url)
    res = response.json()
    if v: print(json.dumps(res))

    if res["code"] == 0:
        print("Job cancelled sucessfully")
    else:
        print("Error cancelling job: {}".format(res["message"]))
Пример #4
0
def main():
    host = "https://prod8api.plunify.com"
    uri = "cloudapi/v1/getjob"

    description = ""
    description += "Download result files for the specified job.\n"
    description += "Files will be downloaded into the output directory specified.\n"
    description += "Note - Files are decrypted autmatically.\n"
    description += "If you prefer to download and decrypt files manually, see getjobclient.py and decrypt.py.\n"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=description)
    parser.add_argument("-v",
                        help="Increase output verbosity",
                        action="store_true")
    parser.add_argument(
        "-c",
        "--credentials",
        metavar="credentials",
        help=
        "Location of credential file. Default location is <home directory>/.plunify/credentials"
    )
    parser.add_argument(
        "jobid",
        metavar="jobid",
        type=int,
        help="Downloads and decrypts job information with the specified Job ID."
    )
    parser.add_argument("-o",
                        "--outdir",
                        metavar="outdir",
                        help="Ouput directory for downloaded files")

    args = parser.parse_args()
    v = args.v

    plunify_apiid, plunify_key, plunify_password, plunify_host = plunifyutils.readCredentialsFile(
        args.credentials)
    if plunify_host:
        host = plunify_host
    endpoint = host + "/" + uri

    params = {}
    params["apiid"] = plunify_apiid
    params["key"] = plunify_key
    params["jobid"] = None
    params["outdir"] = None

    parseCommandLineParameters(args, params)
    plunifyutils.validateParameters(params)

    outdir = os.path.abspath(params["outdir"])
    params["outdir"] = None

    url = plunifyutils.getSignedURL(endpoint, params, plunify_password)
    if v: print(url)

    print("Get job {} info ... ".format(params["jobid"]))
    response = requests.get(url)
    res = response.json()
    if v: print(json.dumps(res))

    if res["code"] == 0:
        print("Job status: {}".format(res["action"]))

        if sys.version_info[0] < 3:
            key = hashlib.md5(bytes(plunify_password)).hexdigest()
        else:
            key = hashlib.md5(bytes(plunify_password, "latin-1")).hexdigest()

        files = res["files"]
        urls = res["presigned"]

        if len(files):

            if not os.path.exists(outdir) or not os.path.isdir(outdir):
                print("Creating output directory {}".format(outdir))
                os.makedirs(outdir)

            for i in range(len(files)):
                presignurl = base64.b64decode(urls[i])
                downloadfile = os.path.join(outdir, files[i])
                print("Downloading {}. ({} of {})".format(
                    downloadfile, i + 1, len(files)))

                downloadresponse = requests.get(presignurl)
                with open(downloadfile, "wb") as f:
                    f.write(downloadresponse.content)

                filename_no_ext, file_ext = os.path.splitext(downloadfile)
                if file_ext == ".enc":
                    print("Decrypting {} to {} ".format(
                        downloadfile, filename_no_ext))
                    decryptFile(key, downloadfile, filename_no_ext)

            print("Download complete")

        else:
            print("No files to download")

    else:
        print("Error getting job info: {}".format(res["message"]))
Пример #5
0
def main():
    host = "https://prod8api.plunify.com"
    uri = "cloudapi/v1/startjob"

    description = ""
    description += "Issues a request to start compiling the specified job with the specified server type.\n"
    description += "The list of available server types can be found on https://cloud.plunify.com/faq.\n"
    description += "Note - Call this script AFTER createjobclient.py.\n"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=description)
    parser.add_argument("-v",
                        help="Increase output verbosity",
                        action="store_true")
    parser.add_argument(
        "-c",
        "--credentials",
        metavar="credentials",
        help=
        "Location of credential file. Default location is <home directory>/.plunify/credentials"
    )
    parser.add_argument(
        "-j",
        "--jobconfig",
        metavar="jobconfig",
        help=
        "Location of job config file. Properties of this file will be overwritten by properties set on the command line."
    )
    parser.add_argument("-servertype",
                        metavar="servertype",
                        help="Server Type")
    parser.add_argument("-maxtime",
                        metavar="maxtime",
                        type=int,
                        help="Max run time for job in hours.")
    parser.add_argument("jobid",
                        metavar="jobid",
                        type=int,
                        help="Starts the job with the specified Job ID.")

    args = parser.parse_args()
    v = args.v

    plunify_apiid, plunify_key, plunify_password, plunify_host = plunifyutils.readCredentialsFile(
        args.credentials)
    if plunify_host:
        host = plunify_host
    endpoint = host + "/" + uri

    params = {}
    params["apiid"] = plunify_apiid
    params["key"] = plunify_key
    params["servertype"] = None
    params["jobid"] = None
    params["maxtime"] = 48

    if args.jobconfig: plunifyutils.readConfigFile(args.jobconfig, params)

    parseCommandLineParameters(args, params)
    plunifyutils.validateParameters(params)

    if "maxtime" in params:
        if params["maxtime"] <= 0:
            print("Maxtime {} cannot be less than or equal to 0".format(
                params[maxtime]))
            sys.exit()

    url = plunifyutils.getSignedURL(endpoint, params, plunify_password)
    if v: print(url)

    print("Starting job {} ...".format(params["jobid"]))
    response = requests.get(url)
    res = response.json()
    if v: print(json.dumps(res))

    if res["code"] == 0:
        print("Job started")
    else:
        print("Error starting job: {}".format(res["message"]))
Пример #6
0
def main():
    host = "https://prod8api.plunify.com"
    uri = "cloudapi/v1/createjob"

    description = ""
    description += "Issues a new job request with the specified tool and platform.\n"
    description += "The encrypted zip file will be uploaded to Plunify Cloud.\n"
    description += "A job id is returned which is used to:\n"
    description += "\n"
    description += "1) Start Job (startjobclient.py)\n"
    description += "2) Download Job (getjobclient.py)\n"
    description += "3) Check Job Status (listjobclient.py)\n"
    description += "4) Cancel Job (canceljobclient.py)\n"
    description += "\n"
    description += "Note - Ensure that the zip file has been encrypted. See encrypt.py for more information.\n"
    description += "Note - This script DOES NOT start the job. Use startjobclient.py after calling this script to start the job.\n"

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter, description=description)
    parser.add_argument("-v",
                        help="Increase output verbosity",
                        action="store_true")
    parser.add_argument(
        "-c",
        "--credentials",
        metavar="credentials",
        help=
        "Location of credential file. Default location is <home directory>/.plunify/credentials"
    )
    parser.add_argument(
        "-j",
        "--jobconfig",
        metavar="jobconfig",
        help=
        "Location of job config file. Properties of this file will be overwritten by properties set on the command line."
    )
    parser.add_argument("-toolvendor",
                        metavar="toolvendor",
                        help="Tool Vendor")
    parser.add_argument("-toolname", metavar="toolname", help="Tool Name")
    parser.add_argument("-toolversion",
                        metavar="toolversion",
                        help="Tool Version")
    parser.add_argument("-platform",
                        metavar="platform",
                        help="Platform to run")
    parser.add_argument("-platformver",
                        metavar="platformver",
                        help="Platform version to run")
    parser.add_argument("-filename",
                        metavar="filename",
                        help="Zip file to upload")

    args = parser.parse_args()
    v = args.v

    plunify_apiid, plunify_key, plunify_password, plunify_host = plunifyutils.readCredentialsFile(
        args.credentials)
    if plunify_host:
        host = plunify_host
    endpoint = host + "/" + uri

    params = {}
    params["apiid"] = plunify_apiid
    params["key"] = plunify_key
    params["toolvendor"] = None
    params["toolname"] = None
    params["toolversion"] = None
    params["platform"] = None
    params["platformver"] = None
    params["filename"] = None

    if args.jobconfig: plunifyutils.readConfigFile(args.jobconfig, params)

    parseCommandLineParameters(args, params)
    plunifyutils.validateParameters(params)
    params["filelen"] = getFileLen(params["filename"])
    params["checksum"] = plunifyutils.md5(params["filename"])

    filepath = os.path.abspath(params["filename"])
    params["filename"] = os.path.basename(filepath)

    url = plunifyutils.getSignedURL(endpoint, params, plunify_password)
    if v: print(url)

    print("Creating job ... ")
    response = requests.get(url)
    res = response.json()
    if v: print(json.dumps(res))

    if res["code"] == 0:
        base64presignURL = res["presigned"]
        presignUploadURL = base64.b64decode(base64presignURL)
        print("Uploading {}".format(filepath))
        with open(filepath, 'rb') as data:
            requests.put(presignUploadURL, data=data)
        print("Upload successful")
        print("Job Created. Job ID: {}".format(res["jobid"]))
        print(
            "Job is created but NOT started yet. Use startjobclient.py to start the job"
        )
    else:
        print("Error creating job: {}".format(res["message"]))