示例#1
0
    def set(self, key: str, value: Any) -> bool:
        """Set key with given value.

        :params key: Key name.
        :params value: Value of the key.
        :returns: A ``bool`` to mark whether config is set or not.
        """
        return self.client.kv.put(self._merge_path(key), safe_value(value))
示例#2
0
    def set(self, key: str, value: Any) -> bool:
        """Set key with given value.

        :params key: Key name.
        :params value: Value of the key.
        :returns: A ``bool`` to mark whether config is set or not.
        """
        self._authenticate()
        val = {"value": safe_value(value)}

        # hvac.v1.Client.write checks for status code 200,
        # but Vault HTTP API returns 205 if request succeeded;
        # hence we're using lower level of `hvac.v1.Client` API to set key-val
        response = self.client._adapter.post(
            f"/v1/{self.prefix}/{key}", json=val
        )
        return response.status_code == 204
示例#3
0
    def set(self, key: str, value: Any) -> bool:
        """Set key with given value.

        :params key: Key name.
        :params value: Value of the key.
        :returns: A ``bool`` to mark whether config is set or not.
        """
        self._prepare_secret()
        body = {
            "kind": "Secret",
            "apiVersion": "v1",
            "metadata": {
                "name": self.settings["GLUU_SECRET_KUBERNETES_SECRET"]
            },
            "data": {
                key: base64.b64encode(safe_value(value).encode()).decode()
            },
        }
        ret = self.client.patch_namespaced_secret(
            self.settings["GLUU_SECRET_KUBERNETES_SECRET"],
            self.settings["GLUU_SECRET_KUBERNETES_NAMESPACE"],
            body=body,
        )
        return bool(ret)
    def set(self, key: str, value: Any) -> bool:
        """Set key with given value.

        :params key: Key name.
        :params value: Value of the key.
        :returns: A ``bool`` to mark whether config is set or not.
        """
        self._prepare_configmap()
        body = {
            "kind": "ConfigMap",
            "apiVersion": "v1",
            "metadata": {
                "name": self.settings["GLUU_CONFIG_KUBERNETES_CONFIGMAP"]
            },
            "data": {
                key: safe_value(value)
            },
        }
        ret = self.client.patch_namespaced_config_map(
            self.settings["GLUU_CONFIG_KUBERNETES_CONFIGMAP"],
            self.settings["GLUU_CONFIG_KUBERNETES_NAMESPACE"],
            body=body,
        )
        return bool(ret)
def test_safe_value(value, expected):
    from pygluu.containerlib.utils import safe_value
    assert safe_value(value) == expected