2019-02-21 16:58:25 +00:00
|
|
|
// Copyright 2019 Sorint.lab
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
|
2019-07-01 09:40:20 +00:00
|
|
|
scommon "agola.io/agola/internal/common"
|
|
|
|
slog "agola.io/agola/internal/log"
|
|
|
|
"agola.io/agola/internal/objectstorage"
|
|
|
|
"agola.io/agola/internal/services/common"
|
|
|
|
"agola.io/agola/internal/services/config"
|
|
|
|
"agola.io/agola/internal/services/gateway/action"
|
|
|
|
"agola.io/agola/internal/services/gateway/api"
|
|
|
|
"agola.io/agola/internal/services/gateway/handlers"
|
|
|
|
"agola.io/agola/internal/util"
|
2019-07-31 13:39:07 +00:00
|
|
|
csclient "agola.io/agola/services/configstore/client"
|
|
|
|
rsclient "agola.io/agola/services/runservice/client"
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
jwt "github.com/dgrijalva/jwt-go"
|
|
|
|
ghandlers "github.com/gorilla/handlers"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
2019-05-23 09:23:14 +00:00
|
|
|
errors "golang.org/x/xerrors"
|
2019-02-21 16:58:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
|
|
|
|
var logger = slog.New(level)
|
|
|
|
var log = logger.Sugar()
|
|
|
|
|
2019-04-03 14:59:17 +00:00
|
|
|
const (
|
|
|
|
maxRequestSize = 1024 * 1024
|
|
|
|
)
|
|
|
|
|
2019-02-21 16:58:25 +00:00
|
|
|
type Gateway struct {
|
|
|
|
c *config.Gateway
|
|
|
|
|
2019-04-27 13:16:48 +00:00
|
|
|
ost *objectstorage.ObjStorage
|
2019-07-31 13:39:07 +00:00
|
|
|
runserviceClient *rsclient.Client
|
|
|
|
configstoreClient *csclient.Client
|
2019-05-03 21:48:49 +00:00
|
|
|
ah *action.ActionHandler
|
2019-02-21 16:58:25 +00:00
|
|
|
sd *common.TokenSigningData
|
|
|
|
}
|
|
|
|
|
2019-04-30 10:13:12 +00:00
|
|
|
func NewGateway(gc *config.Config) (*Gateway, error) {
|
|
|
|
c := &gc.Gateway
|
2019-02-21 16:58:25 +00:00
|
|
|
if c.Debug {
|
|
|
|
level.SetLevel(zapcore.DebugLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Web.ListenAddress == "" {
|
|
|
|
return nil, errors.Errorf("listen address undefined")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Web.TLS {
|
|
|
|
if c.Web.TLSKeyFile == "" {
|
|
|
|
return nil, errors.Errorf("no tls key file specified")
|
|
|
|
}
|
|
|
|
if c.Web.TLSCertFile == "" {
|
|
|
|
return nil, errors.Errorf("no tls cert file specified")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sd := &common.TokenSigningData{Duration: c.TokenSigning.Duration}
|
|
|
|
switch c.TokenSigning.Method {
|
|
|
|
case "hmac":
|
|
|
|
sd.Method = jwt.SigningMethodHS256
|
|
|
|
if c.TokenSigning.Key == "" {
|
|
|
|
return nil, errors.Errorf("empty token signing key for hmac method")
|
|
|
|
}
|
|
|
|
sd.Key = []byte(c.TokenSigning.Key)
|
|
|
|
case "rsa":
|
|
|
|
if c.TokenSigning.PrivateKeyPath == "" {
|
|
|
|
return nil, errors.Errorf("token signing private key file for rsa method not defined")
|
|
|
|
}
|
|
|
|
if c.TokenSigning.PublicKeyPath == "" {
|
|
|
|
return nil, errors.Errorf("token signing public key file for rsa method not defined")
|
|
|
|
}
|
|
|
|
|
|
|
|
sd.Method = jwt.SigningMethodRS256
|
|
|
|
privateKeyData, err := ioutil.ReadFile(c.TokenSigning.PrivateKeyPath)
|
|
|
|
if err != nil {
|
2019-05-23 09:23:14 +00:00
|
|
|
return nil, errors.Errorf("error reading token signing private key: %w", err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
sd.PrivateKey, err = jwt.ParseRSAPrivateKeyFromPEM(privateKeyData)
|
|
|
|
if err != nil {
|
2019-05-23 09:23:14 +00:00
|
|
|
return nil, errors.Errorf("error parsing token signing private key: %w", err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
publicKeyData, err := ioutil.ReadFile(c.TokenSigning.PublicKeyPath)
|
|
|
|
if err != nil {
|
2019-05-23 09:23:14 +00:00
|
|
|
return nil, errors.Errorf("error reading token signing public key: %w", err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
sd.PublicKey, err = jwt.ParseRSAPublicKeyFromPEM(publicKeyData)
|
|
|
|
if err != nil {
|
2019-05-23 09:23:14 +00:00
|
|
|
return nil, errors.Errorf("error parsing token signing public key: %w", err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
case "":
|
|
|
|
return nil, errors.Errorf("missing token signing method")
|
|
|
|
default:
|
|
|
|
return nil, errors.Errorf("unknown token signing method: %q", c.TokenSigning.Method)
|
|
|
|
}
|
|
|
|
|
2019-04-27 13:16:48 +00:00
|
|
|
ost, err := scommon.NewObjectStorage(&c.ObjectStorage)
|
2019-02-21 16:58:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
configstoreClient := csclient.NewClient(c.ConfigstoreURL)
|
|
|
|
runserviceClient := rsclient.NewClient(c.RunserviceURL)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-05 22:00:45 +00:00
|
|
|
ah := action.NewActionHandler(logger, sd, configstoreClient, runserviceClient, gc.ID, c.APIExposedURL, c.WebExposedURL)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
return &Gateway{
|
|
|
|
c: c,
|
2019-04-27 13:16:48 +00:00
|
|
|
ost: ost,
|
2019-05-05 22:00:45 +00:00
|
|
|
runserviceClient: runserviceClient,
|
2019-02-21 16:58:25 +00:00
|
|
|
configstoreClient: configstoreClient,
|
2019-05-03 21:48:49 +00:00
|
|
|
ah: ah,
|
2019-02-21 16:58:25 +00:00
|
|
|
sd: sd,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Gateway) Run(ctx context.Context) error {
|
2019-07-13 21:15:00 +00:00
|
|
|
// noop coors handler
|
|
|
|
corsHandler := func(h http.Handler) http.Handler {
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2019-07-25 08:46:02 +00:00
|
|
|
if len(g.c.Web.AllowedOrigins) > 0 {
|
|
|
|
corsAllowedMethodsOptions := ghandlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "DELETE"})
|
|
|
|
corsAllowedHeadersOptions := ghandlers.AllowedHeaders([]string{"Accept", "Accept-Encoding", "Authorization", "Content-Length", "Content-Type", "X-CSRF-Token", "Authorization"})
|
|
|
|
corsAllowedOriginsOptions := ghandlers.AllowedOrigins(g.c.Web.AllowedOrigins)
|
|
|
|
corsHandler = ghandlers.CORS(corsAllowedMethodsOptions, corsAllowedHeadersOptions, corsAllowedOriginsOptions)
|
|
|
|
}
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-06-11 15:07:08 +00:00
|
|
|
webhooksHandler := api.NewWebhooksHandler(logger, g.ah, g.configstoreClient, g.runserviceClient, g.c.APIExposedURL)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-05 12:27:22 +00:00
|
|
|
projectGroupHandler := api.NewProjectGroupHandler(logger, g.ah)
|
|
|
|
projectGroupSubgroupsHandler := api.NewProjectGroupSubgroupsHandler(logger, g.ah)
|
|
|
|
projectGroupProjectsHandler := api.NewProjectGroupProjectsHandler(logger, g.ah)
|
2019-05-11 22:28:11 +00:00
|
|
|
createProjectGroupHandler := api.NewCreateProjectGroupHandler(logger, g.ah)
|
2019-05-14 15:53:48 +00:00
|
|
|
updateProjectGroupHandler := api.NewUpdateProjectGroupHandler(logger, g.ah)
|
2019-05-12 22:24:16 +00:00
|
|
|
deleteProjectGroupHandler := api.NewDeleteProjectGroupHandler(logger, g.ah)
|
2019-05-05 12:27:22 +00:00
|
|
|
|
|
|
|
projectHandler := api.NewProjectHandler(logger, g.ah)
|
2019-05-11 22:28:11 +00:00
|
|
|
createProjectHandler := api.NewCreateProjectHandler(logger, g.ah)
|
2019-05-12 21:22:18 +00:00
|
|
|
updateProjectHandler := api.NewUpdateProjectHandler(logger, g.ah)
|
2019-05-05 12:27:22 +00:00
|
|
|
deleteProjectHandler := api.NewDeleteProjectHandler(logger, g.ah)
|
2019-05-11 22:28:11 +00:00
|
|
|
projectReconfigHandler := api.NewProjectReconfigHandler(logger, g.ah)
|
|
|
|
projectUpdateRepoLinkedAccountHandler := api.NewProjectUpdateRepoLinkedAccountHandler(logger, g.ah)
|
2019-06-11 09:08:40 +00:00
|
|
|
projectCreateRunHandler := api.NewProjectCreateRunHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-05 12:11:29 +00:00
|
|
|
secretHandler := api.NewSecretHandler(logger, g.ah)
|
|
|
|
createSecretHandler := api.NewCreateSecretHandler(logger, g.ah)
|
2019-07-08 08:32:45 +00:00
|
|
|
updateSecretHandler := api.NewUpdateSecretHandler(logger, g.ah)
|
2019-05-05 12:11:29 +00:00
|
|
|
deleteSecretHandler := api.NewDeleteSecretHandler(logger, g.ah)
|
2019-03-14 13:36:18 +00:00
|
|
|
|
2019-05-04 13:16:49 +00:00
|
|
|
variableHandler := api.NewVariableHandler(logger, g.ah)
|
|
|
|
createVariableHandler := api.NewCreateVariableHandler(logger, g.ah)
|
2019-07-06 13:25:45 +00:00
|
|
|
updateVariableHandler := api.NewUpdateVariableHandler(logger, g.ah)
|
2019-05-04 13:16:49 +00:00
|
|
|
deleteVariableHandler := api.NewDeleteVariableHandler(logger, g.ah)
|
2019-03-14 13:36:18 +00:00
|
|
|
|
2019-05-05 12:45:19 +00:00
|
|
|
currentUserHandler := api.NewCurrentUserHandler(logger, g.ah)
|
|
|
|
userHandler := api.NewUserHandler(logger, g.ah)
|
|
|
|
usersHandler := api.NewUsersHandler(logger, g.ah)
|
2019-05-03 21:48:49 +00:00
|
|
|
createUserHandler := api.NewCreateUserHandler(logger, g.ah)
|
2019-05-05 12:45:19 +00:00
|
|
|
deleteUserHandler := api.NewDeleteUserHandler(logger, g.ah)
|
2019-06-11 13:09:41 +00:00
|
|
|
userCreateRunHandler := api.NewUserCreateRunHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-03 21:48:49 +00:00
|
|
|
createUserLAHandler := api.NewCreateUserLAHandler(logger, g.ah)
|
2019-05-05 12:45:19 +00:00
|
|
|
deleteUserLAHandler := api.NewDeleteUserLAHandler(logger, g.ah)
|
2019-05-03 21:48:49 +00:00
|
|
|
createUserTokenHandler := api.NewCreateUserTokenHandler(logger, g.ah)
|
2019-05-05 12:45:19 +00:00
|
|
|
deleteUserTokenHandler := api.NewDeleteUserTokenHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-05 12:54:16 +00:00
|
|
|
remoteSourceHandler := api.NewRemoteSourceHandler(logger, g.ah)
|
2019-05-03 21:48:49 +00:00
|
|
|
createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(logger, g.ah)
|
2019-05-23 08:29:03 +00:00
|
|
|
updateRemoteSourceHandler := api.NewUpdateRemoteSourceHandler(logger, g.ah)
|
2019-05-05 12:54:16 +00:00
|
|
|
remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, g.ah)
|
2019-05-09 22:03:03 +00:00
|
|
|
deleteRemoteSourceHandler := api.NewDeleteRemoteSourceHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-05 12:36:14 +00:00
|
|
|
orgHandler := api.NewOrgHandler(logger, g.ah)
|
|
|
|
orgsHandler := api.NewOrgsHandler(logger, g.ah)
|
2019-05-03 21:48:49 +00:00
|
|
|
createOrgHandler := api.NewCreateOrgHandler(logger, g.ah)
|
2019-05-05 12:36:14 +00:00
|
|
|
deleteOrgHandler := api.NewDeleteOrgHandler(logger, g.ah)
|
2019-02-28 14:52:35 +00:00
|
|
|
|
2019-05-14 10:58:29 +00:00
|
|
|
orgMembersHandler := api.NewOrgMembersHandler(logger, g.ah)
|
2019-05-09 14:47:22 +00:00
|
|
|
addOrgMemberHandler := api.NewAddOrgMemberHandler(logger, g.ah)
|
2019-05-14 09:20:09 +00:00
|
|
|
removeOrgMemberHandler := api.NewRemoveOrgMemberHandler(logger, g.ah)
|
2019-05-09 14:47:22 +00:00
|
|
|
|
2019-05-05 22:00:45 +00:00
|
|
|
runHandler := api.NewRunHandler(logger, g.ah)
|
|
|
|
runsHandler := api.NewRunsHandler(logger, g.ah)
|
|
|
|
runtaskHandler := api.NewRuntaskHandler(logger, g.ah)
|
|
|
|
runActionsHandler := api.NewRunActionsHandler(logger, g.ah)
|
|
|
|
runTaskActionsHandler := api.NewRunTaskActionsHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-05 22:00:45 +00:00
|
|
|
logsHandler := api.NewLogsHandler(logger, g.ah)
|
2019-11-09 10:18:00 +00:00
|
|
|
logsDeleteHandler := api.NewLogsDeleteHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-03 21:48:49 +00:00
|
|
|
userRemoteReposHandler := api.NewUserRemoteReposHandler(logger, g.ah, g.configstoreClient)
|
2019-02-22 08:34:48 +00:00
|
|
|
|
2019-05-10 09:08:24 +00:00
|
|
|
badgeHandler := api.NewBadgeHandler(logger, g.ah)
|
|
|
|
|
2019-10-04 09:32:07 +00:00
|
|
|
versionHandler := api.NewVersionHandler(logger, g.ah)
|
|
|
|
|
2019-05-10 09:08:24 +00:00
|
|
|
reposHandler := api.NewReposHandler(logger, g.c.GitserverURL)
|
|
|
|
|
2019-05-03 21:48:49 +00:00
|
|
|
loginUserHandler := api.NewLoginUserHandler(logger, g.ah)
|
|
|
|
authorizeHandler := api.NewAuthorizeHandler(logger, g.ah)
|
|
|
|
registerHandler := api.NewRegisterUserHandler(logger, g.ah)
|
2019-05-05 12:45:19 +00:00
|
|
|
oauth2callbackHandler := api.NewOAuth2CallbackHandler(logger, g.ah)
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
router := mux.NewRouter()
|
2019-06-08 14:26:22 +00:00
|
|
|
reposRouter := mux.NewRouter()
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-03-14 13:36:18 +00:00
|
|
|
apirouter := mux.NewRouter().PathPrefix("/api/v1alpha").Subrouter().UseEncodedPath()
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
authForcedHandler := handlers.NewAuthHandler(logger, g.configstoreClient, g.c.AdminToken, g.sd, true)
|
|
|
|
authOptionalHandler := handlers.NewAuthHandler(logger, g.configstoreClient, g.c.AdminToken, g.sd, false)
|
|
|
|
|
|
|
|
router.PathPrefix("/api/v1alpha").Handler(apirouter)
|
|
|
|
|
2019-05-11 22:28:50 +00:00
|
|
|
apirouter.Handle("/logs", authOptionalHandler(logsHandler)).Methods("GET")
|
2019-11-09 10:18:00 +00:00
|
|
|
apirouter.Handle("/logs", authForcedHandler(logsDeleteHandler)).Methods("DELETE")
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-03-14 13:36:18 +00:00
|
|
|
//apirouter.Handle("/projectgroups", authForcedHandler(projectsHandler)).Methods("GET")
|
2019-04-08 07:04:55 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}", authForcedHandler(projectGroupHandler)).Methods("GET")
|
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/subgroups", authForcedHandler(projectGroupSubgroupsHandler)).Methods("GET")
|
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/projects", authForcedHandler(projectGroupProjectsHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/projectgroups", authForcedHandler(createProjectGroupHandler)).Methods("POST")
|
2019-05-14 15:53:48 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}", authForcedHandler(updateProjectGroupHandler)).Methods("PUT")
|
2019-05-12 22:24:16 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}", authForcedHandler(deleteProjectGroupHandler)).Methods("DELETE")
|
2019-03-14 13:36:18 +00:00
|
|
|
|
2019-07-12 21:41:34 +00:00
|
|
|
apirouter.Handle("/projects/{projectref}", authOptionalHandler(projectHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/projects", authForcedHandler(createProjectHandler)).Methods("POST")
|
2019-05-12 21:22:18 +00:00
|
|
|
apirouter.Handle("/projects/{projectref}", authForcedHandler(updateProjectHandler)).Methods("PUT")
|
2019-04-08 07:04:55 +00:00
|
|
|
apirouter.Handle("/projects/{projectref}", authForcedHandler(deleteProjectHandler)).Methods("DELETE")
|
|
|
|
apirouter.Handle("/projects/{projectref}/reconfig", authForcedHandler(projectReconfigHandler)).Methods("PUT")
|
2019-05-09 13:36:47 +00:00
|
|
|
apirouter.Handle("/projects/{projectref}/updaterepolinkedaccount", authForcedHandler(projectUpdateRepoLinkedAccountHandler)).Methods("PUT")
|
2019-10-22 07:47:11 +00:00
|
|
|
apirouter.Handle("/projects/{projectref}/createrun", authForcedHandler(projectCreateRunHandler)).Methods("POST")
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-03-14 13:36:18 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/secrets", authForcedHandler(secretHandler)).Methods("GET")
|
|
|
|
apirouter.Handle("/projects/{projectref}/secrets", authForcedHandler(secretHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/secrets", authForcedHandler(createSecretHandler)).Methods("POST")
|
|
|
|
apirouter.Handle("/projects/{projectref}/secrets", authForcedHandler(createSecretHandler)).Methods("POST")
|
2019-07-08 08:32:45 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/secrets/{secretname}", authForcedHandler(updateSecretHandler)).Methods("PUT")
|
|
|
|
apirouter.Handle("/projects/{projectref}/secrets/{secretname}", authForcedHandler(updateSecretHandler)).Methods("PUT")
|
2019-03-14 13:36:18 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/secrets/{secretname}", authForcedHandler(deleteSecretHandler)).Methods("DELETE")
|
|
|
|
apirouter.Handle("/projects/{projectref}/secrets/{secretname}", authForcedHandler(deleteSecretHandler)).Methods("DELETE")
|
|
|
|
|
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/variables", authForcedHandler(variableHandler)).Methods("GET")
|
|
|
|
apirouter.Handle("/projects/{projectref}/variables", authForcedHandler(variableHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/variables", authForcedHandler(createVariableHandler)).Methods("POST")
|
|
|
|
apirouter.Handle("/projects/{projectref}/variables", authForcedHandler(createVariableHandler)).Methods("POST")
|
2019-07-06 13:25:45 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/variables/{variablename}", authForcedHandler(updateVariableHandler)).Methods("PUT")
|
|
|
|
apirouter.Handle("/projects/{projectref}/variables/{variablename}", authForcedHandler(updateVariableHandler)).Methods("PUT")
|
2019-03-14 13:36:18 +00:00
|
|
|
apirouter.Handle("/projectgroups/{projectgroupref}/variables/{variablename}", authForcedHandler(deleteVariableHandler)).Methods("DELETE")
|
|
|
|
apirouter.Handle("/projects/{projectref}/variables/{variablename}", authForcedHandler(deleteVariableHandler)).Methods("DELETE")
|
|
|
|
|
2019-02-21 16:58:25 +00:00
|
|
|
apirouter.Handle("/user", authForcedHandler(currentUserHandler)).Methods("GET")
|
2019-05-03 09:07:53 +00:00
|
|
|
apirouter.Handle("/users/{userref}", authForcedHandler(userHandler)).Methods("GET")
|
2019-02-21 16:58:25 +00:00
|
|
|
apirouter.Handle("/users", authForcedHandler(usersHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/users", authForcedHandler(createUserHandler)).Methods("POST")
|
2019-05-03 09:07:53 +00:00
|
|
|
apirouter.Handle("/users/{userref}", authForcedHandler(deleteUserHandler)).Methods("DELETE")
|
2019-06-11 13:09:41 +00:00
|
|
|
apirouter.Handle("/user/createrun", authForcedHandler(userCreateRunHandler)).Methods("POST")
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
apirouter.Handle("/users/{userref}/linkedaccounts", authForcedHandler(createUserLAHandler)).Methods("POST")
|
|
|
|
apirouter.Handle("/users/{userref}/linkedaccounts/{laid}", authForcedHandler(deleteUserLAHandler)).Methods("DELETE")
|
|
|
|
apirouter.Handle("/users/{userref}/tokens", authForcedHandler(createUserTokenHandler)).Methods("POST")
|
|
|
|
apirouter.Handle("/users/{userref}/tokens/{tokenname}", authForcedHandler(deleteUserTokenHandler)).Methods("DELETE")
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(remoteSourceHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/remotesources", authForcedHandler(createRemoteSourceHandler)).Methods("POST")
|
2019-05-23 08:29:03 +00:00
|
|
|
apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(updateRemoteSourceHandler)).Methods("PUT")
|
2019-02-21 16:58:25 +00:00
|
|
|
apirouter.Handle("/remotesources", authOptionalHandler(remoteSourcesHandler)).Methods("GET")
|
2019-05-09 22:03:03 +00:00
|
|
|
apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(deleteRemoteSourceHandler)).Methods("DELETE")
|
2019-02-21 16:58:25 +00:00
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
apirouter.Handle("/orgs/{orgref}", authForcedHandler(orgHandler)).Methods("GET")
|
2019-02-28 14:52:35 +00:00
|
|
|
apirouter.Handle("/orgs", authForcedHandler(orgsHandler)).Methods("GET")
|
2019-04-08 06:54:45 +00:00
|
|
|
apirouter.Handle("/orgs", authForcedHandler(createOrgHandler)).Methods("POST")
|
2019-05-03 09:07:53 +00:00
|
|
|
apirouter.Handle("/orgs/{orgref}", authForcedHandler(deleteOrgHandler)).Methods("DELETE")
|
2019-05-14 10:58:29 +00:00
|
|
|
apirouter.Handle("/orgs/{orgref}/members", authForcedHandler(orgMembersHandler)).Methods("GET")
|
2019-05-09 14:47:22 +00:00
|
|
|
apirouter.Handle("/orgs/{orgref}/members/{userref}", authForcedHandler(addOrgMemberHandler)).Methods("PUT")
|
2019-05-14 09:20:09 +00:00
|
|
|
apirouter.Handle("/orgs/{orgref}/members/{userref}", authForcedHandler(removeOrgMemberHandler)).Methods("DELETE")
|
2019-02-28 14:52:35 +00:00
|
|
|
|
2019-07-01 14:40:02 +00:00
|
|
|
apirouter.Handle("/runs/{runid}", authOptionalHandler(runHandler)).Methods("GET")
|
2019-04-08 14:11:19 +00:00
|
|
|
apirouter.Handle("/runs/{runid}/actions", authForcedHandler(runActionsHandler)).Methods("PUT")
|
2019-07-01 14:40:02 +00:00
|
|
|
apirouter.Handle("/runs/{runid}/tasks/{taskid}", authOptionalHandler(runtaskHandler)).Methods("GET")
|
2019-05-06 13:19:29 +00:00
|
|
|
apirouter.Handle("/runs/{runid}/tasks/{taskid}/actions", authForcedHandler(runTaskActionsHandler)).Methods("PUT")
|
2019-02-21 16:58:25 +00:00
|
|
|
apirouter.Handle("/runs", authForcedHandler(runsHandler)).Methods("GET")
|
|
|
|
|
2019-05-10 09:08:24 +00:00
|
|
|
apirouter.Handle("/user/remoterepos/{remotesourceref}", authForcedHandler(userRemoteReposHandler)).Methods("GET")
|
|
|
|
|
|
|
|
apirouter.Handle("/badges/{projectref}", badgeHandler).Methods("GET")
|
|
|
|
|
2019-10-04 09:32:07 +00:00
|
|
|
apirouter.Handle("/version", versionHandler).Methods("GET")
|
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
// TODO(sgotti) add auth to these requests
|
2019-06-08 14:26:22 +00:00
|
|
|
reposRouter.Handle("/repos/{rest:.*}", reposHandler).Methods("GET", "POST")
|
2019-05-02 22:11:11 +00:00
|
|
|
|
2019-05-16 08:05:21 +00:00
|
|
|
router.Handle("/api/login", loginUserHandler).Methods("POST")
|
|
|
|
router.Handle("/api/authorize", authorizeHandler).Methods("POST")
|
|
|
|
router.Handle("/api/register", registerHandler).Methods("POST")
|
|
|
|
router.Handle("/api/oauth2/callback", oauth2callbackHandler).Methods("GET")
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
router.Handle("/webhooks", webhooksHandler).Methods("POST")
|
|
|
|
router.PathPrefix("/").HandlerFunc(handlers.NewWebBundleHandlerFunc(g.c.APIExposedURL))
|
|
|
|
|
2019-07-02 13:35:14 +00:00
|
|
|
maxBytesHandler := handlers.NewMaxBytesHandler(router, maxRequestSize)
|
2019-04-03 14:59:17 +00:00
|
|
|
|
2019-02-21 16:58:25 +00:00
|
|
|
mainrouter := mux.NewRouter()
|
2019-06-08 14:26:22 +00:00
|
|
|
mainrouter.PathPrefix("/repos/").Handler(corsHandler(reposRouter))
|
2019-04-03 14:59:17 +00:00
|
|
|
mainrouter.PathPrefix("/").Handler(corsHandler(maxBytesHandler))
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
var tlsConfig *tls.Config
|
|
|
|
if g.c.Web.TLS {
|
|
|
|
var err error
|
|
|
|
tlsConfig, err = util.NewTLSConfig(g.c.Web.TLSCertFile, g.c.Web.TLSKeyFile, "", false)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("err: %+v")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
httpServer := http.Server{
|
|
|
|
Addr: g.c.Web.ListenAddress,
|
|
|
|
Handler: mainrouter,
|
|
|
|
TLSConfig: tlsConfig,
|
|
|
|
}
|
|
|
|
|
|
|
|
lerrCh := make(chan error)
|
|
|
|
go func() {
|
|
|
|
lerrCh <- httpServer.ListenAndServe()
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
log.Infof("configstore exiting")
|
|
|
|
httpServer.Close()
|
|
|
|
case err := <-lerrCh:
|
2019-07-04 13:50:37 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("http server listen error: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
2019-07-04 13:50:37 +00:00
|
|
|
|
|
|
|
return nil
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|