mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: add description to audit log responses (#3949)
This commit is contained in:
@ -2,6 +2,7 @@ package coderd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@ -167,7 +168,14 @@ func convertAuditLog(dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
|
|||||||
Diff: diff,
|
Diff: diff,
|
||||||
StatusCode: dblog.StatusCode,
|
StatusCode: dblog.StatusCode,
|
||||||
AdditionalFields: dblog.AdditionalFields,
|
AdditionalFields: dblog.AdditionalFields,
|
||||||
Description: "",
|
Description: auditLogDescription(dblog),
|
||||||
User: user,
|
User: user,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func auditLogDescription(alog database.GetAuditLogsOffsetRow) string {
|
||||||
|
return fmt.Sprintf("{user} %s %s {target}",
|
||||||
|
codersdk.AuditAction(alog.Action).FriendlyString(),
|
||||||
|
codersdk.ResourceType(alog.ResourceType).FriendlyString(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -2308,7 +2308,7 @@ func (q *fakeQuerier) GetAuditLogsOffset(ctx context.Context, arg database.GetAu
|
|||||||
OrganizationID: alog.OrganizationID,
|
OrganizationID: alog.OrganizationID,
|
||||||
Ip: alog.Ip,
|
Ip: alog.Ip,
|
||||||
UserAgent: alog.UserAgent,
|
UserAgent: alog.UserAgent,
|
||||||
ResourceType: database.ResourceType(alog.UserAgent),
|
ResourceType: alog.ResourceType,
|
||||||
ResourceID: alog.ResourceID,
|
ResourceID: alog.ResourceID,
|
||||||
ResourceTarget: alog.ResourceTarget,
|
ResourceTarget: alog.ResourceTarget,
|
||||||
ResourceIcon: alog.ResourceIcon,
|
ResourceIcon: alog.ResourceIcon,
|
||||||
|
4
coderd/database/dump.sql
generated
4
coderd/database/dump.sql
generated
@ -73,7 +73,9 @@ CREATE TYPE resource_type AS ENUM (
|
|||||||
'template',
|
'template',
|
||||||
'template_version',
|
'template_version',
|
||||||
'user',
|
'user',
|
||||||
'workspace'
|
'workspace',
|
||||||
|
'git_ssh_key',
|
||||||
|
'api_key'
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TYPE user_status AS ENUM (
|
CREATE TYPE user_status AS ENUM (
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
|
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
|
||||||
-- EXISTS".
|
-- EXISTS".
|
||||||
|
|
||||||
-- Delete all jobs that use the new enum value.
|
-- Delete all audit logs that use the new enum values.
|
||||||
DELETE FROM
|
DELETE FROM
|
||||||
provisioner_jobs
|
audit_logs
|
||||||
WHERE
|
WHERE
|
||||||
type = 'template_version_dry_run'
|
resource_type = 'git_ssh_key' OR
|
||||||
;
|
resource_type = 'api_key';
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
|
||||||
|
-- EXISTS".
|
||||||
|
|
||||||
|
-- Delete all jobs that use the new enum value.
|
||||||
|
DELETE FROM
|
||||||
|
provisioner_jobs
|
||||||
|
WHERE
|
||||||
|
type = 'template_version_dry_run';
|
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'git_ssh_key';
|
||||||
|
ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'api_key';
|
@ -258,6 +258,8 @@ const (
|
|||||||
ResourceTypeTemplateVersion ResourceType = "template_version"
|
ResourceTypeTemplateVersion ResourceType = "template_version"
|
||||||
ResourceTypeUser ResourceType = "user"
|
ResourceTypeUser ResourceType = "user"
|
||||||
ResourceTypeWorkspace ResourceType = "workspace"
|
ResourceTypeWorkspace ResourceType = "workspace"
|
||||||
|
ResourceTypeGitSshKey ResourceType = "git_ssh_key"
|
||||||
|
ResourceTypeApiKey ResourceType = "api_key"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *ResourceType) Scan(src interface{}) error {
|
func (e *ResourceType) Scan(src interface{}) error {
|
||||||
|
@ -18,8 +18,31 @@ const (
|
|||||||
ResourceTypeTemplateVersion ResourceType = "template_version"
|
ResourceTypeTemplateVersion ResourceType = "template_version"
|
||||||
ResourceTypeUser ResourceType = "user"
|
ResourceTypeUser ResourceType = "user"
|
||||||
ResourceTypeWorkspace ResourceType = "workspace"
|
ResourceTypeWorkspace ResourceType = "workspace"
|
||||||
|
ResourceTypeGitSSHKey ResourceType = "git_ssh_key"
|
||||||
|
ResourceTypeAPIKey ResourceType = "api_key"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (r ResourceType) FriendlyString() string {
|
||||||
|
switch r {
|
||||||
|
case ResourceTypeOrganization:
|
||||||
|
return "organization"
|
||||||
|
case ResourceTypeTemplate:
|
||||||
|
return "template"
|
||||||
|
case ResourceTypeTemplateVersion:
|
||||||
|
return "template version"
|
||||||
|
case ResourceTypeUser:
|
||||||
|
return "user"
|
||||||
|
case ResourceTypeWorkspace:
|
||||||
|
return "workspace"
|
||||||
|
case ResourceTypeGitSSHKey:
|
||||||
|
return "git ssh key"
|
||||||
|
case ResourceTypeAPIKey:
|
||||||
|
return "api key"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type AuditAction string
|
type AuditAction string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -28,6 +51,19 @@ const (
|
|||||||
AuditActionDelete AuditAction = "delete"
|
AuditActionDelete AuditAction = "delete"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (a AuditAction) FriendlyString() string {
|
||||||
|
switch a {
|
||||||
|
case AuditActionCreate:
|
||||||
|
return "created"
|
||||||
|
case AuditActionWrite:
|
||||||
|
return "updated"
|
||||||
|
case AuditActionDelete:
|
||||||
|
return "deleted"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type AuditDiff map[string]AuditDiffField
|
type AuditDiff map[string]AuditDiffField
|
||||||
|
|
||||||
type AuditDiffField struct {
|
type AuditDiffField struct {
|
||||||
|
@ -692,7 +692,14 @@ export type ProvisionerStorageMethod = "file"
|
|||||||
export type ProvisionerType = "echo" | "terraform"
|
export type ProvisionerType = "echo" | "terraform"
|
||||||
|
|
||||||
// From codersdk/audit.go
|
// From codersdk/audit.go
|
||||||
export type ResourceType = "organization" | "template" | "template_version" | "user" | "workspace"
|
export type ResourceType =
|
||||||
|
| "api_key"
|
||||||
|
| "git_ssh_key"
|
||||||
|
| "organization"
|
||||||
|
| "template"
|
||||||
|
| "template_version"
|
||||||
|
| "user"
|
||||||
|
| "workspace"
|
||||||
|
|
||||||
// From codersdk/users.go
|
// From codersdk/users.go
|
||||||
export type UserStatus = "active" | "suspended"
|
export type UserStatus = "active" | "suspended"
|
||||||
|
@ -38,6 +38,8 @@ const resourceLabelByResourceType: Record<AuditLog["resource_type"], string> = {
|
|||||||
template_version: "template version",
|
template_version: "template version",
|
||||||
user: "user",
|
user: "user",
|
||||||
workspace: "workspace",
|
workspace: "workspace",
|
||||||
|
git_ssh_key: "git ssh key",
|
||||||
|
api_key: "api key",
|
||||||
}
|
}
|
||||||
|
|
||||||
const readableActionMessage = (auditLog: AuditLog) => {
|
const readableActionMessage = (auditLog: AuditLog) => {
|
||||||
|
Reference in New Issue
Block a user