1
- // A `pass` based credential helper. Passwords are stored as arguments to pass
2
- // of the form: "$PASS_FOLDER/base64-url(serverURL)/username". We base64-url
3
- // encode the serverURL, because under the hood pass uses files and folders, so
4
- // /s will get translated into additional folders.
1
+ // Package pass implements a `pass` based credential helper. Passwords are stored
2
+ // as arguments to pass of the form: "$PASS_FOLDER/base64-url(serverURL)/username".
3
+ // We base64-url encode the serverURL, because under the hood pass uses files and
4
+ // folders, so /s will get translated into additional folders.
5
5
package pass
6
6
7
7
import (
@@ -19,7 +19,8 @@ import (
19
19
"github.com/docker/docker-credential-helpers/credentials"
20
20
)
21
21
22
- const PASS_FOLDER = "docker-credential-helpers"
22
+ // PASS_FOLDER contains the directory where credentials are stored
23
+ const PASS_FOLDER = "docker-credential-helpers" //nolint: golint
23
24
24
25
// Pass handles secrets using Linux secret-service as a store.
25
26
type Pass struct {}
@@ -79,25 +80,25 @@ func (p Pass) runPassHelper(stdinContent string, args ...string) (string, error)
79
80
}
80
81
81
82
// Add adds new credentials to the keychain.
82
- func (h Pass ) Add (creds * credentials.Credentials ) error {
83
+ func (p Pass ) Add (creds * credentials.Credentials ) error {
83
84
if creds == nil {
84
85
return errors .New ("missing credentials" )
85
86
}
86
87
87
88
encoded := base64 .URLEncoding .EncodeToString ([]byte (creds .ServerURL ))
88
89
89
- _ , err := h .runPass (creds .Secret , "insert" , "-f" , "-m" , path .Join (PASS_FOLDER , encoded , creds .Username ))
90
+ _ , err := p .runPass (creds .Secret , "insert" , "-f" , "-m" , path .Join (PASS_FOLDER , encoded , creds .Username ))
90
91
return err
91
92
}
92
93
93
94
// Delete removes credentials from the store.
94
- func (h Pass ) Delete (serverURL string ) error {
95
+ func (p Pass ) Delete (serverURL string ) error {
95
96
if serverURL == "" {
96
97
return errors .New ("missing server url" )
97
98
}
98
99
99
100
encoded := base64 .URLEncoding .EncodeToString ([]byte (serverURL ))
100
- _ , err := h .runPass ("" , "rm" , "-rf" , path .Join (PASS_FOLDER , encoded ))
101
+ _ , err := p .runPass ("" , "rm" , "-rf" , path .Join (PASS_FOLDER , encoded ))
101
102
return err
102
103
}
103
104
@@ -128,7 +129,7 @@ func listPassDir(args ...string) ([]os.FileInfo, error) {
128
129
}
129
130
130
131
// Get returns the username and secret to use for a given registry server URL.
131
- func (h Pass ) Get (serverURL string ) (string , string , error ) {
132
+ func (p Pass ) Get (serverURL string ) (string , string , error ) {
132
133
if serverURL == "" {
133
134
return "" , "" , errors .New ("missing server url" )
134
135
}
@@ -153,12 +154,12 @@ func (h Pass) Get(serverURL string) (string, string, error) {
153
154
}
154
155
155
156
actual := strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
156
- secret , err := h .runPass ("" , "show" , path .Join (PASS_FOLDER , encoded , actual ))
157
+ secret , err := p .runPass ("" , "show" , path .Join (PASS_FOLDER , encoded , actual ))
157
158
return actual , secret , err
158
159
}
159
160
160
161
// List returns the stored URLs and corresponding usernames for a given credentials label
161
- func (h Pass ) List () (map [string ]string , error ) {
162
+ func (p Pass ) List () (map [string ]string , error ) {
162
163
servers , err := listPassDir ()
163
164
if err != nil {
164
165
return nil , err
0 commit comments