mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-08-25 09:50:47 +00:00
Rename oauth variables (#5435)
Co-authored-by: Anton Bracke <anton.bracke@fastleansmart.com>
This commit is contained in:
parent
88b926c9dd
commit
24ebcb8cf8
@ -125,12 +125,12 @@ func PatchForge(c *gin.Context) {
|
||||
}
|
||||
forge.URL = in.URL
|
||||
forge.Type = in.Type
|
||||
forge.Client = in.Client
|
||||
forge.OAuthClientID = in.OAuthClientID
|
||||
forge.OAuthHost = in.OAuthHost
|
||||
forge.SkipVerify = in.SkipVerify
|
||||
forge.AdditionalOptions = in.AdditionalOptions
|
||||
if in.ClientSecret != "" {
|
||||
forge.ClientSecret = in.ClientSecret
|
||||
forge.OAuthClientSecret = in.ClientSecret
|
||||
}
|
||||
|
||||
err = _store.ForgeUpdate(forge)
|
||||
@ -163,8 +163,8 @@ func PostForge(c *gin.Context) {
|
||||
forge := &model.Forge{
|
||||
URL: in.URL,
|
||||
Type: in.Type,
|
||||
Client: in.Client,
|
||||
ClientSecret: in.ClientSecret,
|
||||
OAuthClientID: in.OAuthClientID,
|
||||
OAuthClientSecret: in.OAuthClientSecret,
|
||||
OAuthHost: in.OAuthHost,
|
||||
SkipVerify: in.SkipVerify,
|
||||
AdditionalOptions: in.AdditionalOptions,
|
||||
|
@ -44,25 +44,25 @@ const (
|
||||
|
||||
// Opts are forge options for bitbucket.
|
||||
type Opts struct {
|
||||
Client string
|
||||
Secret string
|
||||
OAuthClientID string
|
||||
OAuthClientSecret string
|
||||
}
|
||||
|
||||
type config struct {
|
||||
API string
|
||||
url string
|
||||
Client string
|
||||
Secret string
|
||||
api string
|
||||
url string
|
||||
oAuthClientID string
|
||||
oAuthSecret string
|
||||
}
|
||||
|
||||
// New returns a new forge Configuration for integrating with the Bitbucket
|
||||
// repository hosting service at https://bitbucket.org
|
||||
func New(opts *Opts) (forge.Forge, error) {
|
||||
return &config{
|
||||
API: DefaultAPI,
|
||||
url: DefaultURL,
|
||||
Client: opts.Client,
|
||||
Secret: opts.Secret,
|
||||
api: DefaultAPI,
|
||||
url: DefaultURL,
|
||||
oAuthClientID: opts.OAuthClientID,
|
||||
oAuthSecret: opts.OAuthClientSecret,
|
||||
}, nil
|
||||
// TODO: add checks
|
||||
}
|
||||
@ -93,7 +93,7 @@ func (c *config) Login(ctx context.Context, req *forge_types.OAuthRequest) (*mod
|
||||
return nil, redirectURL, err
|
||||
}
|
||||
|
||||
client := internal.NewClient(ctx, c.API, config.Client(ctx, token))
|
||||
client := internal.NewClient(ctx, c.api, config.Client(ctx, token))
|
||||
curr, err := client.FindCurrent()
|
||||
if err != nil {
|
||||
return nil, redirectURL, err
|
||||
@ -448,15 +448,15 @@ func (c *config) newClient(ctx context.Context, u *model.User) *internal.Client
|
||||
}
|
||||
|
||||
// helper function to return the bitbucket oauth2 client.
|
||||
func (c *config) newClientToken(ctx context.Context, token, secret string) *internal.Client {
|
||||
func (c *config) newClientToken(ctx context.Context, accessToken, refreshToken string) *internal.Client {
|
||||
return internal.NewClientToken(
|
||||
ctx,
|
||||
c.API,
|
||||
c.Client,
|
||||
c.Secret,
|
||||
c.api,
|
||||
accessToken,
|
||||
refreshToken,
|
||||
&oauth2.Token{
|
||||
AccessToken: token,
|
||||
RefreshToken: secret,
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -464,8 +464,8 @@ func (c *config) newClientToken(ctx context.Context, token, secret string) *inte
|
||||
// helper function to return the bitbucket oauth2 config.
|
||||
func (c *config) newOAuth2Config() *oauth2.Config {
|
||||
return &oauth2.Config{
|
||||
ClientID: c.Client,
|
||||
ClientSecret: c.Secret,
|
||||
ClientID: c.oAuthClientID,
|
||||
ClientSecret: c.oAuthSecret,
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url),
|
||||
TokenURL: fmt.Sprintf("%s/site/oauth2/access_token", c.url),
|
||||
|
@ -34,13 +34,13 @@ import (
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
forge, _ := New(&Opts{Client: "4vyW6b49Z", Secret: "a5012f6c6"})
|
||||
forge, _ := New(&Opts{OAuthClientID: "4vyW6b49Z", OAuthClientSecret: "a5012f6c6"})
|
||||
|
||||
f, _ := forge.(*config)
|
||||
assert.Equal(t, DefaultURL, f.url)
|
||||
assert.Equal(t, DefaultAPI, f.API)
|
||||
assert.Equal(t, "4vyW6b49Z", f.Client)
|
||||
assert.Equal(t, "a5012f6c6", f.Secret)
|
||||
assert.Equal(t, DefaultAPI, f.api)
|
||||
assert.Equal(t, "4vyW6b49Z", f.oAuthClientID)
|
||||
assert.Equal(t, "a5012f6c6", f.oAuthSecret)
|
||||
}
|
||||
|
||||
func TestBitbucket(t *testing.T) {
|
||||
@ -48,7 +48,7 @@ func TestBitbucket(t *testing.T) {
|
||||
|
||||
s := httptest.NewServer(fixtures.Handler())
|
||||
defer s.Close()
|
||||
c := &config{url: s.URL, API: s.URL}
|
||||
c := &config{url: s.URL, api: s.URL}
|
||||
|
||||
ctx := t.Context()
|
||||
|
||||
|
@ -38,12 +38,12 @@ const listLimit = 250
|
||||
|
||||
// Opts defines configuration options.
|
||||
type Opts struct {
|
||||
URL string // Bitbucket server url for API access.
|
||||
Username string // Git machine account username.
|
||||
Password string // Git machine account password.
|
||||
ClientID string // OAuth 2.0 client id
|
||||
ClientSecret string // OAuth 2.0 client secret
|
||||
OAuthHost string // OAuth 2.0 host
|
||||
URL string // Bitbucket server url for API access.
|
||||
Username string // Git machine account username.
|
||||
Password string // Git machine account password.
|
||||
OAuthClientID string // OAuth 2.0 client id
|
||||
OAuthClientSecret string // OAuth 2.0 client secret
|
||||
OAuthHost string // OAuth 2.0 host
|
||||
}
|
||||
|
||||
type client struct {
|
||||
@ -62,8 +62,8 @@ func New(opts Opts) (forge.Forge, error) {
|
||||
config := &client{
|
||||
url: opts.URL,
|
||||
urlAPI: fmt.Sprintf("%s/rest", opts.URL),
|
||||
clientID: opts.ClientID,
|
||||
clientSecret: opts.ClientSecret,
|
||||
clientID: opts.OAuthClientID,
|
||||
clientSecret: opts.OAuthClientSecret,
|
||||
oauthHost: opts.OAuthHost,
|
||||
username: opts.Username,
|
||||
password: opts.Password,
|
||||
@ -74,9 +74,9 @@ func New(opts Opts) (forge.Forge, error) {
|
||||
return nil, fmt.Errorf("must have a git machine account username")
|
||||
case opts.Password == "":
|
||||
return nil, fmt.Errorf("must have a git machine account password")
|
||||
case opts.ClientID == "":
|
||||
case opts.OAuthClientID == "":
|
||||
return nil, fmt.Errorf("must have an oauth 2.0 client id")
|
||||
case opts.ClientSecret == "":
|
||||
case opts.OAuthClientSecret == "":
|
||||
return nil, fmt.Errorf("must have an oauth 2.0 client secret")
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,11 @@ import (
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
forge, err := New(Opts{
|
||||
URL: "http://localhost:8080",
|
||||
Username: "0ZXh0IjoiI",
|
||||
Password: "I1NiIsInR5",
|
||||
ClientID: "client-id",
|
||||
ClientSecret: "client-secret",
|
||||
URL: "http://localhost:8080",
|
||||
Username: "0ZXh0IjoiI",
|
||||
Password: "I1NiIsInR5",
|
||||
OAuthClientID: "client-id",
|
||||
OAuthClientSecret: "client-secret",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, forge)
|
||||
|
@ -45,21 +45,21 @@ const (
|
||||
)
|
||||
|
||||
type Forgejo struct {
|
||||
url string
|
||||
oauth2URL string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
SkipVerify bool
|
||||
pageSize int
|
||||
url string
|
||||
oauth2URL string
|
||||
oAuthClientID string
|
||||
oAuthClientSecret string
|
||||
skipVerify bool
|
||||
pageSize int
|
||||
}
|
||||
|
||||
// Opts defines configuration options.
|
||||
type Opts struct {
|
||||
URL string // Forgejo server url.
|
||||
OAuth2URL string // User-facing Forgejo server url for OAuth2.
|
||||
Client string // OAuth2 Client ID
|
||||
Secret string // OAuth2 Client Secret
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
URL string // Forgejo server url.
|
||||
OAuth2URL string // User-facing Forgejo server url for OAuth2.
|
||||
OAuthClientID string // OAuth2 Client ID
|
||||
OAuthClientSecret string // OAuth2 Client Secret
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
}
|
||||
|
||||
// New returns a Forge implementation that integrates with Forgejo,
|
||||
@ -70,11 +70,11 @@ func New(opts Opts) (forge.Forge, error) {
|
||||
}
|
||||
|
||||
return &Forgejo{
|
||||
url: opts.URL,
|
||||
oauth2URL: opts.OAuth2URL,
|
||||
ClientID: opts.Client,
|
||||
ClientSecret: opts.Secret,
|
||||
SkipVerify: opts.SkipVerify,
|
||||
url: opts.URL,
|
||||
oauth2URL: opts.OAuth2URL,
|
||||
oAuthClientID: opts.OAuthClientID,
|
||||
oAuthClientSecret: opts.OAuthClientSecret,
|
||||
skipVerify: opts.SkipVerify,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -90,8 +90,8 @@ func (c *Forgejo) URL() string {
|
||||
|
||||
func (c *Forgejo) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
|
||||
return &oauth2.Config{
|
||||
ClientID: c.ClientID,
|
||||
ClientSecret: c.ClientSecret,
|
||||
ClientID: c.oAuthClientID,
|
||||
ClientSecret: c.oAuthClientSecret,
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: fmt.Sprintf(authorizeTokenURL, c.oauth2URL),
|
||||
TokenURL: fmt.Sprintf(accessTokenURL, c.oauth2URL),
|
||||
@ -100,7 +100,7 @@ func (c *Forgejo) oauth2Config(ctx context.Context) (*oauth2.Config, context.Con
|
||||
},
|
||||
|
||||
context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SkipVerify},
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.skipVerify},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
}})
|
||||
}
|
||||
@ -568,7 +568,7 @@ func (c *Forgejo) Org(ctx context.Context, u *model.User, owner string) (*model.
|
||||
// newClientToken returns a Forgejo client with token.
|
||||
func (c *Forgejo) newClientToken(ctx context.Context, token string) (*forgejo.Client, error) {
|
||||
httpClient := &http.Client{}
|
||||
if c.SkipVerify {
|
||||
if c.skipVerify {
|
||||
httpClient.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func TestNew(t *testing.T) {
|
||||
|
||||
f, _ := forge.(*Forgejo)
|
||||
assert.Equal(t, "http://localhost:8080", f.url)
|
||||
assert.True(t, f.SkipVerify)
|
||||
assert.True(t, f.skipVerify)
|
||||
}
|
||||
|
||||
func Test_forgejo(t *testing.T) {
|
||||
|
@ -47,32 +47,32 @@ const (
|
||||
)
|
||||
|
||||
type Gitea struct {
|
||||
url string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
OAuthHost string
|
||||
SkipVerify bool
|
||||
pageSize int
|
||||
url string
|
||||
oAuthClientID string
|
||||
oAuthClientSecret string
|
||||
oAuthHost string
|
||||
skipVerify bool
|
||||
pageSize int
|
||||
}
|
||||
|
||||
// Opts defines configuration options.
|
||||
type Opts struct {
|
||||
URL string // Gitea server url.
|
||||
Client string // OAuth2 Client ID
|
||||
Secret string // OAuth2 Client Secret
|
||||
OAuthHost string // OAuth2 Host
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
URL string // Gitea server url.
|
||||
OAuthClientID string // OAuth2 Client ID
|
||||
OAuthClientSecret string // OAuth2 Client Secret
|
||||
OAuthHost string // OAuth2 Host
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
}
|
||||
|
||||
// New returns a Forge implementation that integrates with Gitea,
|
||||
// an open source Git service written in Go. See https://gitea.io/
|
||||
func New(opts Opts) (forge.Forge, error) {
|
||||
return &Gitea{
|
||||
url: opts.URL,
|
||||
ClientID: opts.Client,
|
||||
ClientSecret: opts.Secret,
|
||||
OAuthHost: opts.OAuthHost,
|
||||
SkipVerify: opts.SkipVerify,
|
||||
url: opts.URL,
|
||||
oAuthClientID: opts.OAuthClientID,
|
||||
oAuthClientSecret: opts.OAuthClientSecret,
|
||||
oAuthHost: opts.OAuthHost,
|
||||
skipVerify: opts.SkipVerify,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -87,13 +87,13 @@ func (c *Gitea) URL() string {
|
||||
}
|
||||
|
||||
func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Context) {
|
||||
publicOAuthURL := c.OAuthHost
|
||||
publicOAuthURL := c.oAuthHost
|
||||
if publicOAuthURL == "" {
|
||||
publicOAuthURL = c.url
|
||||
}
|
||||
return &oauth2.Config{
|
||||
ClientID: c.ClientID,
|
||||
ClientSecret: c.ClientSecret,
|
||||
ClientID: c.oAuthClientID,
|
||||
ClientSecret: c.oAuthClientSecret,
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: fmt.Sprintf(authorizeTokenURL, publicOAuthURL),
|
||||
TokenURL: fmt.Sprintf(accessTokenURL, c.url),
|
||||
@ -102,7 +102,7 @@ func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Conte
|
||||
},
|
||||
|
||||
context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.SkipVerify},
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.skipVerify},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
}})
|
||||
}
|
||||
@ -575,7 +575,7 @@ func (c *Gitea) Org(ctx context.Context, u *model.User, owner string) (*model.Or
|
||||
// newClientToken returns the Gitea client with Token.
|
||||
func (c *Gitea) newClientToken(ctx context.Context, token string) (*gitea.Client, error) {
|
||||
httpClient := &http.Client{}
|
||||
if c.SkipVerify {
|
||||
if c.skipVerify {
|
||||
httpClient.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func TestNew(t *testing.T) {
|
||||
|
||||
f, _ := forge.(*Gitea)
|
||||
assert.Equal(t, "http://localhost:8080", f.url)
|
||||
assert.True(t, f.SkipVerify)
|
||||
assert.True(t, f.skipVerify)
|
||||
}
|
||||
|
||||
func Test_gitea(t *testing.T) {
|
||||
|
@ -47,13 +47,13 @@ const (
|
||||
|
||||
// Opts defines configuration options.
|
||||
type Opts struct {
|
||||
URL string // GitHub server url.
|
||||
Client string // GitHub oauth client id.
|
||||
Secret string // GitHub oauth client secret.
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
MergeRef bool // Clone pull requests using the merge ref.
|
||||
OnlyPublic bool // Only obtain OAuth tokens with access to public repos.
|
||||
OAuthHost string // Public url for oauth if different from url.
|
||||
URL string // GitHub server url.
|
||||
OAuthClientID string // GitHub oauth client id.
|
||||
OAuthClientSecret string // GitHub oauth client secret.
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
MergeRef bool // Clone pull requests using the merge ref.
|
||||
OnlyPublic bool // Only obtain OAuth tokens with access to public repos.
|
||||
OAuthHost string // Public url for oauth if different from url.
|
||||
}
|
||||
|
||||
// New returns a Forge implementation that integrates with a GitHub Cloud or
|
||||
@ -62,8 +62,8 @@ func New(opts Opts) (forge.Forge, error) {
|
||||
r := &client{
|
||||
API: defaultAPI,
|
||||
url: defaultURL,
|
||||
Client: opts.Client,
|
||||
Secret: opts.Secret,
|
||||
Client: opts.OAuthClientID,
|
||||
Secret: opts.OAuthClientSecret,
|
||||
oAuthHost: opts.OAuthHost,
|
||||
SkipVerify: opts.SkipVerify,
|
||||
MergeRef: opts.MergeRef,
|
||||
|
@ -28,10 +28,10 @@ import (
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
forge, _ := New(Opts{
|
||||
URL: "http://localhost:8080/",
|
||||
Client: "0ZXh0IjoiI",
|
||||
Secret: "I1NiIsInR5",
|
||||
SkipVerify: true,
|
||||
URL: "http://localhost:8080/",
|
||||
OAuthClientID: "0ZXh0IjoiI",
|
||||
OAuthClientSecret: "I1NiIsInR5",
|
||||
SkipVerify: true,
|
||||
})
|
||||
f, _ := forge.(*client)
|
||||
assert.Equal(t, "http://localhost:8080", f.url)
|
||||
|
@ -47,34 +47,34 @@ const (
|
||||
|
||||
// Opts defines configuration options.
|
||||
type Opts struct {
|
||||
URL string // Gitlab server url.
|
||||
ClientID string // Oauth2 client id.
|
||||
ClientSecret string // Oauth2 client secret.
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
OAuthHost string // Public url for oauth if different from url.
|
||||
URL string // Gitlab server url.
|
||||
OAuthClientID string // Oauth2 client id.
|
||||
OAuthClientSecret string // Oauth2 client secret.
|
||||
SkipVerify bool // Skip ssl verification.
|
||||
OAuthHost string // Public url for oauth if different from url.
|
||||
}
|
||||
|
||||
// Gitlab implements "Forge" interface.
|
||||
type GitLab struct {
|
||||
url string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
SkipVerify bool
|
||||
HideArchives bool
|
||||
Search bool
|
||||
oAuthHost string
|
||||
url string
|
||||
oAuthClientID string
|
||||
oAuthClientSecret string
|
||||
skipVerify bool
|
||||
hideArchives bool
|
||||
search bool
|
||||
oAuthHost string
|
||||
}
|
||||
|
||||
// New returns a Forge implementation that integrates with Gitlab, an open
|
||||
// source Git service. See https://gitlab.com
|
||||
func New(opts Opts) (forge.Forge, error) {
|
||||
return &GitLab{
|
||||
url: opts.URL,
|
||||
ClientID: opts.ClientID,
|
||||
ClientSecret: opts.ClientSecret,
|
||||
oAuthHost: opts.OAuthHost,
|
||||
SkipVerify: opts.SkipVerify,
|
||||
HideArchives: true,
|
||||
url: opts.URL,
|
||||
oAuthClientID: opts.OAuthClientID,
|
||||
oAuthClientSecret: opts.OAuthClientSecret,
|
||||
oAuthHost: opts.OAuthHost,
|
||||
skipVerify: opts.SkipVerify,
|
||||
hideArchives: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -95,8 +95,8 @@ func (g *GitLab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont
|
||||
}
|
||||
|
||||
return &oauth2.Config{
|
||||
ClientID: g.ClientID,
|
||||
ClientSecret: g.ClientSecret,
|
||||
ClientID: g.oAuthClientID,
|
||||
ClientSecret: g.oAuthClientSecret,
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: fmt.Sprintf("%s/oauth/authorize", publicOAuthURL),
|
||||
TokenURL: fmt.Sprintf("%s/oauth/token", g.url),
|
||||
@ -106,7 +106,7 @@ func (g *GitLab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont
|
||||
},
|
||||
|
||||
context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: g.SkipVerify},
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: g.skipVerify},
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
}})
|
||||
}
|
||||
@ -127,7 +127,7 @@ func (g *GitLab) Login(ctx context.Context, req *forge_types.OAuthRequest) (*mod
|
||||
return nil, redirectURL, fmt.Errorf("error exchanging token: %w", err)
|
||||
}
|
||||
|
||||
client, err := newClient(g.url, token.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, token.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, redirectURL, err
|
||||
}
|
||||
@ -178,7 +178,7 @@ func (g *GitLab) Refresh(ctx context.Context, user *model.User) (bool, error) {
|
||||
|
||||
// Auth authenticates the session and returns the forge user login for the given token.
|
||||
func (g *GitLab) Auth(ctx context.Context, token, _ string) (string, error) {
|
||||
client, err := newClient(g.url, token, g.SkipVerify)
|
||||
client, err := newClient(g.url, token, g.skipVerify)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -192,7 +192,7 @@ func (g *GitLab) Auth(ctx context.Context, token, _ string) (string, error) {
|
||||
|
||||
// Teams fetches a list of team memberships from the forge.
|
||||
func (g *GitLab) Teams(ctx context.Context, user *model.User) ([]*model.Team, error) {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -261,7 +261,7 @@ func (g *GitLab) getInheritedProjectMember(ctx context.Context, client *gitlab.C
|
||||
|
||||
// Repo fetches the repository from the forge.
|
||||
func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -286,7 +286,7 @@ func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.Forg
|
||||
|
||||
// Repos fetches a list of repos from the forge.
|
||||
func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, error) {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -296,7 +296,7 @@ func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
|
||||
ListOptions: gitlab.ListOptions{PerPage: perPage},
|
||||
MinAccessLevel: gitlab.Ptr(gitlab.DeveloperPermissions), // TODO: check what's best here
|
||||
}
|
||||
if g.HideArchives {
|
||||
if g.hideArchives {
|
||||
opts.Archived = gitlab.Ptr(false)
|
||||
}
|
||||
intUserID, err := strconv.Atoi(string(user.ForgeRemoteID))
|
||||
@ -335,7 +335,7 @@ func (g *GitLab) Repos(ctx context.Context, user *model.User) ([]*model.Repo, er
|
||||
|
||||
func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) {
|
||||
token := common.UserToken(ctx, r, u)
|
||||
client, err := newClient(g.url, token, g.SkipVerify)
|
||||
client, err := newClient(g.url, token, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -366,7 +366,7 @@ func (g *GitLab) PullRequests(ctx context.Context, u *model.User, r *model.Repo,
|
||||
|
||||
// File fetches a file from the forge repository and returns in string format.
|
||||
func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, fileName string) ([]byte, error) {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -383,7 +383,7 @@ func (g *GitLab) File(ctx context.Context, user *model.User, repo *model.Repo, p
|
||||
|
||||
// Dir fetches a folder from the forge repository.
|
||||
func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, path string) ([]*forge_types.FileMeta, error) {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -435,7 +435,7 @@ func (g *GitLab) Dir(ctx context.Context, user *model.User, repo *model.Repo, pi
|
||||
|
||||
// Status sends the commit status back to gitlab.
|
||||
func (g *GitLab) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, workflow *model.Workflow) error {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -493,7 +493,7 @@ func (g *GitLab) getTokenAndWebURL(link string) (token, webURL string, err error
|
||||
// Activate activates a repository by adding a Post-commit hook and
|
||||
// a Public Deploy key, if applicable.
|
||||
func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Repo, link string) error {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -519,7 +519,7 @@ func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Rep
|
||||
TagPushEvents: gitlab.Ptr(true),
|
||||
MergeRequestsEvents: gitlab.Ptr(true),
|
||||
DeploymentEvents: gitlab.Ptr(true),
|
||||
EnableSSLVerification: gitlab.Ptr(!g.SkipVerify),
|
||||
EnableSSLVerification: gitlab.Ptr(!g.skipVerify),
|
||||
}, gitlab.WithContext(ctx))
|
||||
|
||||
return err
|
||||
@ -528,7 +528,7 @@ func (g *GitLab) Activate(ctx context.Context, user *model.User, repo *model.Rep
|
||||
// Deactivate removes a repository by removing all the post-commit hooks
|
||||
// which are equal to link and removing the SSH deploy key.
|
||||
func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.Repo, link string) error {
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -577,7 +577,7 @@ func (g *GitLab) Deactivate(ctx context.Context, user *model.User, repo *model.R
|
||||
// Branches returns the names of all branches for the named repository.
|
||||
func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Repo, p *model.ListOptions) ([]string, error) {
|
||||
token := common.UserToken(ctx, repo, user)
|
||||
client, err := newClient(g.url, token, g.SkipVerify)
|
||||
client, err := newClient(g.url, token, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -604,7 +604,7 @@ func (g *GitLab) Branches(ctx context.Context, user *model.User, repo *model.Rep
|
||||
// BranchHead returns the sha of the head (latest commit) of the specified branch.
|
||||
func (g *GitLab) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (*model.Commit, error) {
|
||||
token := common.UserToken(ctx, r, u)
|
||||
client, err := newClient(g.url, token, g.SkipVerify)
|
||||
client, err := newClient(g.url, token, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -677,7 +677,7 @@ func (g *GitLab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *mod
|
||||
// OrgMembership returns if user is member of organization and if user
|
||||
// is admin/owner in this organization.
|
||||
func (g *GitLab) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) {
|
||||
client, err := newClient(g.url, u.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, u.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -731,7 +731,7 @@ func (g *GitLab) OrgMembership(ctx context.Context, u *model.User, owner string)
|
||||
}
|
||||
|
||||
func (g *GitLab) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) {
|
||||
client, err := newClient(g.url, u.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, u.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -797,7 +797,7 @@ func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client, err := newClient(g.url, user.AccessToken, g.SkipVerify)
|
||||
client, err := newClient(g.url, user.AccessToken, g.skipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ func load(config string) *GitLab {
|
||||
|
||||
gitlab := GitLab{}
|
||||
gitlab.url = _url.String()
|
||||
gitlab.ClientID = params.Get("client_id")
|
||||
gitlab.ClientSecret = params.Get("client_secret")
|
||||
gitlab.SkipVerify, _ = strconv.ParseBool(params.Get("skip_verify"))
|
||||
gitlab.HideArchives, _ = strconv.ParseBool(params.Get("hide_archives"))
|
||||
gitlab.oAuthClientID = params.Get("client_id")
|
||||
gitlab.oAuthClientSecret = params.Get("client_secret")
|
||||
gitlab.skipVerify, _ = strconv.ParseBool(params.Get("skip_verify"))
|
||||
gitlab.hideArchives, _ = strconv.ParseBool(params.Get("hide_archives"))
|
||||
|
||||
// this is a temp workaround
|
||||
gitlab.Search, _ = strconv.ParseBool(params.Get("search"))
|
||||
gitlab.search, _ = strconv.ParseBool(params.Get("search"))
|
||||
|
||||
return &gitlab
|
||||
}
|
||||
@ -70,14 +70,14 @@ func Test_GitLab(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
// Test projects method
|
||||
t.Run("Should return only non-archived projects is hidden", func(t *testing.T) {
|
||||
client.HideArchives = true
|
||||
client.hideArchives = true
|
||||
_projects, err := client.Repos(ctx, &user)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, _projects, 1)
|
||||
})
|
||||
|
||||
t.Run("Should return all the projects", func(t *testing.T) {
|
||||
client.HideArchives = false
|
||||
client.hideArchives = false
|
||||
_projects, err := client.Repos(ctx, &user)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
@ -41,12 +41,13 @@ func Forge(forge *model.Forge) (forge.Forge, error) {
|
||||
|
||||
func setupBitbucket(forge *model.Forge) (forge.Forge, error) {
|
||||
opts := &bitbucket.Opts{
|
||||
Client: forge.Client,
|
||||
Secret: forge.ClientSecret,
|
||||
OAuthClientID: forge.OAuthClientID,
|
||||
OAuthClientSecret: forge.OAuthClientSecret,
|
||||
}
|
||||
|
||||
log.Debug().
|
||||
Bool("client-set", opts.Client != "").
|
||||
Bool("secret-set", opts.Secret != "").
|
||||
Bool("oauth-client-id-set", opts.OAuthClientID != "").
|
||||
Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
|
||||
Str("type", string(forge.Type)).
|
||||
Msg("setting up forge")
|
||||
return bitbucket.New(opts)
|
||||
@ -59,11 +60,11 @@ func setupGitea(forge *model.Forge) (forge.Forge, error) {
|
||||
}
|
||||
|
||||
opts := gitea.Opts{
|
||||
URL: strings.TrimRight(serverURL.String(), "/"),
|
||||
Client: forge.Client,
|
||||
Secret: forge.ClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
URL: strings.TrimRight(serverURL.String(), "/"),
|
||||
OAuthClientID: forge.OAuthClientID,
|
||||
OAuthClientSecret: forge.OAuthClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
}
|
||||
if len(opts.URL) == 0 {
|
||||
return nil, fmt.Errorf("WOODPECKER_GITEA_URL must be set")
|
||||
@ -72,8 +73,8 @@ func setupGitea(forge *model.Forge) (forge.Forge, error) {
|
||||
Str("url", opts.URL).
|
||||
Str("oauth-host", opts.OAuthHost).
|
||||
Bool("skip-verify", opts.SkipVerify).
|
||||
Bool("client-set", opts.Client != "").
|
||||
Bool("secret-set", opts.Secret != "").
|
||||
Bool("oauth-client-id-set", opts.OAuthClientID != "").
|
||||
Bool("oauth-secret-id-set", opts.OAuthClientSecret != "").
|
||||
Str("type", string(forge.Type)).
|
||||
Msg("setting up forge")
|
||||
return gitea.New(opts)
|
||||
@ -86,11 +87,11 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
|
||||
}
|
||||
|
||||
opts := forgejo.Opts{
|
||||
URL: strings.TrimRight(server.String(), "/"),
|
||||
Client: forge.Client,
|
||||
Secret: forge.ClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
OAuth2URL: forge.OAuthHost,
|
||||
URL: strings.TrimRight(server.String(), "/"),
|
||||
OAuthClientID: forge.OAuthClientID,
|
||||
OAuthClientSecret: forge.OAuthClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
OAuth2URL: forge.OAuthHost,
|
||||
}
|
||||
if len(opts.URL) == 0 {
|
||||
return nil, fmt.Errorf("WOODPECKER_FORGEJO_URL must be set")
|
||||
@ -99,8 +100,8 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
|
||||
Str("url", opts.URL).
|
||||
Str("oauth2-url", opts.OAuth2URL).
|
||||
Bool("skip-verify", opts.SkipVerify).
|
||||
Bool("client-set", opts.Client != "").
|
||||
Bool("secret-set", opts.Secret != "").
|
||||
Bool("oauth-client-id-set", opts.OAuthClientID != "").
|
||||
Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
|
||||
Str("type", string(forge.Type)).
|
||||
Msg("setting up forge")
|
||||
return forgejo.New(opts)
|
||||
@ -108,18 +109,18 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
|
||||
|
||||
func setupGitLab(forge *model.Forge) (forge.Forge, error) {
|
||||
opts := gitlab.Opts{
|
||||
URL: forge.URL,
|
||||
ClientID: forge.Client,
|
||||
ClientSecret: forge.ClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
URL: forge.URL,
|
||||
OAuthClientID: forge.OAuthClientID,
|
||||
OAuthClientSecret: forge.OAuthClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
}
|
||||
log.Debug().
|
||||
Str("url", opts.URL).
|
||||
Str("oauth-host", opts.OAuthHost).
|
||||
Bool("skip-verify", opts.SkipVerify).
|
||||
Bool("client-id-set", opts.ClientID != "").
|
||||
Bool("client-secret-set", opts.ClientSecret != "").
|
||||
Bool("oauth-client-id-set", opts.OAuthClientID != "").
|
||||
Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
|
||||
Str("type", string(forge.Type)).
|
||||
Msg("setting up forge")
|
||||
return gitlab.New(opts)
|
||||
@ -137,13 +138,13 @@ func setupGitHub(forge *model.Forge) (forge.Forge, error) {
|
||||
}
|
||||
|
||||
opts := github.Opts{
|
||||
URL: forge.URL,
|
||||
Client: forge.Client,
|
||||
Secret: forge.ClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
MergeRef: mergeRef,
|
||||
OnlyPublic: publicOnly,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
URL: forge.URL,
|
||||
OAuthClientID: forge.OAuthClientID,
|
||||
OAuthClientSecret: forge.OAuthClientSecret,
|
||||
SkipVerify: forge.SkipVerify,
|
||||
MergeRef: mergeRef,
|
||||
OnlyPublic: publicOnly,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
}
|
||||
log.Debug().
|
||||
Str("url", opts.URL).
|
||||
@ -151,8 +152,8 @@ func setupGitHub(forge *model.Forge) (forge.Forge, error) {
|
||||
Bool("merge-ref", opts.MergeRef).
|
||||
Bool("only-public", opts.OnlyPublic).
|
||||
Bool("skip-verify", opts.SkipVerify).
|
||||
Bool("client-set", opts.Client != "").
|
||||
Bool("secret-set", opts.Secret != "").
|
||||
Bool("oauth-client-id-set", opts.OAuthClientID != "").
|
||||
Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
|
||||
Str("type", string(forge.Type)).
|
||||
Msg("setting up forge")
|
||||
return github.New(opts)
|
||||
@ -169,18 +170,18 @@ func setupBitbucketDatacenter(forge *model.Forge) (forge.Forge, error) {
|
||||
}
|
||||
|
||||
opts := bitbucketdatacenter.Opts{
|
||||
URL: forge.URL,
|
||||
ClientID: forge.Client,
|
||||
ClientSecret: forge.ClientSecret,
|
||||
Username: gitUsername,
|
||||
Password: gitPassword,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
URL: forge.URL,
|
||||
OAuthClientID: forge.OAuthClientID,
|
||||
OAuthClientSecret: forge.OAuthClientSecret,
|
||||
Username: gitUsername,
|
||||
Password: gitPassword,
|
||||
OAuthHost: forge.OAuthHost,
|
||||
}
|
||||
log.Debug().
|
||||
Str("url", opts.URL).
|
||||
Str("oauth-host", opts.OAuthHost).
|
||||
Bool("client-id-set", opts.ClientID != "").
|
||||
Bool("client-secret-set", opts.ClientSecret != "").
|
||||
Bool("oauth-client-id-set", opts.OAuthClientID != "").
|
||||
Bool("oauth-client-secret-set", opts.OAuthClientSecret != "").
|
||||
Str("type", string(forge.Type)).
|
||||
Msg("setting up forge")
|
||||
return bitbucketdatacenter.New(opts)
|
||||
|
@ -30,8 +30,8 @@ type Forge struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
Type ForgeType `json:"type" xorm:"VARCHAR(250)"`
|
||||
URL string `json:"url" xorm:"VARCHAR(500) 'url'"`
|
||||
Client string `json:"client,omitempty" xorm:"VARCHAR(250)"`
|
||||
ClientSecret string `json:"-" xorm:"VARCHAR(250)"` // do not expose client secret
|
||||
OAuthClientID string `json:"client,omitempty" xorm:"VARCHAR(250)"`
|
||||
OAuthClientSecret string `json:"-" xorm:"VARCHAR(250)"` // do not expose client secret
|
||||
SkipVerify bool `json:"skip_verify,omitempty" xorm:"bool"`
|
||||
OAuthHost string `json:"oauth_host,omitempty" xorm:"VARCHAR(250) 'oauth_host'"` // public url for oauth if different from url
|
||||
AdditionalOptions map[string]any `json:"additional_options,omitempty" xorm:"json"`
|
||||
|
@ -115,8 +115,8 @@ func setupForgeService(c *cli.Command, _store store.Store) error {
|
||||
_forge.AdditionalOptions = make(map[string]any)
|
||||
}
|
||||
|
||||
_forge.Client = strings.TrimSpace(c.String("forge-oauth-client"))
|
||||
_forge.ClientSecret = strings.TrimSpace(c.String("forge-oauth-secret"))
|
||||
_forge.OAuthClientID = strings.TrimSpace(c.String("forge-oauth-client"))
|
||||
_forge.OAuthClientSecret = strings.TrimSpace(c.String("forge-oauth-secret"))
|
||||
_forge.URL = c.String("forge-url")
|
||||
_forge.SkipVerify = c.Bool("forge-skip-verify")
|
||||
_forge.OAuthHost = c.String("forge-oauth-host")
|
||||
|
@ -27,11 +27,11 @@ func TestForgeCRUD(t *testing.T) {
|
||||
defer closer()
|
||||
|
||||
forge1 := &model.Forge{
|
||||
Type: "github",
|
||||
URL: "https://github.com",
|
||||
Client: "client",
|
||||
ClientSecret: "secret",
|
||||
SkipVerify: false,
|
||||
Type: "github",
|
||||
URL: "https://github.com",
|
||||
OAuthClientID: "client",
|
||||
OAuthClientSecret: "secret",
|
||||
SkipVerify: false,
|
||||
AdditionalOptions: map[string]any{
|
||||
"foo": "bar",
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user