add client IP to audit logs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-19 10:56:37 +11:00
parent 317e0ab83d
commit 8799f0f796
6 changed files with 32 additions and 12 deletions

View File

@@ -80,9 +80,10 @@ func DeleteUser(c *gin.Context) {
// Create audit record
a := models.Audit{
UserId: RequestingUserId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Deleted User Id %d", testUser.UserId),
}
a.AutidLogAdd()
a.AuditLogAdd()
c.JSON(http.StatusOK, gin.H{"message": "user deletion success"})
}
@@ -181,9 +182,10 @@ func AddUser(c *gin.Context) {
// Create audit record
a := models.Audit{
UserId: RequestingUserId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Created User Id %d", u.UserId),
}
a.AutidLogAdd()
a.AuditLogAdd()
c.JSON(http.StatusOK, gin.H{"message": "user registration success", "data": u})
}

View File

@@ -163,9 +163,10 @@ func retrieveSpecifiedSecret(s *models.Secret, c *gin.Context) {
a := models.Audit{
UserId: UserId,
SecretId: results[0].SecretId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Retrieved Secret Id %d", results[0].SecretId),
}
a.AutidLogAdd()
a.AuditLogAdd()
// output results as json
c.JSON(http.StatusOK, gin.H{"message": "success", "data": results})
@@ -209,9 +210,10 @@ func ListSecrets(c *gin.Context) {
// Create audit record
a := models.Audit{
UserId: UserId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Listed %d secrets accessible to user", len(output)),
}
a.AutidLogAdd()
a.AuditLogAdd()
// output results as json
c.JSON(http.StatusOK, gin.H{"message": "success", "data": output})

View File

@@ -148,9 +148,10 @@ func StoreSecret(c *gin.Context) {
a := models.Audit{
UserId: UserId,
SecretId: s.SecretId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Created Secret Id %d", s.SecretId),
}
a.AutidLogAdd()
a.AuditLogAdd()
c.JSON(http.StatusOK, gin.H{"message": "secret stored successfully", "data": models.SecretRestricted(s)})
}
@@ -360,9 +361,10 @@ func UpdateSecret(c *gin.Context) {
a := models.Audit{
UserId: UserId,
SecretId: s.SecretId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Updated Secret Id %d", s.SecretId),
}
a.AutidLogAdd()
a.AuditLogAdd()
c.JSON(http.StatusOK, gin.H{"message": "secret updated successfully", "data": models.SecretRestricted(s)})
} else {
@@ -451,9 +453,10 @@ func DeleteSecret(c *gin.Context) {
a := models.Audit{
UserId: UserId,
SecretId: s.SecretId,
IpAddress: c.ClientIP(),
EventText: fmt.Sprintf("Deleted Secret Id %d", s.SecretId),
}
a.AutidLogAdd()
a.AuditLogAdd()
c.JSON(http.StatusOK, gin.H{"message": "secret deleted successfully"})
} else {