forked from dmacvicar/libvirt-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret.go
78 lines (68 loc) · 1.61 KB
/
secret.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package libvirt
/*
#cgo LDFLAGS: -lvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
type VirSecret struct {
ptr C.virSecretPtr
}
func (s *VirSecret) Free() error {
if result := C.virSecretFree(s.ptr); result != 0 {
return GetLastError()
}
return nil
}
func (s *VirSecret) Undefine() error {
result := C.virSecretUndefine(s.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (s *VirSecret) GetUUID() ([]byte, error) {
var cUuid [C.VIR_UUID_BUFLEN](byte)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virSecretGetUUID(s.ptr, (*C.uchar)(cuidPtr))
if result != 0 {
return []byte{}, GetLastError()
}
return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
}
func (s *VirSecret) GetUUIDString() (string, error) {
var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virSecretGetUUIDString(s.ptr, (*C.char)(cuidPtr))
if result != 0 {
return "", GetLastError()
}
return C.GoString((*C.char)(cuidPtr)), nil
}
func (s *VirSecret) GetUsageID() (string, error) {
result := C.virSecretGetUsageID(s.ptr)
if result == nil {
return "", GetLastError()
}
return C.GoString(result), nil
}
func (s *VirSecret) GetUsageType() (int, error) {
result := int(C.virSecretGetUsageType(s.ptr))
if result == -1 {
return 0, GetLastError()
}
return result, nil
}
func (s *VirSecret) GetXMLDesc(flags uint32) (string, error) {
result := C.virSecretGetXMLDesc(s.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}