checking in, tests left

This commit is contained in:
brent s. 2021-12-23 04:21:21 -05:00
parent 25f9c3c1c9
commit 6c64681bc8
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
8 changed files with 206 additions and 75 deletions

4
TODO
View File

@ -2,8 +2,6 @@
-- compat with kwalletmanager
--- Will require conversion to different struct model.

- Write* and Create*/New* methods
-- return relevant entry as native item
-- confirm i'm checking the result code for all of them.
- walletCheck on all items' operations?

- TESTS

View File

@ -38,6 +38,30 @@ func NewBlob(f *Folder, keyName string, recursion *RecurseOpts) (blob *Blob, err
return
}

// Delete will delete this Blob from its parent Folder. You may want to run Folder.UpdateBlobs to update the existing map of Blob items.
func (b *Blob) Delete() (err error) {

if err = b.folder.RemoveEntry(b.Name); err != nil {
return
}

b = nil

return
}

// SetValue will replace this Blob's Blob.Value.
func (b *Blob) SetValue(newValue []byte) (err error) {

if _, err = b.folder.WriteBlob(b.Name, newValue); err != nil {
return
}

b.Value = newValue

return
}

// Update fetches a Blob's Blob.Value.
func (b *Blob) Update() (err error) {


View File

@ -44,6 +44,21 @@ func NewFolder(w *Wallet, name string, recursion *RecurseOpts) (folder *Folder,
return
}

/*
Delete will delete this Folder, and all its WalletItems, from the parent Wallet.
You may want to run Wallet.Update upon completion to update the Wallet.Folders cache if you're using it.
*/
func (f *Folder) Delete() (err error) {

if err = f.wallet.RemoveFolder(f.Name); err != nil {
return
}

f = nil

return
}

// HasEntry specifies if a Folder has an entry (WalletItem item) by the give entryName.
func (f *Folder) HasEntry(entryName string) (hasEntry bool, err error) {

@ -153,73 +168,6 @@ func (f *Folder) Update() (err error) {
return
}

// UpdatePasswords updates (populates) a Folder's Folder.Passwords.
func (f *Folder) UpdatePasswords() (err error) {

var mapKeys []string
var variant dbus.Variant
var errs []error = make([]error, 0)

if !f.isInit {
err = ErrNotInitialized
return
}

if err = f.Dbus.Call(
DbusWMPasswordList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
).Store(&variant); err != nil {
return
}

mapKeys = bytemapKeys(variant)

f.Passwords = make(map[string]*Password, len(mapKeys))

for _, k := range mapKeys {
if f.Passwords[k], err = NewPassword(f, k, f.Recurse); err != nil {
errs = append(errs, err)
err = nil
}
}

if errs != nil && len(errs) > 0 {
err = NewErrors(errs...)
}

return
}

// UpdateMaps updates (populates) a Folder's Folder.Maps.
func (f *Folder) UpdateMaps() (err error) {

var mapKeys []string
var variant dbus.Variant
var errs []error = make([]error, 0)

if err = f.Dbus.Call(
DbusWMMapList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
).Store(&variant); err != nil {
return
}

mapKeys = bytemapKeys(variant)

f.Maps = make(map[string]*Map, len(mapKeys))

for _, k := range mapKeys {
if f.Maps[k], err = NewMap(f, k, f.Recurse); err != nil {
errs = append(errs, err)
err = nil
}
}

if errs != nil && len(errs) > 0 {
err = NewErrors(errs...)
}

return
}

// UpdateBlobs updates (populates) a Folder's Folder.BinaryData.
func (f *Folder) UpdateBlobs() (err error) {

@ -256,6 +204,76 @@ func (f *Folder) UpdateBlobs() (err error) {
if f.BinaryData[k], err = NewBlob(f, k, f.Recurse); err != nil {
errs = append(errs, err)
err = nil
continue
}
}

if errs != nil && len(errs) > 0 {
err = NewErrors(errs...)
}

return
}

// UpdateMaps updates (populates) a Folder's Folder.Maps.
func (f *Folder) UpdateMaps() (err error) {

var mapKeys []string
var variant dbus.Variant
var errs []error = make([]error, 0)

if err = f.Dbus.Call(
DbusWMMapList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
).Store(&variant); err != nil {
return
}

mapKeys = bytemapKeys(variant)

f.Maps = make(map[string]*Map, len(mapKeys))

for _, k := range mapKeys {
if f.Maps[k], err = NewMap(f, k, f.Recurse); err != nil {
errs = append(errs, err)
err = nil
continue
}
}

if errs != nil && len(errs) > 0 {
err = NewErrors(errs...)
}

return
}

// UpdatePasswords updates (populates) a Folder's Folder.Passwords.
func (f *Folder) UpdatePasswords() (err error) {

var mapKeys []string
var variant dbus.Variant
var errs []error = make([]error, 0)

if !f.isInit {
err = ErrNotInitialized
return
}

if err = f.Dbus.Call(
DbusWMPasswordList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
).Store(&variant); err != nil {
return
}

mapKeys = bytemapKeys(variant)

f.Passwords = make(map[string]*Password, len(mapKeys))

for _, k := range mapKeys {
if f.Passwords[k], err = NewPassword(f, k, f.Recurse); err != nil {
errs = append(errs, err)
err = nil
continue
}
}

@ -302,6 +320,7 @@ func (f *Folder) UpdateUnknowns() (err error) {
if f.Unknown[k], err = NewUnknownItem(f, k, f.Recurse); err != nil {
errs = append(errs, err)
err = nil
continue
}
}

@ -313,12 +332,16 @@ func (f *Folder) UpdateUnknowns() (err error) {
}

// WriteBlob adds or replaces a Blob to/in a Folder.
func (f *Folder) WriteBlob(entryName string, entryValue []byte) (err error) {
func (f *Folder) WriteBlob(entryName string, entryValue []byte) (b *Blob, err error) {

if err = f.WriteEntry(entryName, KwalletdEnumTypeStream, entryValue); err != nil {
return
}

if b, err = NewBlob(f, entryName, f.Recurse); err != nil {
return
}

return
}

@ -348,7 +371,7 @@ func (f *Folder) WriteEntry(entryName string, entryType kwalletdEnumType, entryV
}

// WriteMap adds or replaces a Map to/in a Folder.
func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (err error) {
func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (m *Map, err error) {

var rslt int32
var b []byte
@ -365,11 +388,15 @@ func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (err e

err = resultCheck(rslt)

if m, err = NewMap(f, entryName, f.Recurse); err != nil {
return
}

return
}

// WritePassword adds or replaces a Password to/in a Folder.
func (f *Folder) WritePassword(entryName, entryValue string) (err error) {
func (f *Folder) WritePassword(entryName, entryValue string) (p *Password, err error) {

var rslt int32

@ -381,16 +408,24 @@ func (f *Folder) WritePassword(entryName, entryValue string) (err error) {

err = resultCheck(rslt)

if p, err = NewPassword(f, entryName, f.Recurse); err != nil {
return
}

return
}

// WriteUnknown adds or replaces an UnknownItem to/in a Folder.
func (f *Folder) WriteUnknown(entryName string, entryValue []byte) (err error) {
func (f *Folder) WriteUnknown(entryName string, entryValue []byte) (u *UnknownItem, err error) {

if err = f.WriteEntry(entryName, KwalletdEnumTypeUnknown, entryValue); err != nil {
return
}

if u, err = NewUnknownItem(f, entryName, f.Recurse); err != nil {
return
}

return
}


View File

@ -34,6 +34,30 @@ func NewMap(f *Folder, keyName string, recursion *RecurseOpts) (m *Map, err erro
return
}

// Delete will delete this Map from its parent Folder. You may want to run Folder.UpdateMaps to update the existing map of Map items.
func (m *Map) Delete() (err error) {

if err = m.folder.RemoveEntry(m.Name); err != nil {
return
}

m = nil

return
}

// SetValue will replace this Map's Map.Value.
func (m *Map) SetValue(newValue map[string]string) (err error) {

if _, err = m.folder.WriteMap(m.Name, newValue); err != nil {
return
}

m.Value = newValue

return
}

// Update fetches a Map's Map.Value.
func (m *Map) Update() (err error) {


View File

@ -34,6 +34,30 @@ func NewPassword(f *Folder, keyName string, recursion *RecurseOpts) (password *P
return
}

// Delete will delete this Password from its parent Folder. You may want to run Folder.UpdatePasswords to update the existing map of Password items.
func (p *Password) Delete() (err error) {

if err = p.folder.RemoveEntry(p.Name); err != nil {
return
}

p = nil

return
}

// SetValue will replace this Password's Password.Value.
func (p *Password) SetValue(newValue string) (err error) {

if _, err = p.folder.WritePassword(p.Name, newValue); err != nil {
return
}

p.Value = newValue

return
}

// Update fetches a Password's Password.Value.
func (p *Password) Update() (err error) {


View File

@ -38,6 +38,30 @@ func NewUnknownItem(f *Folder, keyName string, recursion *RecurseOpts) (unknown
return
}

// Delete will delete this UnknownItem from its parent Folder. You may want to run Folder.UpdateUnknowns to update the existing map of UnknownItem items.
func (u *UnknownItem) Delete() (err error) {

if err = u.folder.RemoveEntry(u.Name); err != nil {
return
}

u = nil

return
}

// SetValue will replace this UnknownItem's UnknownItem.Value.
func (u *UnknownItem) SetValue(newValue []byte) (err error) {

if _, err = u.folder.WriteUnknown(u.Name, newValue); err != nil {
return
}

u.Value = newValue

return
}

// Update fetches an UnknownItem's UnknownItem.Value.
func (u *UnknownItem) Update() (err error) {


View File

@ -179,6 +179,8 @@ func (w *Wallet) Delete() (err error) {

err = resultCheck(rslt)

w = nil

return
}


View File

@ -36,7 +36,7 @@ func NewWalletManager(recursion *RecurseOpts, appID ...string) (wm *WalletManage
or provide your own RecurseOpts struct).
If appId is empty, DefaultAppID will be used as the app ID.
*/
/* TODO: POC this before exposing. I have NO idea if it'll work.
/* TODO: POC this before exposing. I have NO idea if/how it'll work.
func NewWalletManagerFiles(recursion *RecurseOpts, appId string, filePaths ...string) (wm *WalletManager, err error) {

var exist bool