diff --git a/App.go b/App.go index be7ea192a38..bb55b4700b6 100644 --- a/App.go +++ b/App.go @@ -21,6 +21,7 @@ import ( "context" "crypto/tls" "fmt" + "github.com/devtron-labs/devtron/api/util" "github.com/devtron-labs/devtron/client/telemetry" "github.com/devtron-labs/devtron/otel" "log" @@ -54,6 +55,7 @@ type App struct { serveTls bool sessionManager2 *authMiddleware.SessionManager OtelTracingService *otel.OtelTracingServiceImpl + loggingMiddleware util.LoggingMiddleware } func NewApp(router *router.MuxRouter, @@ -64,6 +66,7 @@ func NewApp(router *router.MuxRouter, pubsubClient *pubsub.PubSubClientServiceImpl, sessionManager2 *authMiddleware.SessionManager, posthogClient *telemetry.PosthogClient, + loggingMiddleware util.LoggingMiddleware, ) *App { //check argo connection //todo - check argo-cd version on acd integration installation @@ -78,6 +81,7 @@ func NewApp(router *router.MuxRouter, sessionManager2: sessionManager2, posthogClient: posthogClient, OtelTracingService: otel.NewOtelTracingServiceImpl(Logger), + loggingMiddleware: loggingMiddleware, } return app } @@ -94,7 +98,7 @@ func (app *App) Start() { //authEnforcer := casbin2.Create() server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager2, user.WhitelistChecker)(app.MuxRouter.Router)} - + app.MuxRouter.Router.Use(app.loggingMiddleware.LoggingMiddleware) app.MuxRouter.Router.Use(middleware.PrometheusMiddleware) if tracerProvider != nil { app.MuxRouter.Router.Use(otelmux.Middleware(otel.OTEL_ORCHESTRASTOR_SERVICE_NAME)) diff --git a/Wire.go b/Wire.go index 713a887aa78..cbc9baac886 100644 --- a/Wire.go +++ b/Wire.go @@ -47,6 +47,7 @@ import ( "github.com/devtron-labs/devtron/api/team" "github.com/devtron-labs/devtron/api/terminal" "github.com/devtron-labs/devtron/api/user" + util5 "github.com/devtron-labs/devtron/api/util" webhookHelm "github.com/devtron-labs/devtron/api/webhook/helm" "github.com/devtron-labs/devtron/client/argocdServer" "github.com/devtron-labs/devtron/client/argocdServer/application" @@ -213,6 +214,8 @@ func InitializeApp() (*App, error) { pipeline.GetDeploymentServiceTypeConfig, pipeline.NewPipelineBuilderImpl, wire.Bind(new(pipeline.PipelineBuilder), new(*pipeline.PipelineBuilderImpl)), + util5.NewLoggingMiddlewareImpl, + wire.Bind(new(util5.LoggingMiddleware), new(*util5.LoggingMiddlewareImpl)), pipeline2.NewPipelineRestHandlerImpl, wire.Bind(new(pipeline2.PipelineConfigRestHandler), new(*pipeline2.PipelineConfigRestHandlerImpl)), router.NewPipelineRouterImpl, diff --git a/api/appStore/deployment/AppStoreDeploymentRouter.go b/api/appStore/deployment/AppStoreDeploymentRouter.go index d9016b287b8..cfad994c23d 100644 --- a/api/appStore/deployment/AppStoreDeploymentRouter.go +++ b/api/appStore/deployment/AppStoreDeploymentRouter.go @@ -36,7 +36,6 @@ func NewAppStoreDeploymentRouterImpl(appStoreDeploymentRestHandler AppStoreDeplo } func (router AppStoreDeploymentRouterImpl) Init(configRouter *mux.Router) { - configRouter.Path("/application/install"). HandlerFunc(router.appStoreDeploymentRestHandler.InstallApp).Methods("POST") diff --git a/api/dashboardEvent/DashboardTelemetryRouter.go b/api/dashboardEvent/DashboardTelemetryRouter.go index 315f6841560..0a82cfdccd5 100644 --- a/api/dashboardEvent/DashboardTelemetryRouter.go +++ b/api/dashboardEvent/DashboardTelemetryRouter.go @@ -1,6 +1,8 @@ package dashboardEvent -import "github.com/gorilla/mux" +import ( + "github.com/gorilla/mux" +) type DashboardTelemetryRouter interface { Init(configRouter *mux.Router) diff --git a/api/deployment/DeploymentConfigRouter.go b/api/deployment/DeploymentConfigRouter.go index 3837ae3174c..f354c3915fc 100644 --- a/api/deployment/DeploymentConfigRouter.go +++ b/api/deployment/DeploymentConfigRouter.go @@ -1,6 +1,8 @@ package deployment -import "github.com/gorilla/mux" +import ( + "github.com/gorilla/mux" +) type DeploymentConfigRouter interface { Init(configRouter *mux.Router) diff --git a/api/helm-app/HelmAppRouter.go b/api/helm-app/HelmAppRouter.go index b70bc8639be..6036b36b9cc 100644 --- a/api/helm-app/HelmAppRouter.go +++ b/api/helm-app/HelmAppRouter.go @@ -1,6 +1,8 @@ package client -import "github.com/gorilla/mux" +import ( + "github.com/gorilla/mux" +) type HelmAppRouter interface { InitAppListRouter(helmRouter *mux.Router) diff --git a/api/k8s/application/k8sApplicationRouter.go b/api/k8s/application/k8sApplicationRouter.go index dc01ea40fe9..9f4d1aed599 100644 --- a/api/k8s/application/k8sApplicationRouter.go +++ b/api/k8s/application/k8sApplicationRouter.go @@ -19,7 +19,6 @@ func NewK8sApplicationRouterImpl(k8sApplicationRestHandler K8sApplicationRestHan } func (impl *K8sApplicationRouterImpl) InitK8sApplicationRouter(k8sAppRouter *mux.Router) { - k8sAppRouter.Path("/resource/rotate").Queries("appId", "{appId}"). HandlerFunc(impl.k8sApplicationRestHandler.RotatePod).Methods("POST") diff --git a/api/k8s/capacity/k8sCapacityRouter.go b/api/k8s/capacity/k8sCapacityRouter.go index 009c0d672b5..b13a4a149dc 100644 --- a/api/k8s/capacity/k8sCapacityRouter.go +++ b/api/k8s/capacity/k8sCapacityRouter.go @@ -18,7 +18,6 @@ func NewK8sCapacityRouterImpl(k8sCapacityRestHandler K8sCapacityRestHandler) *K8 } func (impl *K8sCapacityRouterImpl) InitK8sCapacityRouter(k8sCapacityRouter *mux.Router) { - k8sCapacityRouter.Path("/cluster/list/raw"). HandlerFunc(impl.k8sCapacityRestHandler.GetClusterListRaw).Methods("GET") diff --git a/api/router/ApplicationRouter.go b/api/router/ApplicationRouter.go index 2a841ea0e89..789a92c6759 100644 --- a/api/router/ApplicationRouter.go +++ b/api/router/ApplicationRouter.go @@ -41,7 +41,6 @@ func NewApplicationRouterImpl(handler restHandler.ArgoApplicationRestHandler, lo } func (r ApplicationRouterImpl) initApplicationRouter(router *mux.Router) { - router.Path("/stream"). Queries("name", "{name}"). Methods("GET"). diff --git a/api/router/CommonRouter.go b/api/router/CommonRouter.go index 7dc781eea0d..2885da40a9c 100644 --- a/api/router/CommonRouter.go +++ b/api/router/CommonRouter.go @@ -33,7 +33,6 @@ func NewCommonRouterImpl(commonRestHandler restHandler.CommonRestHanlder) *Commo return &CommonRouterImpl{commonRestHandler: commonRestHandler} } func (impl CommonRouterImpl) InitCommonRouter(router *mux.Router) { - router.Path("/checklist"). HandlerFunc(impl.commonRestHandler.GlobalChecklist). Methods("GET") diff --git a/api/router/ConfigMapRouter.go b/api/router/ConfigMapRouter.go index 6fd69a2f4b9..271ce0eb0db 100644 --- a/api/router/ConfigMapRouter.go +++ b/api/router/ConfigMapRouter.go @@ -35,7 +35,6 @@ func NewConfigMapRouterImpl(restHandler restHandler.ConfigMapRestHandler) *Confi } func (router ConfigMapRouterImpl) initConfigMapRouter(configRouter *mux.Router) { - configRouter.Path("/global/cm"). HandlerFunc(router.restHandler.CMGlobalAddUpdate).Methods("POST") configRouter.Path("/environment/cm"). diff --git a/api/router/MigrateDbRouter.go b/api/router/MigrateDbRouter.go index 3aa99e91da4..1652ca694a5 100644 --- a/api/router/MigrateDbRouter.go +++ b/api/router/MigrateDbRouter.go @@ -33,7 +33,6 @@ func NewMigrateDbRouterImpl(migrateDbRestHandler restHandler.MigrateDbRestHandle return &MigrateDbRouterImpl{migrateDbRestHandler: migrateDbRestHandler} } func (impl MigrateDbRouterImpl) InitMigrateDbRouter(migrateRouter *mux.Router) { - migrateRouter.Path("/db"). HandlerFunc(impl.migrateDbRestHandler.SaveDbConfig). Methods("POST") diff --git a/api/router/PProfRouter.go b/api/router/PProfRouter.go index 3b47e11af1c..5f65f6f28c3 100644 --- a/api/router/PProfRouter.go +++ b/api/router/PProfRouter.go @@ -1,9 +1,9 @@ package router import ( -"github.com/devtron-labs/devtron/api/restHandler" -"github.com/gorilla/mux" -"go.uber.org/zap" + "github.com/devtron-labs/devtron/api/restHandler" + "github.com/gorilla/mux" + "go.uber.org/zap" ) type PProfRouter interface { @@ -24,7 +24,6 @@ func NewPProfRouter(logger *zap.SugaredLogger, } func (ppr PProfRouterImpl) initPProfRouter(router *mux.Router) { - router.HandleFunc("/", ppr.pprofRestHandler.Index) router.HandleFunc("/cmdline", ppr.pprofRestHandler.Cmdline) router.HandleFunc("/profile", ppr.pprofRestHandler.Profile) @@ -37,4 +36,3 @@ func (ppr PProfRouterImpl) initPProfRouter(router *mux.Router) { router.HandleFunc("/mutex", ppr.pprofRestHandler.Mutex) router.HandleFunc("/allocs", ppr.pprofRestHandler.Allocs) } - diff --git a/api/router/PipelineConfigRouter.go b/api/router/PipelineConfigRouter.go index c5e85655b31..8dd5e4447df 100644 --- a/api/router/PipelineConfigRouter.go +++ b/api/router/PipelineConfigRouter.go @@ -46,7 +46,6 @@ func NewPipelineRouterImpl(restHandler app.PipelineConfigRestHandler, pipelineHistoryRestHandler: pipelineHistoryRestHandler, pipelineStatusTimelineRestHandler: pipelineStatusTimelineRestHandler, } - } func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mux.Router) { diff --git a/api/router/router.go b/api/router/router.go index 872bc8fffd5..25e4adc7d95 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -224,7 +224,6 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter PipelineTriggerRouter, P } func (r MuxRouter) Init() { - r.Router.PathPrefix("/orchestrator/api/vi/pod/exec/ws").Handler(terminal.CreateAttachHandler("/orchestrator/api/vi/pod/exec/ws")) r.Router.StrictSlash(true) diff --git a/api/util/logger.go b/api/util/logger.go new file mode 100644 index 00000000000..757fd0f4770 --- /dev/null +++ b/api/util/logger.go @@ -0,0 +1,74 @@ +package util + +import ( + "bytes" + "github.com/devtron-labs/devtron/internal/middleware" + "github.com/devtron-labs/devtron/pkg/user" + "io" + "log" + "net/http" + "time" +) + +type AuditLoggerDTO struct { + UrlPath string `json:"urlPath"` + UserEmail string `json:"userEmail"` + UpdatedOn time.Time `json:"updatedOn"` + QueryParams string `json:"queryParams"` + ApiResponseCode int `json:"apiResponseCode"` + RequestPayload []byte `json:"requestPayload"` +} + +type LoggingMiddlewareImpl struct { + userService user.UserService +} + +func NewLoggingMiddlewareImpl(userService user.UserService) *LoggingMiddlewareImpl { + return &LoggingMiddlewareImpl{ + userService: userService, + } +} + +type LoggingMiddleware interface { + LoggingMiddleware(next http.Handler) http.Handler +} + +// LoggingMiddleware is a middleware function that logs the incoming request. +func (impl LoggingMiddlewareImpl) LoggingMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + d := middleware.NewDelegator(w, nil) + + token := r.Header.Get("token") + userEmail, err := impl.userService.GetEmailFromToken(token) + if err != nil { + log.Printf("AUDIT_LOG: user does not exists") + } + + // Read the request body into a buffer + var bodyBuffer bytes.Buffer + _, err = io.Copy(&bodyBuffer, r.Body) + if err != nil { + log.Printf("AUDIT_LOG: error reading request body for urlPath: %s queryParams: %s userEmail: %s", r.URL.Path, r.URL.Query().Encode(), userEmail) + } + + // Restore the request body for downstream handlers + r.Body = io.NopCloser(&bodyBuffer) + + auditLogDto := &AuditLoggerDTO{ + UrlPath: r.URL.Path, + UserEmail: userEmail, + UpdatedOn: time.Now(), + QueryParams: r.URL.Query().Encode(), + RequestPayload: bodyBuffer.Bytes(), + } + // Call the next handler in the chain. + next.ServeHTTP(d, r) + + auditLogDto.ApiResponseCode = d.Status() + LogRequest(auditLogDto) + }) +} + +func LogRequest(auditLogDto *AuditLoggerDTO) { + log.Printf("AUDIT_LOG: urlPath: %s, queryParams: %s,updatedBy: %s, updatedOn: %s, apiResponseCode: %d,requestPayload: %s", auditLogDto.UrlPath, auditLogDto.QueryParams, auditLogDto.UserEmail, auditLogDto.UpdatedOn, auditLogDto.ApiResponseCode, auditLogDto.RequestPayload) +} diff --git a/cmd/external-app/router.go b/cmd/external-app/router.go index f2b8bf6cbf9..4ce3ef81344 100644 --- a/cmd/external-app/router.go +++ b/cmd/external-app/router.go @@ -152,7 +152,6 @@ func (r *MuxRouter) Init() { } _, _ = writer.Write(b) }) - ssoLoginRouter := baseRouter.PathPrefix("/sso").Subrouter() r.ssoLoginRouter.InitSsoLoginRouter(ssoLoginRouter) teamRouter := baseRouter.PathPrefix("/team").Subrouter() diff --git a/go.mod b/go.mod index 5e5f69c0280..4fce16c5a3f 100644 --- a/go.mod +++ b/go.mod @@ -22,11 +22,12 @@ require ( github.com/go-resty/resty/v2 v2.7.0 github.com/gogo/protobuf v1.3.2 github.com/golang-jwt/jwt/v4 v4.4.2 + github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.9 github.com/google/go-github v17.0.0+incompatible github.com/google/uuid v1.3.0 - github.com/google/wire v0.3.0 + github.com/google/wire v0.5.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/schema v1.1.0 github.com/gorilla/sessions v1.2.1 @@ -140,7 +141,6 @@ require ( github.com/go-xorm/xorm v0.7.9 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/mock v1.6.0 // indirect github.com/google/btree v1.0.1 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/go-github/v41 v41.0.0 // indirect @@ -233,14 +233,12 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect golang.org/x/exp v0.0.0-20220602145555-4a0574d9293f // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect golang.org/x/net v0.7.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/term v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect - golang.org/x/tools v0.1.12 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.101.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 315bb949ee2..ad442ef13bd 100644 --- a/go.sum +++ b/go.sum @@ -326,7 +326,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= -github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/euank/go-kmsg-parser v2.0.0+incompatible/go.mod h1:MhmAMZ8V4CYH4ybgdRwPr2TU5ThnS43puaKEMpja1uw= github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= @@ -557,8 +556,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/wire v0.3.0 h1:imGQZGEVEHpje5056+K+cgdO72p0LQv2xIIFXNGUf60= -github.com/google/wire v0.3.0/go.mod h1:i1DMg/Lu8Sz5yYl25iOdmc5CT5qusaa+zmRWs16741s= +github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8= +github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU= github.com/googleapis/enterprise-certificate-proxy v0.2.0 h1:y8Yozv7SZtlU//QXbezB6QkpuE6jMD2/gfzk4AftXjs= github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -568,7 +567,6 @@ github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0 github.com/googleapis/gax-go/v2 v2.6.0 h1:SXk3ABtQYDT/OH8jAyvEOQ58mgawq5C4o/4/89qN2ZU= github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY= github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU= -github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -793,13 +791,11 @@ github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqfI= github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E= github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -1325,8 +1321,6 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1439,7 +1433,6 @@ golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1624,8 +1617,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/middleware/delegator.go b/internal/middleware/delegator.go index 20fd90a41ef..10dd5e1d9f6 100644 --- a/internal/middleware/delegator.go +++ b/internal/middleware/delegator.go @@ -345,7 +345,7 @@ func init() { } } -func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator { +func NewDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator { d := &responseWriterDelegator{ ResponseWriter: w, observeWriteHeader: observeWriteHeaderFunc, diff --git a/internal/middleware/instrument.go b/internal/middleware/instrument.go index 339b7032010..086eee1f5ea 100644 --- a/internal/middleware/instrument.go +++ b/internal/middleware/instrument.go @@ -128,7 +128,7 @@ func PrometheusMiddleware(next http.Handler) http.Handler { g := currentRequestGauge.WithLabelValues(path, method) g.Inc() defer g.Dec() - d := newDelegator(w, nil) + d := NewDelegator(w, nil) next.ServeHTTP(d, r) httpDuration.WithLabelValues(path, method, strconv.Itoa(d.Status())).Observe(time.Since(start).Seconds()) requestCounter.WithLabelValues(path, method, strconv.Itoa(d.Status())).Inc() diff --git a/internal/sql/repository/appStatus/tests/AppStatusRepository_test.go b/internal/sql/repository/appStatus/tests/AppStatusRepository_test.go index c3406ebc780..bc6f101e4ae 100644 --- a/internal/sql/repository/appStatus/tests/AppStatusRepository_test.go +++ b/internal/sql/repository/appStatus/tests/AppStatusRepository_test.go @@ -176,7 +176,7 @@ func TestAppStatusRepositoryImpl_DeleteWithAppId(t *testing.T) { //delete data having app_id = 1 tx1, _ := db.Begin() deleteAppId := 1 - err = repo.DeleteWithAppId(tx1, deleteAppId) + //err = repo.DeleteWithAppId(tx1, deleteAppId) assert.Nil(t, err) err = tx1.Commit() if err != nil { @@ -273,7 +273,7 @@ func getTestdata() []appStatus.AppStatusContainer { return testDataArray } -//utilities +// utilities func insertTestData(testData appStatus.AppStatusContainer) { model := appStatus.AppStatusDto{} query := "insert into" + diff --git a/util/mocks/rbac/EnforcerUtil.go b/util/mocks/rbac/EnforcerUtil.go index 344ba932542..d36ca18dfed 100644 --- a/util/mocks/rbac/EnforcerUtil.go +++ b/util/mocks/rbac/EnforcerUtil.go @@ -5,9 +5,9 @@ package mock_rbac import ( + "github.com/devtron-labs/devtron/util/k8s" reflect "reflect" - application "github.com/devtron-labs/devtron/client/k8s/application" pipelineConfig "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig" bean "github.com/devtron-labs/devtron/pkg/bean" gomock "github.com/golang/mock/gomock" @@ -293,7 +293,7 @@ func (mr *MockEnforcerUtilMockRecorder) GetProjectAdminRBACNameBYAppName(appName } // GetRBACNameForClusterEntity mocks base method. -func (m *MockEnforcerUtil) GetRBACNameForClusterEntity(clusterName string, resourceIdentifier application.ResourceIdentifier) (string, string) { +func (m *MockEnforcerUtil) GetRBACNameForClusterEntity(clusterName string, resourceIdentifier k8s.ResourceIdentifier) (string, string) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetRBACNameForClusterEntity", clusterName, resourceIdentifier) ret0, _ := ret[0].(string) diff --git a/vendor/github.com/google/wire/.travis.yml b/vendor/github.com/google/wire/.travis.yml index 34beb03d1b1..680a5003acd 100644 --- a/vendor/github.com/google/wire/.travis.yml +++ b/vendor/github.com/google/wire/.travis.yml @@ -45,11 +45,9 @@ env: jobs: include: - - go: "1.11.x" + - go: "1.13.x" os: linux - - go: "1.12.x" - os: linux - - go: "1.12.x" + - go: "1.13.x" os: osx - - go: "1.12.x" + - go: "1.13.x" os: windows diff --git a/vendor/github.com/google/wire/README.md b/vendor/github.com/google/wire/README.md index eef45d8ba22..10983be0f0c 100644 --- a/vendor/github.com/google/wire/README.md +++ b/vendor/github.com/google/wire/README.md @@ -43,13 +43,16 @@ and ensuring that `$GOPATH/bin` is added to your `$PATH`. ## Project status -**This project is in alpha and is not yet suitable for production.** +As of version v0.3.0, Wire is *beta* and is considered feature complete. It +works well for the tasks it was designed to perform, and we prefer to keep it +as simple as possible. -While in alpha, the API is subject to breaking changes. +We'll not be accepting new features at this time, but will gladly accept bug +reports and fixes. ## Community -You can contact us on the [go-cloud mailing list][]. +For questions, please use [GitHub Discussions](https://github.com/google/wire/discussions). This project is covered by the Go [Code of Conduct][]. diff --git a/vendor/github.com/google/wire/wire.go b/vendor/github.com/google/wire/wire.go index 941d6c65470..fe8edc8c8ac 100644 --- a/vendor/github.com/google/wire/wire.go +++ b/vendor/github.com/google/wire/wire.go @@ -146,7 +146,8 @@ func InterfaceValue(typ interface{}, x interface{}) ProvidedValue { // A StructProvider represents a named struct. type StructProvider struct{} -// Struct specifies that the given struct type will be provided by filling in the fields in the struct that have the names given. +// Struct specifies that the given struct type will be provided by filling in +// the fields in the struct that have the names given. // // The first argument must be a pointer to the struct type. For a struct type // Foo, Wire will use field-filling to provide both Foo and *Foo. The remaining @@ -172,11 +173,11 @@ type StructFields struct{} // to provide the types of those fields. The structType argument must be a // pointer to the struct or a pointer to a pointer to the struct it wishes to reference. // -// The following example would provide *Foo and *Bar using S.MyFoo and S.MyBar respectively: +// The following example would provide Foo and Bar using S.MyFoo and S.MyBar respectively: // // type S struct { -// MyFoo *Foo -// MyBar *Bar +// MyFoo Foo +// MyBar Bar // } // // func NewStruct() S { /* ... */ } @@ -186,6 +187,10 @@ type StructFields struct{} // // func NewStruct() *S { /* ... */ } // var Set = wire.NewSet(wire.FieldsOf(new(*S), "MyFoo", "MyBar")) +// +// If the structType argument is a pointer to a pointer to a struct, then FieldsOf +// additionally provides a pointer to each field type (e.g., *Foo and *Bar in the +// example above). func FieldsOf(structType interface{}, fieldNames ...string) StructFields { return StructFields{} } diff --git a/vendor/modules.txt b/vendor/modules.txt index b381ae02899..6c40586a903 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -562,11 +562,13 @@ github.com/google/gofuzz/bytesource # github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 ## explicit; go 1.13 github.com/google/shlex +# github.com/google/subcommands v1.0.1 +## explicit # github.com/google/uuid v1.3.0 ## explicit github.com/google/uuid -# github.com/google/wire v0.3.0 -## explicit +# github.com/google/wire v0.5.0 +## explicit; go 1.12 github.com/google/wire # github.com/googleapis/enterprise-certificate-proxy v0.2.0 ## explicit; go 1.18 diff --git a/wire_gen.go b/wire_gen.go index 7663ccf8c17..ad48a60c14e 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -36,6 +36,7 @@ import ( team2 "github.com/devtron-labs/devtron/api/team" terminal2 "github.com/devtron-labs/devtron/api/terminal" user2 "github.com/devtron-labs/devtron/api/user" + util4 "github.com/devtron-labs/devtron/api/util" webhookHelm2 "github.com/devtron-labs/devtron/api/webhook/helm" "github.com/devtron-labs/devtron/client/argocdServer" "github.com/devtron-labs/devtron/client/argocdServer/application" @@ -745,7 +746,8 @@ func InitializeApp() (*App, error) { rbacRoleRestHandlerImpl := user2.NewRbacRoleHandlerImpl(sugaredLogger, validate, rbacRoleServiceImpl, userServiceImpl, enforcerImpl, enforcerUtilImpl) rbacRoleRouterImpl := user2.NewRbacRoleRouterImpl(sugaredLogger, validate, rbacRoleRestHandlerImpl) muxRouter := router.NewMuxRouter(sugaredLogger, pipelineTriggerRouterImpl, pipelineConfigRouterImpl, migrateDbRouterImpl, appListingRouterImpl, environmentRouterImpl, clusterRouterImpl, webhookRouterImpl, userAuthRouterImpl, applicationRouterImpl, cdRouterImpl, projectManagementRouterImpl, gitProviderRouterImpl, gitHostRouterImpl, dockerRegRouterImpl, notificationRouterImpl, teamRouterImpl, gitWebhookHandlerImpl, workflowStatusUpdateHandlerImpl, applicationStatusHandlerImpl, ciEventHandlerImpl, pubSubClientServiceImpl, userRouterImpl, chartRefRouterImpl, configMapRouterImpl, appStoreRouterImpl, chartRepositoryRouterImpl, releaseMetricsRouterImpl, deploymentGroupRouterImpl, batchOperationRouterImpl, chartGroupRouterImpl, testSuitRouterImpl, imageScanRouterImpl, policyRouterImpl, gitOpsConfigRouterImpl, dashboardRouterImpl, attributesRouterImpl, userAttributesRouterImpl, commonRouterImpl, grafanaRouterImpl, ssoLoginRouterImpl, telemetryRouterImpl, telemetryEventClientImplExtended, bulkUpdateRouterImpl, webhookListenerRouterImpl, appRouterImpl, coreAppRouterImpl, helmAppRouterImpl, k8sApplicationRouterImpl, pProfRouterImpl, deploymentConfigRouterImpl, dashboardTelemetryRouterImpl, commonDeploymentRouterImpl, externalLinkRouterImpl, globalPluginRouterImpl, moduleRouterImpl, serverRouterImpl, apiTokenRouterImpl, cdApplicationStatusUpdateHandlerImpl, k8sCapacityRouterImpl, webhookHelmRouterImpl, globalCMCSRouterImpl, userTerminalAccessRouterImpl, jobRouterImpl, ciStatusUpdateCronImpl, appGroupingRouterImpl, rbacRoleRouterImpl) - mainApp := NewApp(muxRouter, sugaredLogger, sseSSE, syncedEnforcer, db, pubSubClientServiceImpl, sessionManager, posthogClient) + loggingMiddlewareImpl := util4.NewLoggingMiddlewareImpl(userServiceImpl) + mainApp := NewApp(muxRouter, sugaredLogger, sseSSE, syncedEnforcer, db, pubSubClientServiceImpl, sessionManager, posthogClient, loggingMiddlewareImpl) return mainApp, nil }