gateway: use agola ID in gitsource tokenname
This commit is contained in:
parent
e970e217e2
commit
fefa2819c9
|
@ -129,7 +129,7 @@ func serve(cmd *cobra.Command, args []string) error {
|
||||||
return errors.Wrapf(err, "failed to start scheduler")
|
return errors.Wrapf(err, "failed to start scheduler")
|
||||||
}
|
}
|
||||||
|
|
||||||
gateway, err := gateway.NewGateway(&c.Gateway)
|
gateway, err := gateway.NewGateway(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to start gateway")
|
return errors.Wrapf(err, "failed to start gateway")
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,13 +94,13 @@ func New(opts Opts) (*Client, error) {
|
||||||
}, nil
|
}, 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
|
// try to get agola access token if it already exists
|
||||||
var accessToken string
|
var accessToken string
|
||||||
tokens, err := c.client.ListAccessTokens(username, password)
|
tokens, err := c.client.ListAccessTokens(username, password)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
if token.Name == "agola" {
|
if token.Name == tokenName {
|
||||||
accessToken = token.Sha1
|
accessToken = token.Sha1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (c *Client) LoginPassword(username, password string) (string, error) {
|
||||||
token, terr := c.client.CreateAccessToken(
|
token, terr := c.client.CreateAccessToken(
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
gitea.CreateAccessTokenOption{Name: "agola"},
|
gitea.CreateAccessTokenOption{Name: tokenName},
|
||||||
)
|
)
|
||||||
if terr != nil {
|
if terr != nil {
|
||||||
return "", terr
|
return "", terr
|
||||||
|
|
|
@ -48,7 +48,7 @@ type UserSource interface {
|
||||||
|
|
||||||
type PasswordSource interface {
|
type PasswordSource interface {
|
||||||
UserSource
|
UserSource
|
||||||
LoginPassword(username, password string) (string, error)
|
LoginPassword(username, password, tokenName string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Oauth2Source interface {
|
type Oauth2Source interface {
|
||||||
|
|
|
@ -29,15 +29,17 @@ type CommandHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
sd *common.TokenSigningData
|
sd *common.TokenSigningData
|
||||||
configstoreClient *csapi.Client
|
configstoreClient *csapi.Client
|
||||||
|
agolaID string
|
||||||
apiExposedURL string
|
apiExposedURL string
|
||||||
webExposedURL 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{
|
return &CommandHandler{
|
||||||
log: logger.Sugar(),
|
log: logger.Sugar(),
|
||||||
sd: sd,
|
sd: sd,
|
||||||
configstoreClient: configstoreClient,
|
configstoreClient: configstoreClient,
|
||||||
|
agolaID: agolaID,
|
||||||
apiExposedURL: apiExposedURL,
|
apiExposedURL: apiExposedURL,
|
||||||
webExposedURL: webExposedURL,
|
webExposedURL: webExposedURL,
|
||||||
}
|
}
|
||||||
|
|
|
@ -518,7 +518,8 @@ func (c *CommandHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourc
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create git source")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to login to remote source %q with login name %q", rs.Name, loginName)
|
return nil, errors.Wrapf(err, "failed to login to remote source %q with login name %q", rs.Name, loginName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,8 @@ type Gateway struct {
|
||||||
sd *common.TokenSigningData
|
sd *common.TokenSigningData
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGateway(c *config.Gateway) (*Gateway, error) {
|
func NewGateway(gc *config.Config) (*Gateway, error) {
|
||||||
|
c := &gc.Gateway
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
level.SetLevel(zapcore.DebugLevel)
|
level.SetLevel(zapcore.DebugLevel)
|
||||||
}
|
}
|
||||||
|
@ -122,7 +123,7 @@ func NewGateway(c *config.Gateway) (*Gateway, error) {
|
||||||
|
|
||||||
configstoreClient := csapi.NewClient(c.ConfigStoreURL)
|
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{
|
return &Gateway{
|
||||||
c: c,
|
c: c,
|
||||||
|
|
Loading…
Reference in New Issue