The API allows you to maintain yours databases.
I assumed you know about REST API and JSON. But if you don't know, don't worry about because I give you examples using curl
or you can access api using your web browser too. There is a beatiful interface to help you to understand it.
To ensure you will be able to run all examples, they are based on sample data provided by make reset_data
command.
Currently, only basic authentication is supported. So I recommend you use HTTPS.
This resource represents a database. Databases can be created on different engines.
Fields | Description | Required? | Read only? |
---|---|---|---|
id | Unique identifier of your database | yes (but is automatic) | yes |
name | Name of database. | yes | no* |
plan | Which kind of plan your database is using | yes | no* |
environment | On which environment your database was created | yes | no* |
project | Project related with this database | no | no |
quarantine_dt | Date on which your database enter on quarantine | no | no |
endpoint | Connection address for this database | no | yes |
total_size_in_bytes | Total size of your database. Depends of you plan | no | yes |
used_size_in_bytes | Used space of your database (this is not a realtime information) | no | yes |
credentials | List of credentials that have access to this database | no | yes |
* This fields are not read only at creation time, but you can change it after. |
Create new database. Required fields are:
- name
- plan
- environment
- project, not required, but can be specified at creation time.
In response you will have the id and endpoint of your new database. By default, a new user with name 'u_name of database
' will be create for this database.
curl -u admin:123456 -H 'content-type: application/json' http://localhost:8000/api/database/ -d '{ "name": "test database2", "plan": "/api/plan/1/", "environment": "/api/environment/1/" }'
Response:
{
"_links": {
"self": "http://localhost:8000/api/database/1/"
},
"id": 1,
"name": "test_database2",
"endpoint": "mongodb://<user>:<password>@127.0.0.1:27017/test_database2",
"plan": "http://localhost:8000/api/plan/1/",
"environment": "http://localhost:8000/api/environment/1/",
"project": null,
"quarantine_dt": null,
"total_size_in_bytes": 0,
"used_size_in_bytes": 16924,
"credentials": [
"http://localhost:8000/api/credential/1/"
]
}
List all databases that you have permission.
curl -u admin:123456 http://localhost:8000/api/database/
Response:
{
"_links": {
"count": 6,
"self": "http://localhost:8000/api/database/",
"previous": null,
"next": null
},
"database": [
{
"_links": {
"self": "http://localhost:8000/api/database/1/"
},
"id": 1,
"name": "my_first_database",
"endpoint": "mongodb://<user>:<password>@127.0.0.1:27017/my_first_database",
"plan": "http://localhost:8000/api/plan/1/",
"environment": "http://localhost:8000/api/environment/1/",
"project": null,
"quarantine_dt": null,
"total_size_in_bytes": 0,
"used_size_in_bytes": 17064,
"credentials": [
"http://localhost:8000/api/credential/1/",
"http://localhost:8000/api/credential/7/"
]
},
...
]
}
Get data about one database.
curl -u admin:123456 http://localhost:8000/api/database/*some_id*/
Response:
{
"_links": {
"self": "http://localhost:8000/api/database/1/"
},
"id": 1,
"name": "test_database2",
"endpoint": "mongodb://<user>:<password>@127.0.0.1:27017/test_database2",
"plan": "http://localhost:8000/api/plan/1/",
"environment": "http://localhost:8000/api/environment/1/",
"project": null,
"quarantine_dt": null,
"total_size_in_bytes": 0,
"used_size_in_bytes": 16924,
"credentials": [
"http://localhost:8000/api/credential/1/"
]
}
Put database on quarantine. If database is already on quarantine, it will be delete. When database is no quarantine, all database credentials will be reseted to a unknow password, to avoid connections.
curl -u admin:123456 -X DELETE http://localhost:8000/api/database/1/
Credential are the way you use to have access to some database. In DBaaS credentials are ALWAYS per database, since the engine allows you have the same user with access to more than one database. Currently, you can't specify password, it's always generated by system.
Fields | Description | Required? | Read only? |
---|---|---|---|
id | Unique identifier of your credential | yes (but its automatic) | yes |
user | user name of your credential | yes | yes |
database | database url (/api/database/id) | yes | yes |
password | user password. Is hidden on list | no | no |
List all credentials. In list operation, passwords are not shown.
curl -u admin:123456 http://localhost:8000/api/credential/
Response:
{
"_links": {
"count": 10,
"self": "http://localhost:8000/api/credential/",
"previous": null,
"next": null
},
"credential": [
{
"_links": {
"self": "http://localhost:8000/api/credential/1/"
},
"id": 1,
"user": "u_test_database2",
"database": "http://localhost:8000/api/database/1/"
},
...
]
}
Get the password from credential.
curl -u admin:123456 http://localhost:8000/api/credential/1/
Response:
{
"_links": {
"self": "http://localhost:8000/api/credential/1/"
},
"id": 1,
"user": "u_test_database2",
"database": "http://localhost:8000/api/database/1/",
"password": "26WcA33q6F"
}
Create new credential
In response you will have the id and password of your new credential. Currently is not possible specify user password.
curl -u admin:123456 -H 'content-type: application/json' http://localhost:8000/api/credential/ -d '{ "user": "u_myusr1", "database": "/api/database/1/" }'
Response:
{
"_links": {
"self": "http://localhost:8000/api/credential/2/"
},
"id": 2,
"user": "u_myusr1",
"database": "http://localhost:8000/api/database/1/",
"password": "w9RXg222wK"
}
Generate a new password for your credential
curl -u admin:123456 -d '' http://localhost:8000/api/credential/1/reset_password/
Response:
{
"_links": {
"self": "http://localhost:8000/api/credential/1/"
},
"id": 1,
"user": "u_test_database2",
"database": "http://localhost:8000/api/database/1/",
"password": "PReduz6QtA"
}
Remove credential.
curl -u admin:123456 -X DELETE http://localhost:8000/api/credential/1/