1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30
Commit Graph

29 Commits

Author SHA1 Message Date
Sebastiaan van Stijn 860f1459e3 pass: fix QF1001 (staticcheck)
pass/pass_test.go:86:6: QF1001: could apply De Morgan's law (staticcheck)
            if !(strings.HasSuffix(server, "2376/v1") || strings.HasSuffix(server, "2375/v1")) {
               ^
    pass/pass_test.go:89:6: QF1001: could apply De Morgan's law (staticcheck)
            if !(username == "foo" || username == "bar") {
               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-01 15:55:19 +02:00
Sebastiaan van Stijn a14669f4ff pass: Get: remove redundant stat
listPassdir already handles "not found" errors, in which case it returns
an [empty result][1]. Previously this would return a custom error, but
since 1bb9aa3210, an empty result produces
a `errCredentialsNotFound`, making this check redundant.

This patch removes the redundant check.

[1]: https://github.com/docker/docker-credential-helpers/blob/f64d6b131b3da07a6337dc63a882e08ce541d1c1/pass/pass.go#L118-L125

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-10 10:28:57 +02:00
Sebastiaan van Stijn d3ef442f59 pass: add utilities for encoding/decoding serverURL
While the implementation of these is fairly trivial, we want them
to remain the same. This patch adds utilities to handle the encoding
and decoding of the server-URLs.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-09 16:58:34 +02:00
Sebastiaan van Stijn 1bb9aa3210 pass: return correct error, and ignore empty stores on list
commit 2fc2313bb1 changed the errors returned
by the pass credentials-helper to use a errCredentialsNotFound. This error
string is used in the client to distinguish a "not found" error from other
errors. (see [client.Get][1]).

However, there were additional second code-paths that returned a custom error,
which would not be detected as a "not found" error, resulting in an error when
logging out;

    Removing login credentials for https://index.docker.io/v1/
    WARNING: could not erase credentials:
    https://index.docker.io/v1/: error erasing credentials - err: exit status 1, out: `error getting credentials - err: exit status 1, out: `no usernames for https://index.docker.io/v1/``

This patch:

- updates Pass.Get() to return a errCredentialsNotFound if no credentials
  were found
- updates Pass.List() to not return an error if any of the domains had no
  credentials stored.

[1]: https://github.com/docker/docker-credential-helpers/blob/73b9e5d51f8dc9f598e08a0f2171c5d5a828e76b/client/client.go#L51-L55

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-09 12:19:23 +02:00
Sebastiaan van Stijn ffb3232f6c pass: use designated domains in tests (RFC2606)
Update domains used in tests to used domains that are designated for this
purpose as described in [RFC2606, section 3][1]

[1]: https://www.rfc-editor.org/rfc/rfc2606.html#section-3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-26 13:59:01 +02:00
CrazyMax 72391b37df pass: properly handle errors in tests
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-05-29 12:02:49 +02:00
CrazyMax d0668939bb pass: exclude tests on windows
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-05-29 12:02:49 +02:00
Sebastiaan van Stijn 372315b138 pass: make home-dir resolution platform agnostic
Use stdlib's os.UserHomeDir() instead of depending only on $HOME. Note that
this does not yet does nss lookups for situations where $HOME / $USERPROFILE
is not set.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-29 08:54:49 +02:00
Sebastiaan van Stijn c8c415f9f7 pass: fix interpolation of $PASSWORD_STORE_DIR
commit a13ff50017 simplified the handling of
env-vars in getPassDir(), but moved interpolation of env-vars to the end
of the function.

As a result, a custom path passed through `$PASSWORD_STORE_DIR` would now
be interpolated, instead of taken as-is. For example;

    PASSWORD_STORE_DIR=$PWD/world

Would now interpolate `$PWD`, instead of using a literal `$PWD`.

This patch changes the logic to only expand env-vars for the default location.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-28 18:42:06 +02:00
Sebastiaan van Stijn 9817a23b17 format code with gofumpt
Doing a one-pass of formatting the code with gofumpt, which provides a
superset of gofmt.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-27 13:01:49 +02:00
CrazyMax 29c449aea8 Dockerfile: debian based build
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-08-30 13:09:08 +02:00
Sebastiaan van Stijn 2f246b8570 Merge pull request #221 from nicks/nicks/pass
pass: return an error when a cred doesn't exist
2022-08-28 21:33:45 +02:00
Ellis Clayton dd465ef1f3 Allow pass helper to be built for macOS
Pass is described as "The Standard Unix Password Manager", and so it can
easily run on more than just Linux. Namely, it's supported on macOS. The
CLI is identical to the Linux build, which means the Linux helper code
for Pass is fully applicable toward the macOS build - a couple of
renames being the only needed thing, purely for semantic correctness.

Signed-off-by: Ellis Clayton <ellis@ellis.codes>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-21 16:18:19 +02:00
CrazyMax 9582eb6661 lint gha job
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-08-21 15:33:56 +02:00
Nick Santos 2fc2313bb1 pass: return an error when a cred doesn't exist
fixes https://github.com/docker/docker-credential-helpers/issues/174

Signed-off-by: Nick Santos <nick.santos@docker.com>
2022-07-27 09:28:13 -04:00
Sebastiaan van Stijn 7a2694fc98 fix some linting issues
/go/src/github.com/docker/docker-credential-helper/pass/pass.go:1:1: package comment should be of the form "Package pass ..."
    /go/src/github.com/docker/docker-credential-helper/pass/pass.go:22:7: don't use ALL_CAPS in Go names; use CamelCase
    /go/src/github.com/docker/docker-credential-helper/pass/pass.go:22:7: exported const PASS_FOLDER should have comment or be unexported
    /go/src/github.com/docker/docker-credential-helper/pass/pass.go:82:1: receiver name h should be consistent with previous receiver name p for Pass
    /go/src/github.com/docker/docker-credential-helper/pass/pass.go:94:1: receiver name h should be consistent with previous receiver name p for Pass
    /go/src/github.com/docker/docker-credential-helper/pass/pass.go:131:1: receiver name h should be consistent with previous receiver name p for Pass
    /go/src/github.com/docker/docker-credential-helper/pass/pass.go:161:1: receiver name h should be consistent with previous receiver name p for Pass
    /go/src/github.com/docker/docker-credential-helper/registryurl/url_go18.go:9:1: exported function GetHostname should have comment or be unexported
    /go/src/github.com/docker/docker-credential-helper/registryurl/url_go18.go:13:1: exported function GetPort should have comment or be unexported
    /go/src/github.com/docker/docker-credential-helper/secretservice/secretservice_linux_test.go:22:2: don't use underscores in Go names; var old_auths should be oldAuths
    /go/src/github.com/docker/docker-credential-helper/secretservice/secretservice_linux_test.go:64:2: don't use underscores in Go names; var new_auths should be newAuths

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-01 10:22:11 +02:00
Rafael Ávila de Espíndola f76f0b3f33 Enable pass on non-linux systems
There is nothing linux specific about pass. In particular, I use it in
openbsd.

Signed-off-by: Rafael Ávila de Espíndola <rafael@espindo.la>
2020-09-14 20:54:21 -07:00
eyjhbb@gmail.com 9c18f033f7 pass: changed error message returned, if password-store is not initialized
Signed-off-by: eyjhbb@gmail.com <eyjhbb@gmail.com>
2018-09-24 15:15:24 +02:00
eyjhbb@gmail.com d6c1f136e4 pass: changed the way for checking if password-store is initalized
Signed-off-by: eyjhbb@gmail.com <eyjhbb@gmail.com>
2018-09-22 12:53:56 +02:00
Nassim Eddequiouaq 5241b46610 Merge pull request #110 from euank/lazy-init
pass: only init on run, and do so lazily
2018-06-27 14:33:29 +02:00
Vincent Demeester 3cba3913ea pass: add IsInitialized helper
This will be useful for the cli where they check initialization:
https://github.com/docker/cli/blob/be8dab26a3ab589b96788fdb95f3d07378e57b9b/cli/config/credentials/default_store_linux.go#L8-L10

Signed-off-by: Euan Kemp <euank@euank.com>
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-27 14:28:47 +02:00
Euan Kemp 5da09fd251 pass: only init on run, and do so lazily
This also fixes the following issues:

1. Safe for concurrent initialization still (it was before in 'init',
   but the alternative to this PR is not)
2. Uses the same password directory during init as it does during
   runtime (the change to getPassDir in initialization logic.
3. Prints significantly better errors if initialization fails
4. Has slightly cleaner abstractions by hiding the initialization check
   in 'runPass'

The 4th item there does mean there are a few cases where more work is
done before erroring, but that amount of work is trivial and my manual
audit didn't reveal anything that seemed worrying.

Fixes #96, alternative to #106

Signed-off-by: Euan Kemp <euank@euank.com>
2018-06-27 14:23:22 +02:00
Euan Kemp dd27c246bd pass: trim pass show output
As of 8446a40, pass show will include a newline when showing a password.
This causes the pass helper here to reliably fail to initialize since a
password doesn't round-trip.

Before making this change, the pass test would fail if the installed
password-store version was v1.7.1+, and after this change it passes
again.

Fixes #107

Signed-off-by: Euan Kemp <euank@euank.com>
2018-06-27 14:21:52 +02:00
Euan Kemp a13ff50017 pass: simplify some code
The exec.Command code and os.Getenv implementation were both needlessly
verbose. This replaces them with simpler variations.

Signed-off-by: Euan Kemp <euank@euank.com>
2018-06-27 14:15:36 +02:00
Tycho Andersen c2eec534ee pass: better initialization check
See comment for details, but basically, let's actually use pass to check
that it works.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-29 08:25:08 -07:00
Tycho Andersen f212ea17df fix test
Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-17 10:36:48 -06:00
Tycho Andersen 09e536a128 return "" instead of an error when pass isn't present
It turns out the cred helpers protocol is to return "" and not an error
when a credential isn't present, so let's do that.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-17 09:19:19 -06:00
Tycho Andersen b8fb9690c8 pass backend: expose pass initialized flag
This way clients don't have to run their own checks, they can just use the
library's detection.

Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-14 08:56:59 -06:00
Tycho Andersen 1ab1037707 add a pass credential helper backend
Signed-off-by: Tycho Andersen <tycho@docker.com>
2017-08-11 08:15:29 -06:00