Post-release version bump to 11.0.0
[libvirt.git] / tools / virsh-completer-secret.c
blobf31127d0ce15b173abe3d2907ab6dd3b0eec0992
1 /*
2 * virsh-completer-secret.c: virsh completer callbacks related to secret
4 * Copyright (C) 2019 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 #include "virsh-completer-secret.h"
24 #include "virsh-secret.h"
25 #include "virsh-util.h"
26 #include "virsh.h"
28 char **
29 virshSecretUUIDCompleter(vshControl *ctl,
30 const vshCmd *cmd G_GNUC_UNUSED,
31 unsigned int flags)
33 virshControl *priv = ctl->privData;
34 virSecretPtr *secrets = NULL;
35 int nsecrets = 0;
36 size_t i = 0;
37 char **ret = NULL;
38 g_auto(GStrv) tmp = NULL;
40 virCheckFlags(0, NULL);
42 if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
43 return NULL;
45 if ((nsecrets = virConnectListAllSecrets(priv->conn, &secrets, flags)) < 0)
46 return NULL;
48 tmp = g_new0(char *, nsecrets + 1);
50 for (i = 0; i < nsecrets; i++) {
51 char uuid[VIR_UUID_STRING_BUFLEN];
53 if (virSecretGetUUIDString(secrets[i], uuid) < 0)
54 goto cleanup;
55 tmp[i] = g_strdup(uuid);
58 ret = g_steal_pointer(&tmp);
60 cleanup:
61 for (i = 0; i < nsecrets; i++)
62 virshSecretFree(secrets[i]);
63 g_free(secrets);
64 return ret;
68 char **
69 virshSecretEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
70 const vshCmd *cmd G_GNUC_UNUSED,
71 unsigned int flags)
73 size_t i;
74 g_auto(GStrv) tmp = NULL;
76 virCheckFlags(0, NULL);
78 tmp = g_new0(char *, VIR_SECRET_EVENT_ID_LAST + 1);
80 for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++)
81 tmp[i] = g_strdup(virshSecretEventCallbacks[i].name);
83 return g_steal_pointer(&tmp);