Skip to content

Commit

Permalink
added url support for json auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeanHnter committed Feb 8, 2024
1 parent 86cd33f commit 895e345
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Client/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type DockerAuth struct {
Username string
Password string
URL string
}

type DockerAuthConfig struct {
Expand All @@ -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,
Expand All @@ -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,
},
},
Expand Down
26 changes: 17 additions & 9 deletions Client/cmd/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
username string
password string
labels []string

url string

RootCmd = &cobra.Command {
Use: "docker",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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.`,
Expand All @@ -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)
Expand All @@ -192,6 +198,8 @@ var (
return nil
},
}


)

func init() {
Expand All @@ -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")
}
6 changes: 3 additions & 3 deletions Client/kaniko/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
}

2 changes: 1 addition & 1 deletion Client/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 895e345

Please sign in to comment.