// SetValue sets the value of a secret. func (sec Secret) SetValue(value string) error { cSize := C.size_t(len(value)) cValue := (*C.uchar)(unsafe.Pointer(C.CString(value))) sec.log.Printf("setting secret value (%v)...\n", value) cRet := C.virSecretSetValue(sec.virSecret, cValue, cSize, 0) ret := int32(cRet) if ret == -1 { err := LastError() sec.log.Printf("an error occurred: %v\n", err) return err } sec.log.Println("value set") return nil }
func (c *VirConnection) SecretSetValue(uuid, value string) error { cUuid := C.CString(uuid) defer C.free(unsafe.Pointer(cUuid)) ptr := C.virSecretLookupByUUIDString(c.ptr, cUuid) if ptr == nil { return GetLastError() } secret, err := base64.StdEncoding.DecodeString(value) if err != nil { return err } cSecret := C.CString(string(secret)) defer C.free(unsafe.Pointer(cSecret)) res := C.virSecretSetValue(ptr, (*C.uchar)(unsafe.Pointer(cSecret)), C.size_t(len(secret)), 0) if res != 0 { return GetLastError() } return nil }