Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract the username and password from the mirror url #7651

Merged
merged 15 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Just roundtrip the password
  • Loading branch information
zeripath committed Jul 29, 2019
commit 216d58de41179c5eb7c47e7df9fee328abf3b0ae
12 changes: 12 additions & 0 deletions models/repo_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ func (m *Mirror) Username() string {
return u.User.Username()
}

// Password returns the mirror address password
func (m *Mirror) Password() string {
m.readAddress()
u, err := url.Parse(m.address)
if err != nil {
// this shouldn't happen but if it does return ""
return ""
}
password, _ := u.User.Password()
return password
}

// SaveAddress writes new address to Git repository config.
func (m *Mirror) SaveAddress(addr string) error {
repoPath := m.Repo.RepoPath()
Expand Down
8 changes: 2 additions & 6 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,8 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
return
}

if form.MirrorUsername != "" {
password := form.MirrorPassword
if password == "" && oldURL != nil && u.Hostname() == oldURL.Hostname() {
password, _ = oldURL.User.Password()
}
u.User = url.UserPassword(form.MirrorUsername, password)
if form.MirrorUsername != "" || form.MirrorPassword != "" {
u.User = url.UserPassword(form.MirrorUsername, form.MirrorPassword)
}

// Now use xurls
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<input class="fake" type="password">
<div class="inline field {{if .Err_Auth}}error{{end}}">
<label for="mirror_password">{{.i18n.Tr "password"}}</label>
<input id="mirror_password" name="mirror_password" type="password" value="">
<input id="mirror_password" name="mirror_password" type="password" value="{{.Mirror.Password}}" {{if not .mirror_password}}data-need-clear="true"{{end}}>
</div>
</div>
</div>
Expand Down