decodeAuth decodes a base64 encoded string and returns username and password
(authStr string)
| 295 | |
| 296 | // decodeAuth decodes a base64 encoded string and returns username and password |
| 297 | func decodeAuth(authStr string) (string, string, error) { |
| 298 | if authStr == "" { |
| 299 | return "", "", nil |
| 300 | } |
| 301 | |
| 302 | decLen := base64.StdEncoding.DecodedLen(len(authStr)) |
| 303 | decoded := make([]byte, decLen) |
| 304 | authByte := []byte(authStr) |
| 305 | n, err := base64.StdEncoding.Decode(decoded, authByte) |
| 306 | if err != nil { |
| 307 | return "", "", err |
| 308 | } |
| 309 | if n > decLen { |
| 310 | return "", "", errors.New("something went wrong decoding auth config") |
| 311 | } |
| 312 | userName, password, ok := strings.Cut(string(decoded), ":") |
| 313 | if !ok || userName == "" { |
| 314 | return "", "", errors.New("invalid auth configuration file") |
| 315 | } |
| 316 | return userName, strings.Trim(password, "\x00"), nil |
| 317 | } |
| 318 | |
| 319 | // GetCredentialsStore returns a new credentials store from the settings in the |
| 320 | // configuration file |
no outgoing calls
searching dependent graphs…