From 895e34546fcf44ff6c35c46df2b7b6c19923ff3b Mon Sep 17 00:00:00 2001 From: Dean Hunter Date: Thu, 8 Feb 2024 14:21:29 +0100 Subject: [PATCH] added url support for json auth. --- Client/auth/auth.go | 6 ++++-- Client/cmd/docker.go | 26 +++++++++++++++++--------- Client/kaniko/cmd.go | 6 +++--- Client/shared/shared.go | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Client/auth/auth.go b/Client/auth/auth.go index b3cb9f6..043bee6 100644 --- a/Client/auth/auth.go +++ b/Client/auth/auth.go @@ -11,6 +11,7 @@ import ( type DockerAuth struct { Username string Password string + URL string } type DockerAuthConfig struct { @@ -26,7 +27,7 @@ func NewEnvAuth(envProvider *environment.EnvProvider) *DockerAuth { } } -func NewUserPassAuth(username, password string) *DockerAuth { +func NewUserPassAuth(username, password,url string) *DockerAuth { return &DockerAuth{ Username: username, Password: password, @@ -47,7 +48,8 @@ func (da *DockerAuth) CreateDockerConfigJSON() error { dockerConfig := DockerAuthConfig{ Auths: map[string]map[string]string{ - "https://index.docker.io/v1/": { + da.URL:{ + //"https://index.docker.io/v1/": { "auth": encodedCredentials, }, }, diff --git a/Client/cmd/docker.go b/Client/cmd/docker.go index 8c340af..faa8c28 100644 --- a/Client/cmd/docker.go +++ b/Client/cmd/docker.go @@ -24,7 +24,7 @@ var ( username string password string labels []string - + url string RootCmd = &cobra.Command { Use: "docker", @@ -64,7 +64,7 @@ var ( Use: "login [OPTIONS] [SERVER]", Short: "Log in to a Docker registry", Long: `This command is used to log in to a Docker registry. If no server is specified, the default is to log in to the registry at Docker Hub.`, - Run: func(cmd *cobra.Command, args []string) { DockerCLI.Service.Login(args, username, password) }, + Run: func(cmd *cobra.Command, args []string) { DockerCLI.Service.Login(args, username, password,url) }, } pullCmd = &cobra.Command{ @@ -161,7 +161,7 @@ var ( }, } - historyCmd = &cobra.Command{ + historyCmd = &cobra.Command{ Use: "history [OPTIONS] IMAGE", Short: "Show the history of an image", Long: `This command shows the history of an image, including the layers and size information.`, @@ -171,16 +171,22 @@ var ( format, _ := cmd.Flags().GetString("format") noTrunc, _ := cmd.Flags().GetBool("no-trunc") - historyArgs := []string{} + // Initializing the slice of arguments with the static part + historyArgs := []string{"history"} + + // Handling the format flag if provided if format != "" { - historyArgs = append(historyArgs, "--format="+format) + historyArgs = append(historyArgs, "--format") + historyArgs = append(historyArgs, format) } + + // Handling the no-trunc flag if provided if noTrunc { historyArgs = append(historyArgs, "--no-trunc") } - imageName := args[0] - historyArgs = append(historyArgs, imageName) + // Appending the image name to the list of arguments + historyArgs = append(historyArgs, args[0]) // Executing the history command with the collected arguments result, err := DockerCLI.Service.ImageHistory(historyArgs) @@ -192,6 +198,8 @@ var ( return nil }, } + + ) func init() { @@ -214,6 +222,6 @@ func init() { imagesCmd.Flags().BoolP("all", "a", false, "Show all images (default hides intermediate images)") imagesCmd.Flags().StringArrayP("filter", "f", []string{}, "Filter output based on conditions provided") imagesCmd.Flags().StringP("format", "", "", "Pretty-print images using a Go template") - historyCmd.Flags().StringP("format", "", "", "Pretty-print the image history using a Go template") - historyCmd.Flags().BoolP("no-trunc", "", false, "Don't truncate output") + historyCmd.Flags().StringP("format", "f", "", "Pretty-print the image history using a Go template") + historyCmd.Flags().BoolP("no-trunc", "", false, "Don't truncate output") } \ No newline at end of file diff --git a/Client/kaniko/cmd.go b/Client/kaniko/cmd.go index 49cf757..9159bc0 100644 --- a/Client/kaniko/cmd.go +++ b/Client/kaniko/cmd.go @@ -102,10 +102,10 @@ func (kd *KanikoDocker) PushImage(args []string) { fmt.Println("Placeholder - push") } -func (kd *KanikoDocker) Login(args []string,username string,password string) { +func (kd *KanikoDocker) Login(args []string,username string,password,url string) { dockerauth := auth.New() if len(username)>0 && len(password)>0{ - dockerauth = auth.NewUserPassAuth(username, password) + dockerauth = auth.NewUserPassAuth(username, password,url) } dockerauth.CreateDockerConfigJSON() } @@ -124,6 +124,6 @@ func (kd *KanikoDocker) ListImages(args []string) (string, error) { } func (kd *KanikoDocker) ImageHistory(args []string) (string, error) { - return "",nil + return "placeholder",nil //temporary to provide a debuggable value } diff --git a/Client/shared/shared.go b/Client/shared/shared.go index a4798be..be8742d 100644 --- a/Client/shared/shared.go +++ b/Client/shared/shared.go @@ -5,7 +5,7 @@ type DockerBuilder interface { BuildImage(options BuildOptions, contextPath string, dockerfilePath string) TagImage(args []string) PushImage(args []string) - Login(args []string, username string, password string) + Login(args []string, username string, password string,url string) PullImage(imageName string) error InspectImage(args []string) (string, error) ListImages(args []string) (string, error) // New method for listing images