You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/api/internal/registryutils/auth_header.go

37 lines
761 B

package registryutils
import (
"encoding/base64"
"encoding/json"
portainer "github.com/portainer/portainer/api"
)
type (
authHeader struct {
Username string `json:"username"`
Password string `json:"password"`
ServerAddress string `json:"serveraddress"`
}
)
// GetRegistryAuthHeader generate the X-Registry-Auth header from registry
func GetRegistryAuthHeader(registry *portainer.Registry) (header string, err error) {
authHeader := authHeader{
ServerAddress: registry.URL,
}
authHeader.Username, authHeader.Password, err = GetRegEffectiveCredential(registry)
if err != nil {
return
}
headerData, err := json.Marshal(authHeader)
if err != nil {
return
}
header = base64.StdEncoding.EncodeToString(headerData)
return
}