Roles API
NOTE: Requests to the roles API require you to authenticate with a Sensu access token or API key.
The code examples in this document use the environment variable $SENSU_API_KEY
to represent a valid API key in API requests.
Get all roles
The /roles
API endpoint provides HTTP GET access to role data.
Example
The following example demonstrates a request to the /roles
API endpoint, resulting in a JSON array that contains role definitions.
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/roles \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
[
{
"rules": [
{
"verbs": [
"get",
"list"
],
"resources": [
"events"
],
"resource_names": null
}
],
"metadata": {
"name": "event-reader",
"namespace": "default",
:created_by": "admin"
}
},
{
"rules": [
{
"verbs": [
"read"
],
"resources": [
"*"
],
"resource_names": null
}
],
"metadata": {
"name": "read-only",
"namespace": "default",
"created_by": "admin"
}
}
]
API Specification
/roles (GET) | |
---|---|
description | Returns the list of roles. |
example url | http://hostname:8080/api/core/v2/namespaces/default/roles |
pagination | This endpoint supports pagination using the limit and continue query parameters. |
response filtering | This endpoint supports API response filtering. |
response type | Array |
response codes |
|
output |
|
Create a new role
The /roles
API endpoint provides HTTP POST access to create Sensu roles.
Example
In the following example, an HTTP POST request is submitted to the /roles
API endpoint to create a role named event-reader
.
The request returns a successful HTTP 201 Created
response.
curl -X POST \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"rules": [
{
"verbs": [
"get",
"list"
],
"resources": [
"events"
],
"resource_names": []
}
],
"metadata": {
"name": "event-reader",
"namespace": "default"
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/roles
HTTP/1.1 201 Created
API Specification
/roles (POST) | |
---|---|
description | Creates a Sensu role. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/roles |
payload |
|
response codes |
|
Get a specific role
The /roles/:role
API endpoint provides HTTP GET access to role data for specific :role
definitions, by role name.
Example
In the following example, querying the /roles/:role
API endpoint returns a JSON map that contains the requested :role
definition (in this example, for the :role
named read-only
).
curl -X GET \
http://127.0.0.1:8080/api/core/v2/namespaces/default/roles/read-only \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 200 OK
{
"rules": [
{
"verbs": [
"read"
],
"resources": [
"*"
],
"resource_names": null
}
],
"metadata": {
"name": "read-only",
"namespace": "default",
"created_by": "admin"
}
}
API Specification
/roles/:role (GET) | |
---|---|
description | Returns the specified Sensu role. |
example url | http://hostname:8080/api/core/v2/namespaces/default/roles/read-only |
response type | Map |
response codes |
|
output |
|
Create or update a role
The /roles/:role
API endpoint provides HTTP PUT access to create or update specific :role
definitions, by role name.
Example
In the following example, an HTTP PUT request is submitted to the /roles/:role
API endpoint to create the role read-only
.
The request returns a successful HTTP 201 Created
response.
curl -X PUT \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"rules": [
{
"verbs": [
"read"
],
"resources": [
"*"
],
"resource_names": null
}
],
"metadata": {
"name": "read-only",
"namespace": "default"
}
}' \
http://127.0.0.1:8080/api/core/v2/namespaces/default/roles/read-only
HTTP/1.1 201 Created
API Specification
/roles/:role (PUT) | |
---|---|
description | Creates or updates the specified Sensu role. |
example URL | http://hostname:8080/api/core/v2/namespaces/default/roles/event-reader |
payload |
|
response codes |
|
Delete a role
The /roles/:role
API endpoint provides HTTP DELETE access to delete a role from Sensu (specified by the role name).
Example
The following example shows a request to the /roles/:role
API endpoint to delete the role read-only
, resulting in a successful HTTP 204 No Content
response.
curl -X DELETE \
http://127.0.0.1:8080/api/core/v2/namespaces/default/roles/read-only \
-H "Authorization: Key $SENSU_API_KEY"
HTTP/1.1 204 No Content
API Specification
/roles/:role (DELETE) | |
---|---|
description | Removes the specified role from Sensu. |
example url | http://hostname:8080/api/core/v2/namespaces/default/roles/read-only |
response codes |
|