-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #451 Log api calls for audit and config apis
- Loading branch information
1 parent
81f7691
commit 64e9606
Showing
2 changed files
with
74 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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,28 @@ | ||
package middleware | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/bb-consent/api/internal/actionlog" | ||
"github.com/bb-consent/api/internal/config" | ||
"github.com/bb-consent/api/internal/token" | ||
) | ||
|
||
// LogApiCalls Logs API(s). | ||
func LogApiCalls() Middleware { | ||
// Create a new Middleware | ||
return func(f http.HandlerFunc) http.HandlerFunc { | ||
|
||
// Define the http.HandlerFunc | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
|
||
organisationId := r.Header.Get(config.OrganizationId) | ||
aLog := fmt.Sprintf("Organization API: %v called by user: %v", r.URL.Path, token.GetUserName(r)) | ||
actionlog.LogOrgAPICalls(token.GetUserID(r), token.GetUserName(r), organisationId, aLog) | ||
|
||
// Call the next middleware/handler in chain | ||
f(w, r) | ||
} | ||
} | ||
} |