|
|
|
@ -24,6 +24,7 @@ import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"log/slog"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
@ -224,12 +225,25 @@ type (
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// warnIfHostHasPath checks if the host contains a repository path and logs a warning if it does.
|
|
|
|
|
|
|
|
// Returns true if the host contains a path component (i.e., contains a '/').
|
|
|
|
|
|
|
|
func warnIfHostHasPath(host string) bool {
|
|
|
|
|
|
|
|
if strings.Contains(host, "/") {
|
|
|
|
|
|
|
|
registryHost := strings.Split(host, "/")[0]
|
|
|
|
|
|
|
|
slog.Warn("registry login currently only supports registry hostname, not a repository path", "host", host, "suggested", registryHost)
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Login logs into a registry
|
|
|
|
// Login logs into a registry
|
|
|
|
func (c *Client) Login(host string, options ...LoginOption) error {
|
|
|
|
func (c *Client) Login(host string, options ...LoginOption) error {
|
|
|
|
for _, option := range options {
|
|
|
|
for _, option := range options {
|
|
|
|
option(&loginOperation{host, c})
|
|
|
|
option(&loginOperation{host, c})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
warnIfHostHasPath(host)
|
|
|
|
|
|
|
|
|
|
|
|
reg, err := remote.NewRegistry(host)
|
|
|
|
reg, err := remote.NewRegistry(host)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
|