Roles API

The /roles API endpoint

/roles (GET)

The /roles API endpoint provides HTTP GET access to role data.

EXAMPLE

The following example demonstrates a request to the /roles API, resulting in a JSON Array containing role definitions.

curl http://127.0.0.1:8080/api/core/v2/namespaces/default/roles -H "Authorization: Bearer $TOKEN"

HTTP/1.1 200 OK
[
  {
    "rules": [
      {
        "verbs": [
          "read"
        ],
        "resources": [
          "*"
        ],
        "resource_names": null
      }
    ],
    "metadata": {
      "name": "read-only",
      "namespace": "default"
    }
  }
]

API Specification

/roles (GET)
description Returns the list of roles.
example url http://hostname:8080/api/core/v2/namespaces/default/roles
response type Array
response codes
  • Success: 200 (OK)
  • Error: 500 (Internal Server Error)
output
[
  {
    "rules": [
      {
        "verbs": [
          "read"
        ],
        "resources": [
          "*"
        ],
        "resource_names": null
      }
    ],
    "metadata": {
      "name": "read-only",
      "namespace": "default"
    }
  }
]

/roles (POST)

/roles (POST)
description Create a Sensu role.
example URL http://hostname:8080/api/core/v2/namespaces/default/roles
payload
{
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": []
    }
  ],
  "metadata": {
    "name": "event-reader",
    "namespace": "default"
  }
}
response codes
  • Success: 200 (OK)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

The /roles/:role API endpoint

/roles/:role (GET)

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 returns a JSON Map containing the requested :role definition (in this example: for the :role named read-only).

curl http://127.0.0.1:8080/api/core/v2/namespaces/default/roles/read-only -H "Authorization: Bearer $TOKEN"

HTTP/1.1 200 OK
{
  "rules": [
    {
      "verbs": [
        "read"
      ],
      "resources": [
        "*"
      ],
      "resource_names": null
    }
  ],
  "metadata": {
    "name": "read-only",
    "namespace": "default"
  }
}

API Specification

/roles/:role (GET)
description Returns a role.
example url http://hostname:8080/api/core/v2/namespaces/default/roles/read-only
response type Map
response codes
  • Success: 200 (OK)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)
output
{
  "rules": [
    {
      "verbs": [
        "read"
      ],
      "resources": [
        "*"
      ],
      "resource_names": null
    }
  ],
  "metadata": {
    "name": "read-only",
    "namespace": "default"
  }
}

/roles/:role (PUT)

API Specification

/roles/:role (PUT)
description Create or update a Sensu role.
example URL http://hostname:8080/api/core/v2/namespaces/default/roles/event-reader
payload
{
  "rules": [
    {
      "verbs": [
        "get",
        "list"
      ],
      "resources": [
        "events"
      ],
      "resource_names": []
    }
  ],
  "metadata": {
    "name": "event-reader",
    "namespace": "default"
  }
}
response codes
  • Success: 201 (Created)
  • Malformed: 400 (Bad Request)
  • Error: 500 (Internal Server Error)

/roles/:role (DELETE)

API Specification

/roles/:role (DELETE)
description Removes a role from Sensu given the role name.
example url http://hostname:8080/api/core/v2/namespaces/default/roles/ready-only
response codes
  • Success: 202 (Accepted)
  • Missing: 404 (Not Found)
  • Error: 500 (Internal Server Error)