Skip to content

Commit

Permalink
Merge pull request #9 from jessestuart/jesse/produce_valid_json
Browse files Browse the repository at this point in the history
[cli] Produce valid JSON when `-f json` flag passed
  • Loading branch information
amalfra authored Jul 5, 2018
2 parents f1cd7ee + 27f0477 commit 8a56964
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,66 @@ You should have pip installed in your system.
```sh
pip install docker-hub
```
python 3 users can do
Python 3 users can do:
```sh
pip3 install docker-hub
```

## Usage
##### 1. Authenticate with Docker Hub
If you are already loggedin using `docker login` command, then the token in docker engine config will be used. Otherwise you can choose to proceed without authenticating which will query docker hub without token and list only public resources. To authenticate for viewing private resources do `docker-hub login` command; this will save auth token in docker-hub's config file so that you don't need to do login everytime.
If you are already logged in using `docker login` command, then the token in Docker engine config will be used. Otherwise you can choose to proceed without authenticating which will query docker hub without token and list only public resources. To authenticate for viewing private resources do `docker-hub login` command; this will save auth token in `docker-hub`'s config file so that you don't need to login every time.

If you want to authenticate for only current command(to not presist auth tokens in config) make use of the following env variables:
* DOCKER_HUB_USERNAME - Your Docker Hub username
* DOCKER_HUB_PASSWORD - Your Docker Hub password
If you want to authenticate for the only current command (to not persist auth tokens in config), make use of the following env variables:

* `DOCKER_HUB_USERNAME` - Your Docker Hub username
* `DOCKER_HUB_PASSWORD` - Your Docker Hub password

Pass the mentioned envs with your command and docker-hub will try to do authentication without prompting for credentials.

eg:
e.g.:
```sh
DOCKER_HUB_USERNAME=hello DOCKER_HUB_PASSWORD=world docker-hub repos --orgname docker
```

##### 2. Querying an organization for repositories
To query repositories in an organization use `repos` argument. The organization to query can be passed as `--orgname` or `-o` parameter.
eg: Get repos in organization named "docker"
e.g.: Get repos in organization named "docker"
```sh
docker-hub repos --orgname docker
```

##### 3. Querying the tags of a repository
To query tags of a repository use `tags` argument. The organization of repository can be passed as `--orgname` or `-o` parameter. The repository to query can be passed as `--reponame` or `-r` parameter.
eg: Get tags of repository "ucp" in organization named "docker"
e.g.: Get tags of repository "ucp" in organization named "docker"
```sh
docker-hub tags --orgname docker --reponame ucp
```

##### 4. Querying a user profile
To query a user profile use `users` argument. The username to query can be passed as `--username` or `-u` parameter.
eg: Get profile of user named "docker"
e.g.: Get profile of user named "docker"
```sh
docker-hub users --username docker
```

##### 5. Querying the auto-builds of a repository
To query auto-builds of a repository use `builds` argument. The organization of repository can be passed as `--orgname` or `-o` parameter. The repository to query can be passed as `--reponame` or `-r` parameter.
eg: Get build of repository "ucp" in organization named "docker"
e.g.: Get build of repository "ucp" in organization named "docker"
```sh
docker-hub builds --orgname docker --reponame ucp
```

##### 6. Querying an organization for auto-build queue
To query the auto-build repositories with pending builds use the `queue` argument. The organization to query can be passed as `--orgname` or `-o` parameter.
eg: Get the building queue for organization named "docker"
e.g.: Get the building queue for organization named "docker"
```sh
docker-hub queue --orgname docker
```

##### Notes:
* Only 15 results will be displayed at once. You can fetch remaining pages by passing `--page` or `-p` parameter.

eg: Get 3rd page
e.g.: Get 3rd page
```sh
docker-hub repos --orgname docker --page 3
```
Expand All @@ -81,7 +82,7 @@ docker-hub queue --orgname docker

`--format` or `-f` parameter can be used to specify the format in which result must be displayed.

eg:
e.g.:
* Display in json format
```sh
docker-hub repos --orgname docker --format json
Expand Down
2 changes: 0 additions & 2 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def main():
docker_hub_password_env, False):
print('Invalid credentials. Failed logging in to Docker Hub.')
sys.exit(1)
else:
print('Logged in to Docker Hub.\n')
# Check if an auth token is present
login_token_present = docker_client.get_auth_token() or \
docker_hub_client.get_token()
Expand Down
9 changes: 3 additions & 6 deletions src/libs/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- encoding: utf-8 -*-
import sys
import argparse
import getpass
import json
import math
import sys
from tabulate import tabulate
from ..consts import PER_PAGE

Expand Down Expand Up @@ -55,11 +56,7 @@ def print_result(format, rows=[], header=[], count=0, page=1, heading=False):
(count, page, total_pages))
print_table(header, rows)
else:
json_result = []
for row in rows:
json_dict = {}
json_dict = dict(zip(header, row))
json_result.append(json_dict)
json_result = json.dumps([dict(zip(header, row)) for row in rows])
print(json_result)


Expand Down

0 comments on commit 8a56964

Please sign in to comment.