-
Notifications
You must be signed in to change notification settings - Fork 553
feat: Maintaining audit logs #3763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7208a86
Middleware
dhananjay0601 7b9ef87
logger middleware service layer
dhananjay0601 394cd30
updated files
dhananjay0601 a3780fd
updated files
dhananjay0601 f618c2b
Merge branch 'main' into maintaining_audit_logs
dhananjay0601 3f86b00
updated files
dhananjay0601 6c30b20
commented code
dhananjay0601 9e2bf7e
updated files
dhananjay0601 5ed5b44
updated files
dhananjay0601 b9ee3f0
updated files
dhananjay0601 02baca9
pr comments
dhananjay0601 9790c15
updated files
dhananjay0601 43bd5be
Merge branch 'main' into maintaining_audit_logs
dhananjay0601 9573c5b
updated files
dhananjay0601 38ebea6
updated files
dhananjay0601 f002a8a
Merge branch 'main' into maintaining_audit_logs
prakash100198 b056a07
refactoring
prakash100198 2fc08ed
Merge branch 'main' into maintaining_audit_logs
dhananjay0601 a66126f
removing spilled userAuth object
prakash100198 4c9a92b
refactoring
prakash100198 d6f867d
updated files
dhananjay0601 253a480
refactoring functions names
prakash100198 5086f59
wire gen
prakash100198 f74a95d
Merge branch 'main' of https://github.com/devtron-labs/devtron into m…
dhananjay0601 12dbf6e
updated files
dhananjay0601 ef8de76
making middleware more efficient
prakash100198 3ed292f
Merge branch 'main' into maintaining_audit_logs
prakash100198 03e065f
adding status code in audit log middleware
prakash100198 78f3459
log fix
prakash100198 8317683
refactoring
prakash100198 ca78520
refactoring and few fixes
prakash100198 24907e5
changed package + refactoring
prakash100198 879acc0
argocd assets added
prakash100198 44ed17d
removed unnecessary code
prakash100198 7d5fe5b
Merge branch 'main' into maintaining_audit_logs
prakash100198 c7473c2
EOF error fix
prakash100198 27ad4e0
Merge branch 'main' into maintaining_audit_logs
prakash100198 b3a910e
request payload place changed to be printed at last
prakash100198 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package logger | ||
|
|
||
| import "time" | ||
|
|
||
| type AuditLoggerDTO struct { | ||
| UrlPath string `json:"urlPath"` | ||
| UserID int `json:"userID"` | ||
| UpdatedOn time.Time `json:"updatedOn"` | ||
| QueryParams string `json:"queryParams"` | ||
| ApiResponseCode int `json:"apiResponseCode"` | ||
| RequestPayload string `json:"requestPayload"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package logger | ||
|
|
||
| import ( | ||
| "github.com/devtron-labs/devtron/pkg/user" | ||
| "io/ioutil" | ||
| "log" | ||
| "net/http" | ||
| "time" | ||
| ) | ||
|
|
||
| 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 { | ||
prakash100198 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
| startTime := time.Now() | ||
|
|
||
| // Call the next handler in the chain. | ||
| next.ServeHTTP(w, r) | ||
|
|
||
| //Log the request details. | ||
| url := r.URL.Path | ||
|
|
||
| token := r.Header.Get("token") | ||
| userId, userType, err := impl.userService.GetUserByToken(r.Context(), token) | ||
prakash100198 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| log.Printf("userId does not exists") | ||
| } | ||
| vars := r.URL.Query().Encode() | ||
| body, err := ioutil.ReadAll(r.Body) | ||
| if err != nil { | ||
| log.Printf("error reading request body") | ||
prakash100198 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| // Convert the request body to a string | ||
| requestPayload := string(body) | ||
prakash100198 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log.Printf(userType) | ||
| auditLogDto := &AuditLoggerDTO{ | ||
| UrlPath: url, | ||
| UserID: int(userId), | ||
| UpdatedOn: startTime, | ||
| QueryParams: vars, | ||
| RequestPayload: requestPayload, | ||
| } | ||
| LogRequest(auditLogDto) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package logger | ||
|
|
||
| import ( | ||
| "log" | ||
| ) | ||
|
|
||
| func LogRequest(auditLogDto *AuditLoggerDTO) { | ||
| log.Printf("urlPath: %s, queryParams: %s, requestPayload: %s,updatedBy: %d, updatedOn: %s, apiResponseCode: %d", auditLogDto.UrlPath, auditLogDto.QueryParams, auditLogDto.RequestPayload, auditLogDto.UserID, auditLogDto.UpdatedOn, auditLogDto.ApiResponseCode) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.