Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #312 from woz5999/support-hook-dependencies
Browse files Browse the repository at this point in the history
Support hook dependencies
  • Loading branch information
Yvo committed Mar 24, 2021
2 parents f53af72 + 2c017fe commit fc08ef1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
16 changes: 15 additions & 1 deletion auth0/resource_auth0_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func newHook() *schema.Resource {
ValidateFunc: validateHookNameFunc(),
Description: "Name of this hook",
},
"dependencies": {
Type: schema.TypeMap,
Elem: schema.TypeString,
Optional: true,
Description: "Dependencies of this hook used by webtask server",
},
"script": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -93,6 +99,7 @@ func readHook(d *schema.ResourceData, m interface{}) error {
}

d.Set("name", c.Name)
d.Set("dependencies", c.Dependencies)
d.Set("script", c.Script)
d.Set("trigger_id", c.TriggerID)
d.Set("enabled", c.Enabled)
Expand Down Expand Up @@ -148,12 +155,19 @@ func deleteHook(d *schema.ResourceData, m interface{}) error {
}

func buildHook(d *schema.ResourceData) *management.Hook {
return &management.Hook{
h := &management.Hook{
Name: String(d, "name"),
Script: String(d, "script"),
TriggerID: String(d, "trigger_id", IsNewResource()),
Enabled: Bool(d, "enabled"),
}

deps := Map(d, "dependencies")
if deps != nil {
h.Dependencies = &deps
}

return h
}

func validateHookNameFunc() schema.SchemaValidateFunc {
Expand Down
10 changes: 9 additions & 1 deletion auth0/resource_auth0_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestAccHookSecrets(t *testing.T) {
Config: testAccHookSecrets("alpha"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.auth0", "2.30.0"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "script", "function (user, context, callback) { callback(null, { user }); }"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "true"),
Expand All @@ -60,6 +61,7 @@ func TestAccHookSecrets(t *testing.T) {
Config: testAccHookSecrets2("gamma", "kappa"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.auth0", "2.30.0"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "script", "function (user, context, callback) { callback(null, { user }); }"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"),
resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "true"),
Expand Down Expand Up @@ -89,7 +91,10 @@ resource "auth0_hook" "my_hook" {
script = "function (user, context, callback) { callback(null, { user }); }"
trigger_id = "pre-user-registration"
enabled = true
secrets = {
dependencies = {
auth0 = "2.30.0"
}
secrets = {
foo = "%s"
}
}
Expand All @@ -102,6 +107,9 @@ resource "auth0_hook" "my_hook" {
name = "pre-user-reg-hook"
script = "function (user, context, callback) { callback(null, { user }); }"
trigger_id = "pre-user-registration"
dependencies = {
auth0 = "2.30.0"
}
enabled = true
secrets = {
foo = "%s"
Expand Down
11 changes: 8 additions & 3 deletions docs/resources/hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ Depending on the extensibility point, you can use Hooks with Database Connection
resource "auth0_hook" "my_hook" {
name = "My Pre User Registration Hook"
script = <<EOF
function (user, context, callback) {
callback(null, { user });
function (user, context, callback) {
callback(null, { user });
}
EOF
trigger_id = "pre-user-registration"
enabled = true
dependencies = {
auth0 = "2.30.0"
}
}
```

Expand All @@ -35,4 +39,5 @@ The following arguments are supported:
* `enabled` - (Optional) Whether the hook is enabled, or disabled
* `name` - (Required) Name of this hook
* `script` - (Required) Code to be executed when this hook runs
* `trigger_id` - (Required) Execution stage of this rule. Can be credentials-exchange, pre-user-registration, post-user-registration, post-change-password, or send-phone-message
* `trigger_id` - (Required) Execution stage of this rule. Can be credentials-exchange, pre-user-registration, post-user-registration, post-change-password, or send-phone-message
* `dependencies` - (Optional) Dependencies of this hook used by webtask server

0 comments on commit fc08ef1

Please sign in to comment.