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/>.
23 #include "virsh-completer-secret.h"
24 #include "virsh-secret.h"
25 #include "virsh-util.h"
29 virshSecretUUIDCompleter(vshControl
*ctl
,
30 const vshCmd
*cmd G_GNUC_UNUSED
,
33 virshControl
*priv
= ctl
->privData
;
34 virSecretPtr
*secrets
= NULL
;
38 g_auto(GStrv
) tmp
= NULL
;
40 virCheckFlags(0, NULL
);
42 if (!priv
->conn
|| virConnectIsAlive(priv
->conn
) <= 0)
45 if ((nsecrets
= virConnectListAllSecrets(priv
->conn
, &secrets
, flags
)) < 0)
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)
55 tmp
[i
] = g_strdup(uuid
);
58 ret
= g_steal_pointer(&tmp
);
61 for (i
= 0; i
< nsecrets
; i
++)
62 virshSecretFree(secrets
[i
]);
69 virshSecretEventNameCompleter(vshControl
*ctl G_GNUC_UNUSED
,
70 const vshCmd
*cmd G_GNUC_UNUSED
,
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
);