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 -s http://127.0.0.1:8080/api/core/v2/namespaces/default/roles -H "Authorization: Bearer TOKEN"
[
  {
    "name": "admin",
    "rules": [
      {
        "type": "*",
        "permissions": [
          "create",
          "read",
          "update",
          "delete"
        ],
        "namespace": "*"
      }
    ]
  },
  {
    "name": "read-only",
    "rules": [
      {
        "type": "*",
        "permissions": [
          "read"
        ],
        "namespace": "*"
      }
    ]
  }
]

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
[
  {
    "name": "admin",
    "rules": [
      {
        "type": "*",
        "permissions": [
          "create",
          "read",
          "update",
          "delete"
        ],
        "namespace": "*"
      }
    ]
  },
  {
    "name": "read-only",
    "rules": [
      {
        "type": "*",
        "permissions": [
          "read"
        ],
        "namespace": "*"
      }
    ]
  }
]

/roles (POST)

/roles (POST)
description Create a Sensu role.
example URL http://hostname:8080/api/core/v2/roles/default/roles
payload
{
  "name": "read-only",
  "rules": [
    {
      "type": "*",
      "permissions": [
        "read"
      ],
      "namespace": "*"
    }
  ]
}
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 -s http://127.0.0.1:8080/api/core/v2/namespaces/default/roles/read-only -H "Authorization: Bearer TOKEN"
{
  "name": "read-only",
  "rules": [
    {
      "type": "*",
      "permissions": [
        "read"
      ],
      "namespace": "*"
    }
  ]
}

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
{
  "name": "read-only",
  "rules": [
    {
      "type": "*",
      "permissions": [
        "read"
      ],
      "namespace": "*"
    }
  ]
}

/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/ready-only
payload
{
  "name": "read-only",
  "rules": [
    {
      "type": "*",
      "permissions": [
        "read"
      ],
      "namespace": "*"
    }
  ]
}
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)