Adding IsAvailable to the interface
snorberhuis opened this issue · comments
I am integrating this library in a project of mine and I am running into the issue that I want to bypass caching if it is not available locally.
A method added to the interface would be helpful. The method IsAvailable
would check if the service is available. I looked at the source and saw that it might have been already tried to add a function like IsAvailable
. I see a commented out function:
// func (*MacOSXKeychain) IsAvailable() bool {
// return exec.Command(execPathKeychain).Run() != exec.ErrNotFound
// }
Before I go into developing this more deeply, I was wondering if you tried to adding this method and have come into fundamental problems that prevent implementation.
We can also discuss if this is a good feature to be merged upstream into this library.
Hi, I completely lost track of this issue, sorry about that!
There is already this special error: https://github.com/zalando/go-keyring/blob/master/keyring_darwin.go#L43 returned from Get()
so you can just check if this error is returned and handle the is-not-available case.
Line 47 in 9725ced
ErrNotFound
merely indicates that the secret was not found. You'd get that error when you just hadn't yet stored a secret.
I am (and I think the OP is) looking for a method that checks for security
/dbus
/libsecret
/etc. being available, so external code can find a fallback to store secrets via another library or other behavior.
Alternatively a different special error should be returned in that case. Perhaps it could reuse or wrap the ErrUnsupportedPlatform
error, because it's pretty much the same problem. I think that would work just as well as the method.
I am (and I think the OP is) looking for a method that checks for
security
/dbus
/libsecret
/etc. being available, so external code can find a fallback to store secrets via another library or other behavior.
A fallback solution can be beneficial. A hashed file can be a simple solution for this. There is already a fallback provider. We just need to implement a file solution for it. Happy to work on it if it is okay for maintainers.