token¶
More info about the token schema can be found here.
Note
This resource can also be accessed using the plural form tokens
.
Note
All operations on the token resource can only be performed with an administrator token.
GET¶
-
GET
/token/
(string: token)¶ Get all the available tokens or a single one if
token
is provided.Parameters: - token (string) – The token whose values to retrieve.
Request Headers: - Authorization – The token necessary to authorize the request.
- Accept-Encoding – Accept the
gzip
coding.
Response Headers: - Content-Type – Will be
application/json; charset=UTF-8
.
Query Parameters: - limit (int) – Number of results to return. Default 0 (all results).
- skip (int) – Number of results to skip. Default 0 (none).
- sort (string) – Field to sort the results on. Can be repeated multiple times.
- sort_order (int) – The sort order of the results: -1 (descending), 1
(ascending). This will be applied only to the first
sort
parameter passed. Default -1. - date_range (int) – Number of days to consider, starting from today (more info). By default consider all results.
- field (string) – The field that should be returned in the response. Can be repeated multiple times.
- nfield (string) – The field that should not be returned in the response. Can be repeated multiple times.
- _id (string) – The internal ID of the token object.
- created_on (string) – The creation date: accepted formats are
YYYY-MM-DD
andYYYYMMDD
. - email (string) – The email address associated with the token.
- expired (boolean) – If the token is expired or not.
- username (string) – The user name associated with the token.
Status Codes: - 200 OK – Results found.
- 403 Forbidden – Not authorized to perform the operation.
- 404 Not Found – The provided resource has not been found.
- 500 Internal Server Error – Internal database error.
Example Requests
GET /token/ HTTP/1.1 Host: api.kernelci.org Accept: */* Authorization: token
GET /token/12345-12345-12345 HTTP/1.1 Host: api.kernelci.org Accept: */* Authorization: token
Example Responses
HTTP/1.1 200 OK Vary: Accept-Encoding Date: Mon, 06 Feb 2015 15:12:50 GMT Content-Type: application/json; charset=UTF-8 { "code": 200, "result": [ { "created_on": { "$date": 1407818315043}, "email": "email@example.net", "token": "12345-12345-12345", "expired": false } ] }
Note
Results shown here do not include the full JSON response.
POST¶
-
POST
/token
¶ Create a token as defined in the JSON data.
For more info on all the required JSON request fields, see the JSON token schema for POST requests.
Note
When creating the first token to be stored in the database, you must use the configured master key.
Request JSON Object: - email (string) – The email associated with the token (required only when creating a new token).
- username (string) – The user name associated with the token.
- admin (string) – If the token is an administrator one (it automatically sets GET/DELETE/POST/PUT operations)
- superuser (string) – If the token is a super user one (a super user cannot create new tokens, but can perform GET/DELETE/POST/PUT operations).
- get (boolean) – If the token can perform GET operations.
- post (boolean) – If the token can perform POST/PUT operations.
- delete (boolean) – If the token can perform DELETE operations.
- upload (boolean) – If the token can be used to upload files.
- ip_restricted (boolean) – If the token is restricted to be used on certain IP addresses.
- ip_address (array) – Array of IP addresses the token is restricted to.
- lab (boolean) – If the token is a boot lab one.
- test_lab (boolean) – If the token is a test lab one.
Request Headers: - Authorization – The token necessary to authorize the request.
- Content-Type – Content type of the transmitted data, must be
application/json
. - Accept-Encoding – Accept the
gzip
coding.
Response Headers: - Content-Type – Will be
application/json; charset=UTF-8
.
Status Codes: - 201 Created – The resource has been created.
- 400 Bad Request – JSON data not valid.
- 403 Forbidden – Not authorized to perform the operation.
- 415 Unsupported Media Type – Wrong content type.
- 422 Unprocessable Entity – No real JSON data provided.
Example Requests
POST /token HTTP/1.1 Host: api.kernelci.org Content-Type: application/json Accept: */* Authorization: token { "email": "email@example.net", "admin": 1, "ip_restricted": 1, "ip_address": ["192.168.2.1"] }
PUT¶
-
PUT
/token/
(string: token_id)¶ Update an existing token identified by its
token_id
with the values provided in the JSON data.The
token_id
value is different from the token value itself: thetoken_id
is the internal ID as provided by the database.For more info on all the required JSON request fields, see the JSON token schema for POST requests.
Request JSON Object: - email (string) – The email associated with the token (required only when creating a new token).
- username (string) – The user name associated with the token.
- admin (string) – If the token is an administrator one (it automatically sets GET/DELETE/POST/PUT operations)
- superuser (string) – If the token is a super user one (a super user cannot create new tokens, but can perform GET/DELETE/POST/PUT operations).
- get (boolean) – If the token can perform GET operations.
- post (boolean) – If the token can perform POST/PUT operations.
- delete (boolean) – If the token can perform DELETE operations.
- upload (boolean) – If the token can be used to upload files.
- ip_restricted (boolean) – If the token is restricted to be used on certain IP addresses.
- ip_address (array) – Array of IP addresses the token is restricted to.
- lab (boolean) – If the token is a boot lab one.
- test_lab (boolean) – If the token is a test lab one.
Request Headers: - Authorization – The token necessary to authorize the request.
- Content-Type – Content type of the transmitted data, must be
application/json
. - Accept-Encoding – Accept the
gzip
coding.
Response Headers: - Content-Type – Will be
application/json; charset=UTF-8
.
Status Codes: - 200 OK – The request has been accepted and the token updated.
- 400 Bad Request – JSON data not valid.
- 403 Forbidden – Not authorized to perform the operation.
- 404 Not Found – The provided resource has not been found.
- 415 Unsupported Media Type – Wrong content type.
- 422 Unprocessable Entity – No real JSON data provided.
Example Requests
POST /token/12345-12345-12345 HTTP/1.1 Host: api.kernelci.org Content-Type: application/json Accept: */* Authorization: token { "upload": 1 }
DELETE¶
-
DELETE
/token/
(string: token_id)¶ Delete the token identified by its
token_id
.The
token_id
value is different from the token value itself: thetoken_id
is the internal ID as provided by the database.Parameters: - token_id (string) – The token ID as provided by the database.
Request Headers: - Authorization – The token necessary to authorize the request.
- Accept-Encoding – Accept the
gzip
coding.
Response Headers: - Content-Type – Will be
application/json; charset=UTF-8
.
Status Codes: - 200 OK – Resource deleted.
- 403 Forbidden – Not authorized to perform the operation.
- 404 Not Found – The provided resource has not been found.
- 500 Internal Server Error – Internal database error.
Example Requests
DELETE /token/abcdefghi HTTP/1.1 Host: api.kernelci.org Accept: */* Content-Type: application/json Authorization: token