Skip to content

Commit d6c81b8

Browse files
feat: Maintaining audit logs (#3763)
* Middleware * logger middleware service layer * updated files * commented code * updated files * updated files * updated files * pr comments * updated files * updated files * updated files * refactoring * removing spilled userAuth object * refactoring * updated files * refactoring functions names * wire gen * making middleware more efficient * adding status code in audit log middleware * log fix * refactoring * refactoring and few fixes * changed package + refactoring * argocd assets added * removed unnecessary code * EOF error fix * request payload place changed to be printed at last --------- Co-authored-by: Prakash Kumar <[email protected]>
1 parent 1b57820 commit d6c81b8

File tree

28 files changed

+129
-55
lines changed

28 files changed

+129
-55
lines changed

App.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"crypto/tls"
2323
"fmt"
24+
"github.com/devtron-labs/devtron/api/util"
2425
"github.com/devtron-labs/devtron/client/telemetry"
2526
"github.com/devtron-labs/devtron/otel"
2627
"log"
@@ -54,6 +55,7 @@ type App struct {
5455
serveTls bool
5556
sessionManager2 *authMiddleware.SessionManager
5657
OtelTracingService *otel.OtelTracingServiceImpl
58+
loggingMiddleware util.LoggingMiddleware
5759
}
5860

5961
func NewApp(router *router.MuxRouter,
@@ -64,6 +66,7 @@ func NewApp(router *router.MuxRouter,
6466
pubsubClient *pubsub.PubSubClientServiceImpl,
6567
sessionManager2 *authMiddleware.SessionManager,
6668
posthogClient *telemetry.PosthogClient,
69+
loggingMiddleware util.LoggingMiddleware,
6770
) *App {
6871
//check argo connection
6972
//todo - check argo-cd version on acd integration installation
@@ -78,6 +81,7 @@ func NewApp(router *router.MuxRouter,
7881
sessionManager2: sessionManager2,
7982
posthogClient: posthogClient,
8083
OtelTracingService: otel.NewOtelTracingServiceImpl(Logger),
84+
loggingMiddleware: loggingMiddleware,
8185
}
8286
return app
8387
}
@@ -94,7 +98,7 @@ func (app *App) Start() {
9498
//authEnforcer := casbin2.Create()
9599

96100
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager2, user.WhitelistChecker)(app.MuxRouter.Router)}
97-
101+
app.MuxRouter.Router.Use(app.loggingMiddleware.LoggingMiddleware)
98102
app.MuxRouter.Router.Use(middleware.PrometheusMiddleware)
99103
if tracerProvider != nil {
100104
app.MuxRouter.Router.Use(otelmux.Middleware(otel.OTEL_ORCHESTRASTOR_SERVICE_NAME))

Wire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"github.com/devtron-labs/devtron/api/team"
4848
"github.com/devtron-labs/devtron/api/terminal"
4949
"github.com/devtron-labs/devtron/api/user"
50+
util5 "github.com/devtron-labs/devtron/api/util"
5051
webhookHelm "github.com/devtron-labs/devtron/api/webhook/helm"
5152
"github.com/devtron-labs/devtron/client/argocdServer"
5253
"github.com/devtron-labs/devtron/client/argocdServer/application"
@@ -213,6 +214,8 @@ func InitializeApp() (*App, error) {
213214
pipeline.GetDeploymentServiceTypeConfig,
214215
pipeline.NewPipelineBuilderImpl,
215216
wire.Bind(new(pipeline.PipelineBuilder), new(*pipeline.PipelineBuilderImpl)),
217+
util5.NewLoggingMiddlewareImpl,
218+
wire.Bind(new(util5.LoggingMiddleware), new(*util5.LoggingMiddlewareImpl)),
216219
pipeline2.NewPipelineRestHandlerImpl,
217220
wire.Bind(new(pipeline2.PipelineConfigRestHandler), new(*pipeline2.PipelineConfigRestHandlerImpl)),
218221
router.NewPipelineRouterImpl,

api/appStore/deployment/AppStoreDeploymentRouter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func NewAppStoreDeploymentRouterImpl(appStoreDeploymentRestHandler AppStoreDeplo
3636
}
3737

3838
func (router AppStoreDeploymentRouterImpl) Init(configRouter *mux.Router) {
39-
4039
configRouter.Path("/application/install").
4140
HandlerFunc(router.appStoreDeploymentRestHandler.InstallApp).Methods("POST")
4241

api/dashboardEvent/DashboardTelemetryRouter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dashboardEvent
22

3-
import "github.com/gorilla/mux"
3+
import (
4+
"github.com/gorilla/mux"
5+
)
46

57
type DashboardTelemetryRouter interface {
68
Init(configRouter *mux.Router)

api/deployment/DeploymentConfigRouter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package deployment
22

3-
import "github.com/gorilla/mux"
3+
import (
4+
"github.com/gorilla/mux"
5+
)
46

57
type DeploymentConfigRouter interface {
68
Init(configRouter *mux.Router)

api/helm-app/HelmAppRouter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package client
22

3-
import "github.com/gorilla/mux"
3+
import (
4+
"github.com/gorilla/mux"
5+
)
46

57
type HelmAppRouter interface {
68
InitAppListRouter(helmRouter *mux.Router)

api/k8s/application/k8sApplicationRouter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func NewK8sApplicationRouterImpl(k8sApplicationRestHandler K8sApplicationRestHan
1919
}
2020

2121
func (impl *K8sApplicationRouterImpl) InitK8sApplicationRouter(k8sAppRouter *mux.Router) {
22-
2322
k8sAppRouter.Path("/resource/rotate").Queries("appId", "{appId}").
2423
HandlerFunc(impl.k8sApplicationRestHandler.RotatePod).Methods("POST")
2524

api/k8s/capacity/k8sCapacityRouter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func NewK8sCapacityRouterImpl(k8sCapacityRestHandler K8sCapacityRestHandler) *K8
1818
}
1919

2020
func (impl *K8sCapacityRouterImpl) InitK8sCapacityRouter(k8sCapacityRouter *mux.Router) {
21-
2221
k8sCapacityRouter.Path("/cluster/list/raw").
2322
HandlerFunc(impl.k8sCapacityRestHandler.GetClusterListRaw).Methods("GET")
2423

api/router/ApplicationRouter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func NewApplicationRouterImpl(handler restHandler.ArgoApplicationRestHandler, lo
4141
}
4242

4343
func (r ApplicationRouterImpl) initApplicationRouter(router *mux.Router) {
44-
4544
router.Path("/stream").
4645
Queries("name", "{name}").
4746
Methods("GET").

api/router/CommonRouter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func NewCommonRouterImpl(commonRestHandler restHandler.CommonRestHanlder) *Commo
3333
return &CommonRouterImpl{commonRestHandler: commonRestHandler}
3434
}
3535
func (impl CommonRouterImpl) InitCommonRouter(router *mux.Router) {
36-
3736
router.Path("/checklist").
3837
HandlerFunc(impl.commonRestHandler.GlobalChecklist).
3938
Methods("GET")

0 commit comments

Comments
 (0)