Skip to content

Commit e310510

Browse files
Bao0nelei wang
and
lei wang
authored
Allow repo add to set authentication for private repository (#370)
Co-authored-by: lei wang <[email protected]>
1 parent 550642b commit e310510

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Diff for: cmd/repo/add.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
4545
4646
luet repo add ... --name "foo"
4747
48-
# Inline:
48+
# Inline (provided you have $PASSWORD environent variable set):
4949
50-
luet repo add testfo --description "Bar" --url "FOZZ" --type "ff"
50+
luet repo add testfo --description "Bar" --url "FOZZ" --type "ff" --username "user" --passwd $(echo "$PASSWORD")
5151
5252
`,
5353
Run: func(cmd *cobra.Command, args []string) {
@@ -61,6 +61,8 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
6161
url, _ := cmd.Flags().GetString("url")
6262
ref, _ := cmd.Flags().GetString("reference")
6363
prio, _ := cmd.Flags().GetInt("priority")
64+
username, _ := cmd.Flags().GetString("username")
65+
passwd, _ := cmd.Flags().GetString("passwd")
6466

6567
if len(util.DefaultContext.Config.RepositoriesConfDir) == 0 && d == "" {
6668
util.DefaultContext.Fatal("No repository dirs defined")
@@ -82,6 +84,10 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
8284
Type: t,
8385
Urls: []string{url},
8486
Priority: prio,
87+
Authentication: map[string]string{
88+
"username": username,
89+
"password": passwd,
90+
},
8591
}
8692
} else {
8793
r, err = types.LoadRepository([]byte(str))
@@ -103,6 +109,12 @@ Adds a repository to the system. URLs, local files or inline repo can be specifi
103109
if prio != 0 {
104110
r.Priority = prio
105111
}
112+
if username != "" && passwd != "" {
113+
r.Authentication = map[string]string{
114+
"username": username,
115+
"password": passwd,
116+
}
117+
}
106118
}
107119

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

0 commit comments

Comments
 (0)