File: capabilities.py

package info (click to toggle)
python-hvac 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: python: 29,360; makefile: 42; sh: 14
file content (43 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from hvac.api.system_backend.system_backend_mixin import SystemBackendMixin


class Capabilities(SystemBackendMixin):
    def get_capabilities(self, paths, token=None, accessor=None):
        """Get the capabilities associated with a token.

        Supported methods:
            POST: /sys/capabilities-self. Produces: 200 application/json
            POST: /sys/capabilities. Produces: 200 application/json
            POST: /sys/capabilities-accessor. Produces: 200 application/json

        :param paths: Paths on which capabilities are being queried.
        :type paths: List[str]
        :param token: Token for which capabilities are being queried.
        :type token: str
        :param accessor: Accessor of the token for which capabilities are being queried.
        :type accessor: str
        :return: The JSON response of the request.
        :rtype: dict
        """
        params = {
            "paths": paths,
        }

        if token and accessor:
            raise ValueError("You can specify either token or accessor, not both.")
        elif token:
            # https://www.vaultproject.io/api/system/capabilities.html
            params["token"] = token
            api_path = "/v1/sys/capabilities"
        elif accessor:
            # https://www.vaultproject.io/api/system/capabilities-accessor.html
            params["accessor"] = accessor
            api_path = "/v1/sys/capabilities-accessor"
        else:
            # https://www.vaultproject.io/api/system/capabilities-self.html
            api_path = "/v1/sys/capabilities-self"

        return self._adapter.post(
            url=api_path,
            json=params,
        )