in pkg/netrc/netrc.go [110:138]
func AddConfigs(locations []string, netrc, hostPattern, jsonKeyPath string) (string, error) {
for _, l := range locations {
h := fmt.Sprintf(hostPattern, l)
match, err := regexp.MatchString("machine "+h+"\n", netrc)
if err != nil {
return "", fmt.Errorf("Internal: AddConfigs has error: %v", err)
}
if match {
log.Printf("Warning: machine %s is already in the .netrc file, skipping\n", h)
continue
}
var cfg string
if jsonKeyPath == "" {
cfg = arTokenConfigPlaceholder(h)
} else {
key, err := auth.EncodeJsonKey(jsonKeyPath)
if err != nil {
return "", fmt.Errorf("AddConfigs: %w", err)
}
cfg = arJsonKeyConfig(h, key)
}
if netrc != "" {
netrc = netrc + "\n"
}
netrc = netrc + cfg
}
return netrc, nil
}