How to use the hvac.utils.format_url function in hvac

To help you get started, we’ve selected a few hvac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
def list_roles(self, mount_point=DEFAULT_MOUNT_POINT):
        """List Roles.

        Get a list of available roles.

        Supported methods:
            LIST: /{mount_point}/roles. Produces: 200 application/json

        :param mount_point: The "path" the method/backend was mounted on.
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: dict
        """
        api_path = utils.format_url('/v1/{mount_point}/roles', mount_point=mount_point)
        response = self._adapter.list(
            url=api_path,
        )
        return response.json()
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
Creates or updates the role definition.

        Supported methods:
            POST: /{mount_point}/roles/{name}. Produces: 200 application/json

        :param name: The name of the role to create.
        :name name: str | unicode
        :param extra_params: A dictionary with extra parameters.
        :name extra_params: dict
        :param mount_point: The "path" the method/backend was mounted on.
        :name mount_point: str | unicode
        :return: The JSON response of the request.
        :rname: requests.Response
        """
        api_path = utils.format_url(
            '/v1/{mount_point}/roles/{name}',
            mount_point=mount_point,
            name=name,
        )

        params = extra_params
        params['name'] = name

        return self._adapter.post(
            url=api_path,
            json=params,
        )
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
def read_certificate(self, serial, mount_point=DEFAULT_MOUNT_POINT):
        """Read Certificate.

        Retrieves one of a selection of certificates.

        Supported methods:
            GET: /{mount_point}/cert/{serial}. Produces: 200 application/json

        :param serial: the serial of the key to read.
        :type serial: str | unicode
        :param mount_point: The "path" the method/backend was mounted on.
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: dict
        """
        api_path = utils.format_url(
            '/v1/{mount_point}/cert/{serial}',
            mount_point=mount_point,
            serial=serial,
        )
        response = self._adapter.get(
            url=api_path,
        )
        return response.json()
github hvac / hvac / hvac / api / secrets_engines / rabbitmq.py View on Github external
def create_role(self, name, tags="", vhosts="", mount_point=DEFAULT_MOUNT_POINT):
        """This endpoint creates or updates the role definition.

        :param name:  Specifies the name of the role to create.
        :type name: str | unicode
        :param tags:  Specifies a comma-separated RabbitMQ management tags.
        :type tags: str | unicode
        :param vhosts:  pecifies a map of virtual hosts to permissions.
        :type vhosts: str | unicode
        :param mount_point: Specifies the place where the secrets engine will be accessible (default: rabbitmq).
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        api_path = utils.format_url("/v1/{}/roles/{}", mount_point, name)
        params = {
            "tags": tags,
            "vhosts": vhosts,
        }
        return self._adapter.post(
            url=api_path,
            json=params,
        )
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
Supported methods:
            POST: /{mount_point}/intermediate/generate/{type}. Produces: 200 application/json

        :param type: Specifies the type to create. `exported` (private key also exported) or `internal`.
        :type type: str | unicode
        :param common_name: Specifies the requested CN for the certificate.
        :type common_name: str | unicode
        :param extra_params: Dictionary with extra parameters.
        :type extra_params: dict
        :param mount_point: The "path" the method/backend was mounted on.
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        api_path = utils.format_url(
            '/v1/{mount_point}/intermediate/generate/{type}',
            mount_point=mount_point,
            type=type,
        )

        params = extra_params
        params['common_name'] = common_name

        return self._adapter.post(
            url=api_path,
            json=params,
        )
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
:param csr: The PEM-encoded CSR.
        :type csr: str | unicode
        :param name: Specifies a role.
        :type name: str | unicode
        :param extra_params: A dictionary with extra parameters.
        :type extra_params: dict
        :param mount_point: The "path" the method/backend was mounted on.
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        url_to_transform = '/v1/{mount_point}/sign-verbatim'
        if name:
            url_to_transform = url_to_transform + '/{name}'

        api_path = utils.format_url(
            url_to_transform,
            mount_point=mount_point,
            name=name,
        )

        params = extra_params
        params['csr'] = csr

        return self._adapter.post(
            url=api_path,
            json=params,
        )
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
def set_crl_configuration(self, expiry=None, disable=None, extra_params={}, mount_point=DEFAULT_MOUNT_POINT):
        """Set CRL Configuration.

        Setting the duration for which the generated CRL should be marked valid.
        If the CRL is disabled, it will return a signed but zero-length CRL for any
        request. If enabled, it will re-build the CRL.

        Supported methods:
            POST: /{mount_point}/config/crl. Produces: 200 application/json

        :param mount_point: The "path" the method/backend was mounted on.
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        api_path = utils.format_url('/v1/{mount_point}/config/crl', mount_point=mount_point)
        params = extra_params
        if expiry is not None:
            params['expiry'] = expiry
        if disable is not None:
            params['disable'] = disable

        return self._adapter.post(
            url=api_path,
            json=params,
        )
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
def delete_root(self, mount_point=DEFAULT_MOUNT_POINT):
        """Delete Root.

        Deletes the current CA key.

        Supported methods:
            DELETE: /{mount_point}/root. Produces: 200 application/json

        :param mount_point: The "path" the method/backend was mounted on.
        :type mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        api_path = utils.format_url(
            '/v1/{mount_point}/root',
            mount_point=mount_point,
        )

        return self._adapter.delete(
            url=api_path,
        )
github hvac / hvac / hvac / api / secrets_engines / pki.py View on Github external
def revoke_certificate(self, serial_number, mount_point=DEFAULT_MOUNT_POINT):
        """Revoke Certificate.

        Revokes a certificate using its serial number.

        Supported methods:
            POST: /{mount_point}/revoke. Produces: 200 application/json

        :param serial_number: The serial number of the certificate to revoke.
        :name serial_number: str | unicode
        :param mount_point: The "path" the method/backend was mounted on.
        :name mount_point: str | unicode
        :return: The JSON response of the request.
        :rtype: requests.Response
        """
        api_path = utils.format_url('/v1/{mount_point}/revoke', mount_point=mount_point)

        params = {}
        params['serial_number'] = serial_number

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