mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
get_secret_value returned bytes, so the edit dialog showed b'cHc=' (the bytes' repr) for the base64 value cHc=. Saving the dialog as shown fed "b'cHc='" to b64decode, which dropped the quotes and the b and stored other bytes: the secret silently changed (pw became m\xc1\xdc). The value is now base64 text, and set_secret_value decodes with validate=True, so a value that is not base64 is refused with a message instead. The field had an invalid pattern ([a-zA-Z0-9]$+, ignored by browsers) and a 45 character limit; it takes base64 of any length.
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
import base64
|
|
|
|
from lxml import etree
|
|
from vrtManager.connection import wvmConnect
|
|
|
|
# the element of <usage> that holds the value, per usage type
|
|
USAGE_ELEMENTS = {"ceph": "name", "volume": "volume", "iscsi": "target"}
|
|
|
|
|
|
class wvmSecrets(wvmConnect):
|
|
def create_secret(self, ephemeral, private, secret_type, data):
|
|
# built with lxml: data is text, whatever characters it holds
|
|
secret = etree.Element("secret", ephemeral=ephemeral, private=private)
|
|
usage = etree.SubElement(secret, "usage", type=secret_type)
|
|
etree.SubElement(usage, USAGE_ELEMENTS[secret_type]).text = data
|
|
self.wvm.secretDefineXML(etree.tostring(secret, encoding="unicode"))
|
|
|
|
def get_secret_value(self, uuid):
|
|
"""The value as base64 text, the form set_secret_value takes."""
|
|
secrt = self.get_secret(uuid)
|
|
return base64.b64encode(secrt.value()).decode()
|
|
|
|
def set_secret_value(self, uuid, value):
|
|
secrt = self.get_secret(uuid)
|
|
# validate: a value that is not base64 is refused, not decoded to other bytes
|
|
secrt.setValue(base64.b64decode(value, validate=True))
|
|
|
|
def delete_secret(self, uuid):
|
|
secrt = self.get_secret(uuid)
|
|
secrt.undefine()
|