Skip to content

Commit 38441fa

Browse files
committed
store/keychain: improve linux godocs
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent a44f380 commit 38441fa

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

store/keychain/keychain_linux.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313

1414
const (
1515
// the default collection in most X11 sessions would be 'login'
16+
// it is created by default through PAM, see https://wiki.gnome.org/Projects/GnomeKeyring/Pam.
17+
//
18+
// NOTE: do not use this directly, always call [getDefaultCollection]
1619
loginKeychainObjectPath = dbus.ObjectPath("/org/freedesktop/secrets/collection/login")
1720
)
1821

@@ -30,10 +33,11 @@ func (k *keychainStore[T]) itemAttributes(id store.ID) map[string]string {
3033
// getDefaultCollection gets the secret service collection dbus object path.
3134
//
3235
// It prefers the loginKeychainObjectPath, since most users on X11 would have
33-
// this available.
36+
// this available via PAM, see https://wiki.gnome.org/Projects/GnomeKeyring/Pam.
3437
//
35-
// As a fallback it queries the secret service for the default collection and
36-
// returns that instead.
38+
// As a fallback it queries the secret service for the default collection.
39+
// It is possible that the host does not have a collection set up, in that case
40+
// the only option is to error.
3741
func (k *keychainStore[T]) getDefaultCollection(service *kc.SecretService) (dbus.ObjectPath, error) {
3842
variant, err := service.ServiceObj().GetProperty("org.freedesktop.Secret.Service.Collections")
3943
if err != nil {
@@ -56,6 +60,10 @@ func (k *keychainStore[T]) getDefaultCollection(service *kc.SecretService) (dbus
5660
return "", err
5761
}
5862

63+
if !defaultKeychainObjectPath.IsValid() {
64+
return "", errors.New("the default collection object path is invalid")
65+
}
66+
5967
return defaultKeychainObjectPath, nil
6068
}
6169

0 commit comments

Comments
 (0)