Skip to content

chore: rearrange audit logging code into enterprise folder #3741

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 13 commits into from
Aug 31, 2022
Prev Previous commit
Next Next commit
fixup! spike comments
  • Loading branch information
coadler committed Aug 31, 2022
commit ec83dfcc1d4168768aae3452c380e8577ed735ed
3 changes: 2 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ALTER TABLE audit_logs
DROP COLUMN additional_fields,
DROP COLUMN request_id;
DROP COLUMN request_id,
DROP COLUMN resource_icon;
13 changes: 9 additions & 4 deletions coderd/database/migrations/000039_audit_addtl_fields.up.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
ALTER TABLE audit_logs ADD COLUMN additional_fields jsonb NOT NULL DEFAULT '{}'::jsonb;
ALTER TABLE audit_logs ALTER COLUMN additional_fields DROP DEFAULT;
ALTER TABLE audit_logs ADD COLUMN request_id uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::uuid;
ALTER TABLE audit_logs ALTER COLUMN request_id DROP DEFAULT;
ALTER TABLE audit_logs
ADD COLUMN additional_fields jsonb NOT NULL DEFAULT '{}'::jsonb,
ADD COLUMN request_id uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::uuid,
ADD COLUMN resource_icon text NOT NULL DEFAULT '';

ALTER TABLE audit_logs
ALTER COLUMN additional_fields DROP DEFAULT,
ALTER COLUMN request_id DROP DEFAULT,
ALTER COLUMN resource_icon DROP DEFAULT;
1 change: 1 addition & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions coderd/database/queries/auditlogs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ INSERT INTO
diff,
status_code,
additional_fields,
request_id
request_id,
resource_icon
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *;
3 changes: 1 addition & 2 deletions codersdk/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ type AuditLog struct {
ResourceID uuid.UUID `json:"resource_id"`
// ResourceTarget is the name of the resource.
ResourceTarget string `json:"resource_target"`
ResourceIcon string `json:"resource_icon"`
Action AuditAction `json:"action"`
Diff AuditDiff `json:"diff"`
StatusCode int32 `json:"status_code"`
AdditionalFields json.RawMessage `json:"additional_fields"`
Description string `json:"description"`

User *User `json:"user"`
// Resource is the full object of the resource the audit log is for.
Resource json.RawMessage `json:"resource"`
}
3 changes: 1 addition & 2 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ export interface AuditLog {
readonly resource_type: ResourceType
readonly resource_id: string
readonly resource_target: string
readonly resource_icon: string
readonly action: AuditAction
readonly diff: AuditDiff
readonly status_code: number
// This is likely an enum in an external package ("encoding/json.RawMessage")
readonly additional_fields: string
readonly description: string
readonly user?: User
// This is likely an enum in an external package ("encoding/json.RawMessage")
readonly resource: string
}

// From codersdk/users.go
Expand Down