Example #1
0
def cli():
    api_server = client.base_url
    project_suuid = os.getenv("AA_PROJECT_SUUID")
    package_suuid = os.getenv("AA_PACKAGE_SUUID")

    if not project_suuid:
        click.echo("No AA_PROJECT_SUUID found.", err=True)
        sys.exit(1)
    if not package_suuid:
        click.echo("No AA_PACKAGE_SUUID found.", err=True)
        sys.exit(1)

    download_url = "/".join(
        ["project", project_suuid, "packages", package_suuid, "download", ""])
    download_url = api_server + download_url

    r = client.get(download_url)
    res = r.json()

    r = client.get(res["target"])
    with open("/tmp/code.zip", "wb") as f:
        f.write(r.content)

    with ZipFile("/tmp/code.zip", "r") as myzip:
        myzip.extractall("/code")
Example #2
0
def cli(output):
    api_server = client.base_url
    run_suuid = os.getenv("AA_RUN_SUUID")

    download_url = "/".join(["runinfo", run_suuid, "manifest", ""])
    download_url = api_server + download_url

    r = client.get(download_url)

    with open(output, "w") as f:
        f.write(r.text)
Example #3
0
    def get_user_info(self) -> User:
        url = f"{self.base_url}/rest-auth/user/"
        r = client.get(url)

        if r.status_code == 200:
            return User(**r.json())
        elif r.status_code == 401:
            raise GetError(
                "The provided token is not valid. Via `askanna logout` you can remove the token "
                "and via `askanna login` you can set a new token.")
        else:
            raise GetError("{} - We could not connect to AskAnna. More info:\n"
                           "{}".format(r.status_code, r.reason))
Example #4
0
def getProjectPackages(project, offset=0, limit=1):
    from askanna.config import config
    from askanna.core.apiclient import client

    r = client.get(
        "{api_server}/v1/project/{project_suuid}/packages/?offset={offset}&limit={limit}"
        .format(
            api_server=config.server.remote,
            project_suuid=project.short_uuid,
            offset=offset,
            limit=limit,
        ))
    if not r.status_code == 200:
        return []

    return r.json()
Example #5
0
def cli(run, payload, output):
    api_server = client.base_url

    # we assume we can get jobrun id and the payload
    payload_url = (
        "{ASKANNA_API_SERVER}runinfo/{RUN_SUUID}/payload/{PAYLOAD_SUUID}/".format(
            RUN_SUUID=run,
            PAYLOAD_SUUID=payload,
            ASKANNA_API_SERVER=api_server,
        )
    )

    req = client.get(payload_url)

    if not req.status_code == 200:
        click.echo(f"Could not retrieve payload with SUUID: {payload}", err=True)
        sys.exit(1)

    if output:
        with open(output, "w") as f:
            f.write(req.text)
    else:
        click.echo(req.text)