Skip to content

Commit

Permalink
[Extend Governor APIs] Extension Resource Definitions (#72)
Browse files Browse the repository at this point in the history
* add erd endpoints

* add slug validations

* proper enum type for scopes
  • Loading branch information
bailinhe authored Oct 12, 2023
1 parent 7f58565 commit 0944b94
Show file tree
Hide file tree
Showing 11 changed files with 3,184 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/nats-io/nats.go v1.28.0
github.com/pressly/goose/v3 v3.14.0
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThC
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sagikazarmark/crypt v0.6.0/go.mod h1:U8+INwJo3nBv1m6A/8OBXAq7Jnpspk5AxSgDyEQcea8=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
Expand Down
57 changes: 57 additions & 0 deletions internal/dbtools/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,3 +1069,60 @@ func AuditExtensionDeleted(ctx context.Context, exec boil.ContextExecutor, pID s

return &event, event.Insert(ctx, exec, boil.Infer())
}

// AuditExtensionResourceDefinitionCreated inserts an event representing a extension being created
func AuditExtensionResourceDefinitionCreated(ctx context.Context, exec boil.ContextExecutor, pID string, actor *models.User, erd *models.ExtensionResourceDefinition) (*models.AuditEvent, error) {
// TODO non-user API actors don't exist in the governor database,
// we need to figure out how to handle that relationship in the audit table
var actorID null.String
if actor != nil {
actorID = null.StringFrom(actor.ID)
}

event := models.AuditEvent{
ParentID: null.StringFrom(pID),
ActorID: actorID,
Action: "extension.erd.created",
Changeset: calculateChangeset(&models.ExtensionResourceDefinition{}, erd),
}

return &event, event.Insert(ctx, exec, boil.Infer())
}

// AuditExtensionResourceDefinitionUpdated inserts an event representing a extension being created
func AuditExtensionResourceDefinitionUpdated(ctx context.Context, exec boil.ContextExecutor, pID string, actor *models.User, o, a *models.ExtensionResourceDefinition) (*models.AuditEvent, error) {
// TODO non-user API actors don't exist in the governor database,
// we need to figure out how to handle that relationship in the audit table
var actorID null.String
if actor != nil {
actorID = null.StringFrom(actor.ID)
}

event := models.AuditEvent{
ParentID: null.StringFrom(pID),
ActorID: actorID,
Action: "extension.erd.updated",
Changeset: calculateChangeset(o, a),
}

return &event, event.Insert(ctx, exec, boil.Infer())
}

// AuditExtensionResourceDefinitionDeleted inserts an event representing a extension being created
func AuditExtensionResourceDefinitionDeleted(ctx context.Context, exec boil.ContextExecutor, pID string, actor *models.User, erd *models.ExtensionResourceDefinition) (*models.AuditEvent, error) {
// TODO non-user API actors don't exist in the governor database,
// we need to figure out how to handle that relationship in the audit table
var actorID null.String
if actor != nil {
actorID = null.StringFrom(actor.ID)
}

event := models.AuditEvent{
ParentID: null.StringFrom(pID),
ActorID: actorID,
Action: "extension.erd.deleted",
Changeset: calculateChangeset(erd, &models.ExtensionResourceDefinition{}),
}

return &event, event.Insert(ctx, exec, boil.Infer())
}
Loading

0 comments on commit 0944b94

Please sign in to comment.