Skip to content

Commit

Permalink
Allow repo add to set authentication for private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
lei wang authored and lei wang committed Dec 5, 2024
1 parent bcfd864 commit 42b215c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/repo/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
# Inline:
luet repo add testfo --description "Bar" --url "FOZZ" --type "ff"
luet repo add testfo --description "Bar" --url "FOZZ" --type "ff" --username "user" --passwd "password"
`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -61,6 +61,8 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
url, _ := cmd.Flags().GetString("url")
ref, _ := cmd.Flags().GetString("reference")
prio, _ := cmd.Flags().GetInt("priority")
username, _ := cmd.Flags().GetString("username")
passwd, _ := cmd.Flags().GetString("passwd")

if len(util.DefaultContext.Config.RepositoriesConfDir) == 0 && d == "" {
util.DefaultContext.Fatal("No repository dirs defined")
Expand All @@ -82,6 +84,10 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
Type: t,
Urls: []string{url},
Priority: prio,
Authentication: map[string]string{
"username": username,
"password": passwd,
},
}
} else {
r, err = types.LoadRepository([]byte(str))
Expand All @@ -103,6 +109,13 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
if prio != 0 {
r.Priority = prio
}
if username != "" && passwd != ""{
fmt.Println("111")
r.Authentication = map[string]string{
"username": username,
"password": passwd,
}
}
}

file := filepath.Join(util.DefaultContext.Config.System.Rootfs, d, fmt.Sprintf("%s.yaml", r.Name))
Expand Down Expand Up @@ -133,5 +146,7 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
cmd.Flags().String("url", "", "Repository URL")
cmd.Flags().String("reference", "", "Repository Reference ID")
cmd.Flags().IntP("priority", "p", 99, "repository prio")
cmd.Flags().String("username", "", "repository username")
cmd.Flags().String("passwd", "", "repository password")
return cmd
}

0 comments on commit 42b215c

Please sign in to comment.