mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-23 12:59:30 +00:00
Get Netrc machine from clone url (#800)
We previously got the machine hostname for Netrc from the url of the remote, but in cases where the clone-url does not match the api url this can lead to errors.
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||
"github.com/woodpecker-ci/woodpecker/server/remote"
|
||||
"github.com/woodpecker-ci/woodpecker/server/remote/common"
|
||||
)
|
||||
|
||||
// Opts defines configuration options.
|
||||
@@ -40,7 +41,6 @@ type Opts struct {
|
||||
|
||||
type client struct {
|
||||
URL string
|
||||
Machine string
|
||||
Username string
|
||||
Password string
|
||||
PrivateMode bool
|
||||
@@ -60,7 +60,6 @@ func New(opts Opts) (remote.Remote, error) {
|
||||
}
|
||||
return &client{
|
||||
URL: opts.URL,
|
||||
Machine: u.Host,
|
||||
Username: opts.Username,
|
||||
Password: opts.Password,
|
||||
PrivateMode: opts.PrivateMode,
|
||||
@@ -217,17 +216,22 @@ func (c *client) Status(ctx context.Context, u *model.User, r *model.Repo, b *mo
|
||||
// cloning Gogs repositories. The netrc will use the global machine account
|
||||
// when configured.
|
||||
func (c *client) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
|
||||
host, err := common.ExtractHostFromCloneURL(r.Clone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.Password != "" {
|
||||
return &model.Netrc{
|
||||
Login: c.Username,
|
||||
Password: c.Password,
|
||||
Machine: c.Machine,
|
||||
Machine: host,
|
||||
}, nil
|
||||
}
|
||||
return &model.Netrc{
|
||||
Login: u.Token,
|
||||
Password: "x-oauth-basic",
|
||||
Machine: c.Machine,
|
||||
Machine: host,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user