feat: audit addition and removal of licenses (#6125)

* added license audit resource

* audit delete licenses

* added filtering

* remove logs

* making the best of the current UUID situation

* fixed lint

* fix tests

* regen docs

* PR feedback

* PR feedback
This commit is contained in:
Kira Pilot
2023-02-14 16:34:13 -05:00
committed by GitHub
parent 6e3330a03f
commit 5e60879fb8
15 changed files with 94 additions and 23 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ type Auditable interface {
database.Workspace |
database.GitSSHKey |
database.WorkspaceBuild |
database.AuditableGroup
database.AuditableGroup |
database.License
}
// Map is a map of changed fields in an audited resource. It maps field names to
+7
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/http"
"strconv"
"github.com/google/uuid"
"github.com/tabbed/pqtype"
@@ -71,6 +72,8 @@ func ResourceTarget[T Auditable](tgt T) string {
case database.APIKey:
// this isn't used
return ""
case database.License:
return strconv.Itoa(int(typed.ID))
default:
panic(fmt.Sprintf("unknown resource %T", tgt))
}
@@ -94,6 +97,8 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
return typed.Group.ID
case database.APIKey:
return typed.UserID
case database.License:
return typed.UUID
default:
panic(fmt.Sprintf("unknown resource %T", tgt))
}
@@ -117,6 +122,8 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
return database.ResourceTypeGroup
case database.APIKey:
return database.ResourceTypeApiKey
case database.License:
return database.ResourceTypeLicense
default:
panic(fmt.Sprintf("unknown resource %T", tgt))
}