Exemplo n.º 1
0
def exists(image, insecure):
    """
    Checks whether image reference exists

    Examples:

    \b
        pydor exists quay.io/gilliam/base:latest
    """
    try:
        ri = pydor.Image.from_image(image)
        response = pydor.API(ri.registry,
                             insecure).Manifest(ri.repository, ri.tag
                                                or ri.digest).get()
    except requests.exceptions.SSLError as e:
        logging.fatal(e.message)
        click.echo("Consider using --insecure")
        click.get_current_context().exit(pydor.errors.SSL_ERROR_CODE)
    except requests.exceptions.HTTPError as e:
        response = e.response

    if response.status_code == requests.codes.ok:
        click.echo("OK")
    elif response.status_code == requests.codes.not_found:
        click.echo("NOT FOUND")
        click.get_current_context().exit(pydor.errors.IMAGE_NOT_FOUND)
    elif response.status_code == requests.codes.unauthorized:
        click.echo(
            "Received unauthorized... Authorization not implemented yet... exiting"
        )
        click.get_current_context().exit(pydor.errors.NOT_IMPLEMENTED)
    else:
        raise NotImplementedError()
Exemplo n.º 2
0
def ping(registry, insecure):
    """
    Ping a docker registry to check if the address is a valid docker registry and is responding.

    Examples:

    \b
        pydor ping quay.io
    """
    try:
        response = pydor.API(registry, insecure).Base().get()
    except requests.exceptions.SSLError as e:
        logging.fatal(e.message)
        click.echo("Consider using --insecure")
        click.get_current_context().exit(pydor.errors.SSL_ERROR_CODE)

    if response.status_code == requests.codes.ok:
        click.echo("OK")
    elif response.status_code == requests.codes.not_found:
        click.echo("Error: registry does not implement v2 API")
        click.get_current_context().exit(pydor.errors.NOT_V2_REGISTRY)
    elif response.status_code == requests.codes.unauthorized:
        click.echo("Authorization not implemented yet... exiting")
        click.get_current_context().exit(pydor.errors.NOT_IMPLEMENTED)
    else:
        raise NotImplementedError()
Exemplo n.º 3
0
def list(registry, limit, output, insecure):
    """
    List repositories present in docker registry.

    Examples:

    \b
        pydor list quay.io
        pydor list --limit=0 quay.io
        pydor list --output=json quay.io
    """
    generator = pydor.API(registry, insecure=insecure).Catalog()
    _list(generator, limit, output, insecure)
Exemplo n.º 4
0
def tags(repository, limit, output, insecure):
    """
    List tags of a given repository.

    Examples:

    \b
        pydor tags quay.io/coreos/etcd
        pydor tags --limit=0 quay.io/coreos/etcd
        pydor tags --output=yaml quay.io/coreos/etcd
    """
    ri = pydor.Image.from_image(repository)

    generator = pydor.API(ri.registry, insecure=insecure).Tags(ri.repository)
    _list(generator, limit, output, insecure)
Exemplo n.º 5
0
def manifest(image, insecure):
    """
    Retrieve a manifest from a docker registry.

    Examples:

    \b
        pydor manifest quay.io/coreos/etcd:latest

    """
    ri = pydor.Image.from_image(image)

    manifest = pydor.Manifest(
        pydor.API(ri.registry,
                  insecure=insecure).Manifest(ri.repository,
                                              ri.reference).get())
    click.echo(json.dumps(manifest.json, indent=4))
Exemplo n.º 6
0
def inspect(type, image, output, insecure):
    """
    Inspect an attribute of a docker image in remote docker registry. TYPE is one of [labels, author, entrypoint, cmd]

    Examples:

    \b
        pydor inspect cmd quay.io/coreos/etcd:latest
    """

    ri = pydor.Image.from_image(image)

    manifest = pydor.Manifest(
        pydor.API(ri.registry,
                  insecure=insecure).Manifest(ri.repository,
                                              ri.reference).get())

    inspected_object = getattr(manifest, type)

    dataset = tablib.Dataset(headers=inspected_object.headers)
    map(dataset.append, inspected_object.data)
    click.echo(getattr(dataset, output))