MCPcopy
hub / github.com/determined-ai/determined / registryToString

Function registryToString

agent/pkg/docker/docker.go:432–454  ·  view source on GitHub ↗

registryToString converts the Registry struct to a base64 encoding for json strings.

(reg typeReg.AuthConfig)

Source from the content-addressed store, hash-verified

430
431// registryToString converts the Registry struct to a base64 encoding for json strings.
432func 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
456func (d *Client) sendPullLogs(ctx context.Context, r io.Reader, p events.Publisher[Event]) error {
457 plf := pullLogFormatter{Known: map[string]*pullInfo{}}

Callers 2

PullImageMethod · 0.85
TestRegistryToStringFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestRegistryToStringFunction · 0.68