1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/cnbutils/auth.go
Pavel Busko 547ef5b55d
feat(cnbBuild): remove docker config after parsing (#3417)
Co-authored-by: Philipp Stehle <philipp.stehle@sap.com>
2022-01-11 10:01:15 +01:00

38 lines
707 B
Go

package cnbutils
import (
"encoding/json"
"fmt"
"github.com/docker/cli/cli/config/configfile"
)
func GenerateCnbAuth(config string, utils BuildUtils) (string, error) {
var err error
dockerConfig := &configfile.ConfigFile{}
if config != "" {
dockerConfigJSON, err := utils.FileRead(config)
if err != nil {
return "", err
}
err = json.Unmarshal(dockerConfigJSON, dockerConfig)
if err != nil {
return "", err
}
}
auth := map[string]string{}
for registry, value := range dockerConfig.AuthConfigs {
auth[registry] = fmt.Sprintf("Basic %s", value.Auth)
}
cnbRegistryAuth, err := json.Marshal(auth)
if err != nil {
return "", err
}
return string(cnbRegistryAuth), nil
}