registryToString converts the Registry struct to a base64 encoding for json strings.
(reg typeReg.AuthConfig)
| 430 | |
| 431 | // registryToString converts the Registry struct to a base64 encoding for json strings. |
| 432 | func registryToString(reg typeReg.AuthConfig) (string, error) { |
| 433 | // Docker stores the username and password in an auth section typeReg.AuthConfig |
| 434 | // formatted as user:pass then base64ed. This is not documented clearly. |
| 435 | // https://github.com/docker/cli/blob/master/cli/config/configfile/file.go#L76 |
| 436 | if reg.Auth != "" { |
| 437 | bytes, err := base64.StdEncoding.DecodeString(reg.Auth) |
| 438 | if err != nil { |
| 439 | return "", err |
| 440 | } |
| 441 | userAndPass := strings.SplitN(string(bytes), ":", 2) |
| 442 | if len(userAndPass) != 2 { |
| 443 | return "", errors.Errorf("auth field of docker authConfig must be base64ed user:pass") |
| 444 | } |
| 445 | reg.Username, reg.Password = userAndPass[0], userAndPass[1] |
| 446 | reg.Auth = "" |
| 447 | } |
| 448 | bs, err := json.Marshal(reg) |
| 449 | if err != nil { |
| 450 | return "", err |
| 451 | } |
| 452 | |
| 453 | return base64.URLEncoding.EncodeToString(bs), nil |
| 454 | } |
| 455 | |
| 456 | func (d *Client) sendPullLogs(ctx context.Context, r io.Reader, p events.Publisher[Event]) error { |
| 457 | plf := pullLogFormatter{Known: map[string]*pullInfo{}} |