@@ -87,8 +87,7 @@ func (p Pass) Add(creds *credentials.Credentials) error {
87
87
return errors .New ("missing credentials" )
88
88
}
89
89
90
- encoded := base64 .URLEncoding .EncodeToString ([]byte (creds .ServerURL ))
91
-
90
+ encoded := encodeServerURL (creds .ServerURL )
92
91
_ , err := p .runPass (creds .Secret , "insert" , "-f" , "-m" , path .Join (PASS_FOLDER , encoded , creds .Username ))
93
92
return err
94
93
}
@@ -99,7 +98,7 @@ func (p Pass) Delete(serverURL string) error {
99
98
return errors .New ("missing server url" )
100
99
}
101
100
102
- encoded := base64 . URLEncoding . EncodeToString ([] byte ( serverURL ) )
101
+ encoded := encodeServerURL ( serverURL )
103
102
_ , err := p .runPass ("" , "rm" , "-rf" , path .Join (PASS_FOLDER , encoded ))
104
103
return err
105
104
}
@@ -142,23 +141,14 @@ func (p Pass) Get(serverURL string) (string, string, error) {
142
141
return "" , "" , errors .New ("missing server url" )
143
142
}
144
143
145
- encoded := base64 .URLEncoding .EncodeToString ([]byte (serverURL ))
146
-
147
- if _ , err := os .Stat (path .Join (getPassDir (), PASS_FOLDER , encoded )); err != nil {
148
- if os .IsNotExist (err ) {
149
- return "" , "" , credentials .NewErrCredentialsNotFound ()
150
- }
151
-
152
- return "" , "" , err
153
- }
154
-
144
+ encoded := encodeServerURL (serverURL )
155
145
usernames , err := listPassDir (encoded )
156
146
if err != nil {
157
147
return "" , "" , err
158
148
}
159
149
160
150
if len (usernames ) < 1 {
161
- return "" , "" , fmt . Errorf ( "no usernames for %s" , serverURL )
151
+ return "" , "" , credentials . NewErrCredentialsNotFound ( )
162
152
}
163
153
164
154
actual := strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
@@ -180,7 +170,7 @@ func (p Pass) List() (map[string]string, error) {
180
170
continue
181
171
}
182
172
183
- serverURL , err := base64 . URLEncoding . DecodeString (server .Name ())
173
+ serverURL , err := decodeServerURL (server .Name ())
184
174
if err != nil {
185
175
return nil , err
186
176
}
@@ -191,11 +181,27 @@ func (p Pass) List() (map[string]string, error) {
191
181
}
192
182
193
183
if len (usernames ) < 1 {
194
- return nil , fmt . Errorf ( "no usernames for %s" , serverURL )
184
+ continue
195
185
}
196
186
197
- resp [string ( serverURL ) ] = strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
187
+ resp [serverURL ] = strings .TrimSuffix (usernames [0 ].Name (), ".gpg" )
198
188
}
199
189
200
190
return resp , nil
201
191
}
192
+
193
+ // encodeServerURL returns the serverURL in base64-URL encoding to use
194
+ // as directory-name in pass storage.
195
+ func encodeServerURL (serverURL string ) string {
196
+ return base64 .URLEncoding .EncodeToString ([]byte (serverURL ))
197
+ }
198
+
199
+ // decodeServerURL decodes base64-URL encoded serverURL. ServerURLs are
200
+ // used in encoded format for directory-names in pass storage.
201
+ func decodeServerURL (encodedServerURL string ) (string , error ) {
202
+ serverURL , err := base64 .URLEncoding .DecodeString (encodedServerURL )
203
+ if err != nil {
204
+ return "" , err
205
+ }
206
+ return string (serverURL ), nil
207
+ }
0 commit comments