mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
util: Introduce virSecretLookupFormatSecret
Add utility to format the virSecretLookupTypeDefPtr in XML Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
ecd45ced0e
commit
42510c5199
@ -2221,6 +2221,7 @@ virSecurityLabelDefNew;
|
|||||||
# util/virsecret.h
|
# util/virsecret.h
|
||||||
virSecretLookupDefClear;
|
virSecretLookupDefClear;
|
||||||
virSecretLookupDefCopy;
|
virSecretLookupDefCopy;
|
||||||
|
virSecretLookupFormatSecret;
|
||||||
virSecretLookupParseSecret;
|
virSecretLookupParseSecret;
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,3 +99,26 @@ virSecretLookupParseSecret(xmlNodePtr secretnode,
|
|||||||
VIR_FREE(usage);
|
VIR_FREE(usage);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
virSecretLookupFormatSecret(virBufferPtr buf,
|
||||||
|
const char *secrettype,
|
||||||
|
virSecretLookupTypeDefPtr def)
|
||||||
|
{
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
|
if (secrettype)
|
||||||
|
virBufferAsprintf(buf, "<secret type='%s'", secrettype);
|
||||||
|
else
|
||||||
|
virBufferAddLit(buf, "<secret");
|
||||||
|
|
||||||
|
if (def->type == VIR_SECRET_LOOKUP_TYPE_UUID) {
|
||||||
|
virUUIDFormat(def->u.uuid, uuidstr);
|
||||||
|
virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
|
||||||
|
} else if (def->type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
|
||||||
|
virBufferEscapeString(buf, " usage='%s'/>\n", def->u.usage);
|
||||||
|
} else {
|
||||||
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -50,4 +50,7 @@ int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
|
|||||||
const virSecretLookupTypeDef *src);
|
const virSecretLookupTypeDef *src);
|
||||||
int virSecretLookupParseSecret(xmlNodePtr secretnode,
|
int virSecretLookupParseSecret(xmlNodePtr secretnode,
|
||||||
virSecretLookupTypeDefPtr def);
|
virSecretLookupTypeDefPtr def);
|
||||||
|
void virSecretLookupFormatSecret(virBufferPtr buf,
|
||||||
|
const char *secrettype,
|
||||||
|
virSecretLookupTypeDefPtr def);
|
||||||
#endif /* __VIR_SECRET_H__ */
|
#endif /* __VIR_SECRET_H__ */
|
||||||
|
@ -1623,8 +1623,6 @@ int
|
|||||||
virStorageAuthDefFormat(virBufferPtr buf,
|
virStorageAuthDefFormat(virBufferPtr buf,
|
||||||
virStorageAuthDefPtr authdef)
|
virStorageAuthDefPtr authdef)
|
||||||
{
|
{
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
|
|
||||||
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
|
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
|
||||||
virBufferEscapeString(buf, "<auth username='%s'>\n", authdef->username);
|
virBufferEscapeString(buf, "<auth username='%s'>\n", authdef->username);
|
||||||
} else {
|
} else {
|
||||||
@ -1634,20 +1632,8 @@ virStorageAuthDefFormat(virBufferPtr buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, 2);
|
virBufferAdjustIndent(buf, 2);
|
||||||
if (authdef->secrettype)
|
virSecretLookupFormatSecret(buf, authdef->secrettype,
|
||||||
virBufferAsprintf(buf, "<secret type='%s'", authdef->secrettype);
|
&authdef->seclookupdef);
|
||||||
else
|
|
||||||
virBufferAddLit(buf, "<secret");
|
|
||||||
|
|
||||||
if (authdef->seclookupdef.type == VIR_SECRET_LOOKUP_TYPE_UUID) {
|
|
||||||
virUUIDFormat(authdef->seclookupdef.u.uuid, uuidstr);
|
|
||||||
virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
|
|
||||||
} else if (authdef->seclookupdef.type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
|
|
||||||
virBufferEscapeString(buf, " usage='%s'/>\n",
|
|
||||||
authdef->seclookupdef.u.usage);
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
}
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</auth>\n");
|
virBufferAddLit(buf, "</auth>\n");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user