Skip to content

Commit c400dd0

Browse files
authored
Merge pull request #539 from docker/fix/export-no-default-collection
fix(keychain): export ErrNoDefaultCollection sentinel
2 parents 2348149 + 1d9e10b commit c400dd0

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

store/keychain/keychain.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ import (
2525

2626
var _ store.Store = &keychainStore[store.Secret]{}
2727

28+
// ErrNoDefaultCollection is returned when the secret service has no usable
29+
// default collection (no 'login' collection and no collection assigned to the
30+
// 'default' alias). This typically happens on headless hosts where the keyring
31+
// has not been initialized.
32+
//
33+
// NOTE: this condition is currently specific to the Linux keyring (the
34+
// freedesktop Secret Service). macOS and Windows have no equivalent "default
35+
// collection" concept, so the keychain store never returns this error on those
36+
// platforms. The sentinel is nonetheless declared here, in the cross-platform
37+
// file (rather than the Linux-specific one), so that platform-agnostic callers
38+
// can reference it on every platform without build tags. On non-Linux platforms
39+
// it simply never matches.
40+
//
41+
// It is exported so callers can use [errors.Is] to detect the absence of usable
42+
// keychain infrastructure and fall back gracefully, rather than relying on
43+
// fragile error message comparisons.
44+
var ErrNoDefaultCollection = errors.New("no default keychain collection available")
45+
2846
type (
2947
Option interface{ apply(any) error }
3048
optionFunc[K any] func(K) error

store/keychain/keychain_linux.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ const (
6262
secretServiceIsCollectionLockedProperty = "org.freedesktop.Secret.Collection.Locked"
6363
)
6464

65-
// errNoDefaultCollection is returned when the secret service has no usable
66-
// default collection (no 'login' collection and no collection assigned to the
67-
// 'default' alias). This typically happens on headless hosts where the keyring
68-
// has not been initialized.
69-
var errNoDefaultCollection = errors.New("no default keychain collection available")
70-
7165
// getDefaultCollection gets the secret service collection dbus object path.
7266
//
7367
// It prefers the loginKeychainObjectPath, since most users on X11 would have
@@ -122,7 +116,7 @@ func resolveDefaultCollection(collections []dbus.ObjectPath, aliasPath dbus.Obje
122116
// The null path is syntactically valid (so IsValid above returns true) but
123117
// does not point at a real collection, so it must be rejected explicitly.
124118
if aliasPath == nullObjectPath {
125-
return "", errNoDefaultCollection
119+
return "", ErrNoDefaultCollection
126120
}
127121

128122
return aliasPath, nil

store/keychain/keychain_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestResolveDefaultCollection(t *testing.T) {
5353
// ReadAlias returns the null object path "/"
5454
collections: []dbus.ObjectPath{},
5555
aliasPath: nullObjectPath,
56-
wantErr: errNoDefaultCollection,
56+
wantErr: ErrNoDefaultCollection,
5757
},
5858
{
5959
name: "rejects syntactically invalid alias path",

0 commit comments

Comments
 (0)