Rename oauth variables (#5435)

Co-authored-by: Anton Bracke <anton.bracke@fastleansmart.com>
This commit is contained in:
Anbraten 2025-08-20 22:47:43 +02:00 committed by GitHub
parent 88b926c9dd
commit 24ebcb8cf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 197 additions and 196 deletions

View File

@ -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,

View File

@ -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
api string
url string
Client string
Secret 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,
api: DefaultAPI,
url: DefaultURL,
Client: opts.Client,
Secret: opts.Secret,
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),

View File

@ -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()

View File

@ -41,8 +41,8 @@ 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
OAuthClientID string // OAuth 2.0 client id
OAuthClientSecret string // OAuth 2.0 client secret
OAuthHost string // OAuth 2.0 host
}
@ -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")
}

View File

@ -30,8 +30,8 @@ func TestNew(t *testing.T) {
URL: "http://localhost:8080",
Username: "0ZXh0IjoiI",
Password: "I1NiIsInR5",
ClientID: "client-id",
ClientSecret: "client-secret",
OAuthClientID: "client-id",
OAuthClientSecret: "client-secret",
})
assert.NoError(t, err)
assert.NotNil(t, forge)

View File

@ -47,9 +47,9 @@ const (
type Forgejo struct {
url string
oauth2URL string
ClientID string
ClientSecret string
SkipVerify bool
oAuthClientID string
oAuthClientSecret string
skipVerify bool
pageSize int
}
@ -57,8 +57,8 @@ type Forgejo struct {
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
OAuthClientID string // OAuth2 Client ID
OAuthClientSecret string // OAuth2 Client Secret
SkipVerify bool // Skip ssl verification.
}
@ -72,9 +72,9 @@ func New(opts Opts) (forge.Forge, error) {
return &Forgejo{
url: opts.URL,
oauth2URL: opts.OAuth2URL,
ClientID: opts.Client,
ClientSecret: opts.Secret,
SkipVerify: opts.SkipVerify,
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},
}

View File

@ -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) {

View File

@ -48,18 +48,18 @@ const (
type Gitea struct {
url string
ClientID string
ClientSecret string
OAuthHost string
SkipVerify bool
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
OAuthClientID string // OAuth2 Client ID
OAuthClientSecret string // OAuth2 Client Secret
OAuthHost string // OAuth2 Host
SkipVerify bool // Skip ssl verification.
}
@ -69,10 +69,10 @@ type Opts struct {
func New(opts Opts) (forge.Forge, error) {
return &Gitea{
url: opts.URL,
ClientID: opts.Client,
ClientSecret: opts.Secret,
OAuthHost: opts.OAuthHost,
SkipVerify: opts.SkipVerify,
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},
}

View File

@ -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) {

View File

@ -48,8 +48,8 @@ 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.
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.
@ -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,

View File

@ -29,8 +29,8 @@ import (
func TestNew(t *testing.T) {
forge, _ := New(Opts{
URL: "http://localhost:8080/",
Client: "0ZXh0IjoiI",
Secret: "I1NiIsInR5",
OAuthClientID: "0ZXh0IjoiI",
OAuthClientSecret: "I1NiIsInR5",
SkipVerify: true,
})
f, _ := forge.(*client)

View File

@ -48,8 +48,8 @@ const (
// Opts defines configuration options.
type Opts struct {
URL string // Gitlab server url.
ClientID string // Oauth2 client id.
ClientSecret string // Oauth2 client secret.
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.
}
@ -57,11 +57,11 @@ type Opts struct {
// Gitlab implements "Forge" interface.
type GitLab struct {
url string
ClientID string
ClientSecret string
SkipVerify bool
HideArchives bool
Search bool
oAuthClientID string
oAuthClientSecret string
skipVerify bool
hideArchives bool
search bool
oAuthHost string
}
@ -70,11 +70,11 @@ type GitLab struct {
func New(opts Opts) (forge.Forge, error) {
return &GitLab{
url: opts.URL,
ClientID: opts.ClientID,
ClientSecret: opts.ClientSecret,
oAuthClientID: opts.OAuthClientID,
oAuthClientSecret: opts.OAuthClientSecret,
oAuthHost: opts.OAuthHost,
SkipVerify: opts.SkipVerify,
HideArchives: true,
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
}

View File

@ -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)

View File

@ -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)
@ -60,8 +61,8 @@ func setupGitea(forge *model.Forge) (forge.Forge, error) {
opts := gitea.Opts{
URL: strings.TrimRight(serverURL.String(), "/"),
Client: forge.Client,
Secret: forge.ClientSecret,
OAuthClientID: forge.OAuthClientID,
OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify,
OAuthHost: forge.OAuthHost,
}
@ -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)
@ -87,8 +88,8 @@ func setupForgejo(forge *model.Forge) (forge.Forge, error) {
opts := forgejo.Opts{
URL: strings.TrimRight(server.String(), "/"),
Client: forge.Client,
Secret: forge.ClientSecret,
OAuthClientID: forge.OAuthClientID,
OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify,
OAuth2URL: forge.OAuthHost,
}
@ -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)
@ -109,8 +110,8 @@ 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,
OAuthClientID: forge.OAuthClientID,
OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify,
OAuthHost: forge.OAuthHost,
}
@ -118,8 +119,8 @@ func setupGitLab(forge *model.Forge) (forge.Forge, error) {
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)
@ -138,8 +139,8 @@ func setupGitHub(forge *model.Forge) (forge.Forge, error) {
opts := github.Opts{
URL: forge.URL,
Client: forge.Client,
Secret: forge.ClientSecret,
OAuthClientID: forge.OAuthClientID,
OAuthClientSecret: forge.OAuthClientSecret,
SkipVerify: forge.SkipVerify,
MergeRef: mergeRef,
OnlyPublic: publicOnly,
@ -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)
@ -170,8 +171,8 @@ func setupBitbucketDatacenter(forge *model.Forge) (forge.Forge, error) {
opts := bitbucketdatacenter.Opts{
URL: forge.URL,
ClientID: forge.Client,
ClientSecret: forge.ClientSecret,
OAuthClientID: forge.OAuthClientID,
OAuthClientSecret: forge.OAuthClientSecret,
Username: gitUsername,
Password: gitPassword,
OAuthHost: forge.OAuthHost,
@ -179,8 +180,8 @@ func setupBitbucketDatacenter(forge *model.Forge) (forge.Forge, error) {
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)

View File

@ -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"`

View File

@ -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")

View File

@ -29,8 +29,8 @@ func TestForgeCRUD(t *testing.T) {
forge1 := &model.Forge{
Type: "github",
URL: "https://github.com",
Client: "client",
ClientSecret: "secret",
OAuthClientID: "client",
OAuthClientSecret: "secret",
SkipVerify: false,
AdditionalOptions: map[string]any{
"foo": "bar",