A REST(ful) API for MetricsGrimoire/sortinghat.
756
A REST(ful) API for MetricsGrimoire/sortinghat.
addinitshowInstall MetricsGrimoire/sortinghat
Install python dependencies: pip install Flask flask-restful
Start the app:
$ ./apihat/app.py
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* ...
You can use the pre compiled docker image available from Docker Hub.
At first we need a database. Lets use MySQL:
$ docker run --name mysql \
-e MYSQL_USER=sortinghat \
-e MYSQL_PASSWORD=sortinghat \
-e MYSQL_ROOT_PASSWORD=sortinghat \
-d mysql
Now we start apihat with the sortinghat and apihat configuration and use the database we started a minute ago:
$ docker run -p 5000:5000 \
-e SORTINGHAT_DB_HOST=mysql \
-e SORTINGHAT_DB_USER=root \
-e SORTINGHAT_DB_PASSWORD= \
-e SORTINGHAT_DB_DATABASE=sortinghat \
-d andygrunwald/apihat
Afterwards we do a small test if the api is running (change the host apihat to your docker host IP):
$ curl http://apihat:5000/ping
{"content": "pong"}
Congratulations! Everything up and running! You can now continue with initializing a registry and adding identities. Have fun!
Configuration of apihat is done by environment variables. Checkout the table below for all supported variables.
| Name | Default value | Description |
|---|---|---|
| APIHAT_HOST | 0.0.0.0 | IP that this API is listen to |
| APIHAT_PORT | 5000 | Port that this API is listen to |
| APIHAT_DEBUG | False | Debug mode of apihat |
To configure sortinghat (the software this api is based on) we only support their environment variables as well. Checkout the README of sortinghat to get details about this.
initname (required): Name of the init databaseExample:
$ curl -X POST \
-H "Content-Type: application/json" \
-d '{"name":"registry"}' \
http://apihat:5000/init
{
"name": "registry"
}
showterm (optional): Term to filter the response identitesExample:
$ curl -X GET http://apihat:5000/identities
{
"identities": [
{
"identities": [
{
"email": "[email protected]",
"id": "0067ffa82acc2721670f13e26bf2548a98458579",
"name": "Max Muster",
"source": "gerrit",
"username": "",
"uuid": "0067ffa82acc2721670f13e26bf2548a98458579"
}
],
"profile": null,
"uuid": "0067ffa82acc2721670f13e26bf2548a98458579"
},
{
"identities": [
{
...
}
],
"profile": null,
"uuid": "01b98cd2fdd2a2802e3168c5b54bfc50ff384fe5"
},
...
]
}
addname (optional): Name of the identityemail (optional): Email of the identityusername (optional): Username of the identityuuid (optional): UUID to assign the identitysource (optional): Source of the identitymatching (optional): Matching mechanism (email (default), email-name, see sortinghat for more)Example:
$ curl -X POST \
-H "Content-Type: application/json" \
-d '{"username":"maxwell","email":"[email protected]","source":"scm"}' \
http://apihat:5000/identities
{
"id": "7fcf59c00ee2ece02824adb48d65edcaae755e17",
"uuid": "7fcf59c00ee2ece02824adb48d65edcaae755e17"
}
showExample:
$ curl http://apihat:5000/identities/7fcf59c00ee2ece02824adb48d65edcaae755e17
{
"identities": [
{
"email": "[email protected]",
"id": "7fcf59c00ee2ece02824adb48d65edcaae755e17",
"name": null,
"source": "scm",
"username": "maxwell",
"uuid": "7fcf59c00ee2ece02824adb48d65edcaae755e17"
}
],
"profile": null,
"uuid": "7fcf59c00ee2ece02824adb48d65edcaae755e17"
}
Small ping / health endpoint to check if the service is up.
showExample:
$ curl http://apihat:5000/ping
pong
Contribution is highly welcome. It doesn`t matter if you are able to modify source code, create a Pull Request, commenting issues or talk about apihat at the next usergroup meetup. Every kind of contribution is welcome here.
If you are unsure about something open a new issue and ask your question there. The team will be happy to help.
Content type
Image
Digest
Size
265.4 MB
Last updated
over 5 years ago
docker pull andygrunwald/apihat