Skip to content

Commit 2f1d06a

Browse files
committed
store/keychain: linux define secret service interface as consts
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent 7363f4b commit 2f1d06a

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

store/keychain/keychain_linux.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// The keychain package for Linux uses the org.freedesktop.secret service API
2+
// over dbus.
3+
// For more information on the Secret Service API, see https://specifications.freedesktop.org/secret-service-spec/latest/index.html.
14
package keychain
25

36
import (
@@ -17,6 +20,21 @@ const (
1720
//
1821
// NOTE: do not use this directly, always call [getDefaultCollection]
1922
loginKeychainObjectPath = dbus.ObjectPath("/org/freedesktop/secrets/collection/login")
23+
24+
// used to list all available collections on the secret service API
25+
//
26+
// https://specifications.freedesktop.org/secret-service-spec/latest/org.freedesktop.Secret.Service.html
27+
secretServiceCollectionProperty = "org.freedesktop.Secret.Service.Collections"
28+
29+
// used to get the dbus object path of an aliased collection
30+
// An common alias would be 'default'
31+
// https://specifications.freedesktop.org/secret-service-spec/latest/org.freedesktop.Secret.Service.html
32+
secretServiceGetAliasObjectPath = "org.freedesktop.Secret.Service.ReadAlias"
33+
34+
// used to check if the collection is locked
35+
//
36+
// https://specifications.freedesktop.org/secret-service-spec/latest/org.freedesktop.Secret.Collection.html
37+
secretServiceIsCollectionLockedProperty = "org.freedesktop.Secret.Collection.Locked"
2038
)
2139

2240
// newItemAttributes configures the default attributes for each item in the keychain
@@ -43,7 +61,7 @@ func newItemAttributes[T store.Secret](id store.ID, k *keychainStore[T]) map[str
4361
// It is possible that the host does not have a collection set up, in that case
4462
// the only option is to error.
4563
func getDefaultCollection(service *kc.SecretService) (dbus.ObjectPath, error) {
46-
variant, err := service.ServiceObj().GetProperty("org.freedesktop.Secret.Service.Collections")
64+
variant, err := service.ServiceObj().GetProperty(secretServiceCollectionProperty)
4765
if err != nil {
4866
return "", err
4967
}
@@ -58,7 +76,7 @@ func getDefaultCollection(service *kc.SecretService) (dbus.ObjectPath, error) {
5876
// we need to fallback to the default collection
5977
var defaultKeychainObjectPath dbus.ObjectPath
6078
err = service.ServiceObj().
61-
Call("org.freedesktop.Secret.Service.ReadAlias", 0, "default").
79+
Call(secretServiceGetAliasObjectPath, 0, "default").
6280
Store(&defaultKeychainObjectPath)
6381
if err != nil {
6482
return "", err
@@ -78,7 +96,7 @@ var errCollectionLocked = errors.New("collection is locked")
7896
// It returns the errCollectionLocked error by default if the collection is locked.
7997
// On any other error, it returns the underlying error instead.
8098
func isCollectionLocked(service *kc.SecretService) error {
81-
variant, err := service.ServiceObj().GetProperty("org.freedesktop.Secret.Collection.Locked")
99+
variant, err := service.ServiceObj().GetProperty(secretServiceIsCollectionLockedProperty)
82100
if err != nil {
83101
return err
84102
}

0 commit comments

Comments
 (0)