diff --git a/cmd/agola/cmd/serve.go b/cmd/agola/cmd/serve.go index f403725..75969e9 100644 --- a/cmd/agola/cmd/serve.go +++ b/cmd/agola/cmd/serve.go @@ -129,7 +129,7 @@ func serve(cmd *cobra.Command, args []string) error { return errors.Wrapf(err, "failed to start scheduler") } - gateway, err := gateway.NewGateway(&c.Gateway) + gateway, err := gateway.NewGateway(c) if err != nil { return errors.Wrapf(err, "failed to start gateway") } diff --git a/internal/gitsources/gitea/gitea.go b/internal/gitsources/gitea/gitea.go index 26895cd..c6c46d3 100644 --- a/internal/gitsources/gitea/gitea.go +++ b/internal/gitsources/gitea/gitea.go @@ -94,13 +94,13 @@ func New(opts Opts) (*Client, error) { }, nil } -func (c *Client) LoginPassword(username, password string) (string, error) { +func (c *Client) LoginPassword(username, password, tokenName string) (string, error) { // try to get agola access token if it already exists var accessToken string tokens, err := c.client.ListAccessTokens(username, password) if err == nil { for _, token := range tokens { - if token.Name == "agola" { + if token.Name == tokenName { accessToken = token.Sha1 break } @@ -112,7 +112,7 @@ func (c *Client) LoginPassword(username, password string) (string, error) { token, terr := c.client.CreateAccessToken( username, password, - gitea.CreateAccessTokenOption{Name: "agola"}, + gitea.CreateAccessTokenOption{Name: tokenName}, ) if terr != nil { return "", terr diff --git a/internal/gitsources/gitsource.go b/internal/gitsources/gitsource.go index ba8330b..f5e5d10 100644 --- a/internal/gitsources/gitsource.go +++ b/internal/gitsources/gitsource.go @@ -48,7 +48,7 @@ type UserSource interface { type PasswordSource interface { UserSource - LoginPassword(username, password string) (string, error) + LoginPassword(username, password, tokenName string) (string, error) } type Oauth2Source interface { diff --git a/internal/services/gateway/command/command.go b/internal/services/gateway/command/command.go index e3f8b06..9a10ceb 100644 --- a/internal/services/gateway/command/command.go +++ b/internal/services/gateway/command/command.go @@ -29,15 +29,17 @@ type CommandHandler struct { log *zap.SugaredLogger sd *common.TokenSigningData configstoreClient *csapi.Client + agolaID string apiExposedURL string webExposedURL string } -func NewCommandHandler(logger *zap.Logger, sd *common.TokenSigningData, configstoreClient *csapi.Client, apiExposedURL, webExposedURL string) *CommandHandler { +func NewCommandHandler(logger *zap.Logger, sd *common.TokenSigningData, configstoreClient *csapi.Client, agolaID, apiExposedURL, webExposedURL string) *CommandHandler { return &CommandHandler{ log: logger.Sugar(), sd: sd, configstoreClient: configstoreClient, + agolaID: agolaID, apiExposedURL: apiExposedURL, webExposedURL: webExposedURL, } diff --git a/internal/services/gateway/command/user.go b/internal/services/gateway/command/user.go index 483e701..6c24515 100644 --- a/internal/services/gateway/command/user.go +++ b/internal/services/gateway/command/user.go @@ -518,7 +518,8 @@ func (c *CommandHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourc if err != nil { return nil, errors.Wrapf(err, "failed to create git source") } - accessToken, err := passwordSource.LoginPassword(loginName, loginPassword) + tokenName := "agola-" + c.agolaID + accessToken, err := passwordSource.LoginPassword(loginName, loginPassword, tokenName) if err != nil { return nil, errors.Wrapf(err, "failed to login to remote source %q with login name %q", rs.Name, loginName) } diff --git a/internal/services/gateway/gateway.go b/internal/services/gateway/gateway.go index c10b694..e8df76c 100644 --- a/internal/services/gateway/gateway.go +++ b/internal/services/gateway/gateway.go @@ -58,7 +58,8 @@ type Gateway struct { sd *common.TokenSigningData } -func NewGateway(c *config.Gateway) (*Gateway, error) { +func NewGateway(gc *config.Config) (*Gateway, error) { + c := &gc.Gateway if c.Debug { level.SetLevel(zapcore.DebugLevel) } @@ -122,7 +123,7 @@ func NewGateway(c *config.Gateway) (*Gateway, error) { configstoreClient := csapi.NewClient(c.ConfigStoreURL) - ch := command.NewCommandHandler(logger, sd, configstoreClient, c.APIExposedURL, c.WebExposedURL) + ch := command.NewCommandHandler(logger, sd, configstoreClient, gc.ID, c.APIExposedURL, c.WebExposedURL) return &Gateway{ c: c,