From ad7dd25eb2b5e1a2f34217c928633e9b3e1b3933 Mon Sep 17 00:00:00 2001 From: woz5999 Date: Mon, 11 Jan 2021 12:43:15 -0800 Subject: [PATCH 1/9] Support hook dependencies --- auth0/resource_auth0_hook.go | 17 +++++++++++++---- auth0/resource_auth0_hook_test.go | 7 +++++++ docs/resources/hook.md | 6 +++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/auth0/resource_auth0_hook.go b/auth0/resource_auth0_hook.go index ca8e0b7e..0307375e 100644 --- a/auth0/resource_auth0_hook.go +++ b/auth0/resource_auth0_hook.go @@ -29,6 +29,12 @@ func newHook() *schema.Resource { ValidateFunc: validateHookNameFunc(), Description: "Name of this hook", }, + "dependencies": { + Type: schema.TypeMap, + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + Description: "Dependencies of this hook used by webtask server", + }, "script": { Type: schema.TypeString, Required: true, @@ -83,6 +89,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) @@ -115,11 +122,13 @@ func deleteHook(d *schema.ResourceData, m interface{}) error { } func buildHook(d *schema.ResourceData) *management.Hook { + deps := Map(d, "dependencies") return &management.Hook{ - Name: String(d, "name"), - Script: String(d, "script"), - TriggerID: String(d, "trigger_id", IsNewResource()), - Enabled: Bool(d, "enabled"), + Name: String(d, "name"), + Script: String(d, "script"), + TriggerID: String(d, "trigger_id", IsNewResource()), + Enabled: Bool(d, "enabled"), + Dependencies: &deps, } } diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index 5af2bbe9..2dfd9261 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -18,6 +18,7 @@ func TestAccHook(t *testing.T) { Config: testAccHookCreate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"), + resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.#", "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"), @@ -27,6 +28,8 @@ func TestAccHook(t *testing.T) { Config: testAccHookUpdate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"), + resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.#", "1"), + resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.0.auth0", "2.30.0"), // TODO figure out the right value resource.TestCheckResourceAttr("auth0_hook.my_hook", "script", "function (user, context, callback) { console.log(user); callback(null, { user }); }"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "false"), @@ -43,6 +46,7 @@ resource "auth0_hook" "my_hook" { trigger_id = "pre-user-registration" script = "function (user, context, callback) { callback(null, { user }); }" enabled = true + dependencies {} } ` @@ -53,6 +57,9 @@ resource "auth0_hook" "my_hook" { trigger_id = "pre-user-registration" script = "function (user, context, callback) { console.log(user); callback(null, { user }); }" enabled = false + dependencies { + auth0 = "2.30.0" + } } ` diff --git a/docs/resources/hook.md b/docs/resources/hook.md index c7499fc5..66c4a28d 100644 --- a/docs/resources/hook.md +++ b/docs/resources/hook.md @@ -25,6 +25,10 @@ function (user, context, callback) { EOF trigger_id = "pre-user-registration" enabled = true + + dependencies = { + auth0 = "2.30.0" + } } ``` @@ -35,4 +39,4 @@ 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 \ No newline at end of file +* `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 From 3a697d429ff74dd2ecb8397e7635f939645e6ed6 Mon Sep 17 00:00:00 2001 From: woz5999 Date: Mon, 11 Jan 2021 12:52:38 -0800 Subject: [PATCH 2/9] Update resource_auth0_hook.go --- auth0/resource_auth0_hook.go | 1 + 1 file changed, 1 insertion(+) diff --git a/auth0/resource_auth0_hook.go b/auth0/resource_auth0_hook.go index 0307375e..a4af7cf9 100644 --- a/auth0/resource_auth0_hook.go +++ b/auth0/resource_auth0_hook.go @@ -32,6 +32,7 @@ func newHook() *schema.Resource { "dependencies": { Type: schema.TypeMap, Elem: &schema.Schema{Type: schema.TypeString}, + Required: false, Optional: true, Description: "Dependencies of this hook used by webtask server", }, From 09ca064a17e0d7b7906caa817c9349649c742142 Mon Sep 17 00:00:00 2001 From: woz5999 Date: Mon, 11 Jan 2021 14:38:30 -0800 Subject: [PATCH 3/9] some fixes and cleanup --- auth0/resource_auth0_hook.go | 2 +- auth0/resource_auth0_hook_test.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/auth0/resource_auth0_hook.go b/auth0/resource_auth0_hook.go index a4af7cf9..89f7f974 100644 --- a/auth0/resource_auth0_hook.go +++ b/auth0/resource_auth0_hook.go @@ -31,7 +31,7 @@ func newHook() *schema.Resource { }, "dependencies": { Type: schema.TypeMap, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: schema.TypeString, Required: false, Optional: true, Description: "Dependencies of this hook used by webtask server", diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index 2dfd9261..20fe9fea 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -29,7 +29,7 @@ func TestAccHook(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.#", "1"), - resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.0.auth0", "2.30.0"), // TODO figure out the right value + resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.0.auth0", "2.30.0"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "script", "function (user, context, callback) { console.log(user); callback(null, { user }); }"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "false"), @@ -46,7 +46,6 @@ resource "auth0_hook" "my_hook" { trigger_id = "pre-user-registration" script = "function (user, context, callback) { callback(null, { user }); }" enabled = true - dependencies {} } ` @@ -57,7 +56,7 @@ resource "auth0_hook" "my_hook" { trigger_id = "pre-user-registration" script = "function (user, context, callback) { console.log(user); callback(null, { user }); }" enabled = false - dependencies { + dependencies = { auth0 = "2.30.0" } } From 8ebb8034056ab20e5330668b472fd70e19caec19 Mon Sep 17 00:00:00 2001 From: woz5999 Date: Mon, 11 Jan 2021 15:09:09 -0800 Subject: [PATCH 4/9] fixes --- auth0/resource_auth0_hook.go | 18 +++++++++++------- auth0/resource_auth0_hook_test.go | 4 +--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/auth0/resource_auth0_hook.go b/auth0/resource_auth0_hook.go index 89f7f974..08484f30 100644 --- a/auth0/resource_auth0_hook.go +++ b/auth0/resource_auth0_hook.go @@ -32,7 +32,6 @@ func newHook() *schema.Resource { "dependencies": { Type: schema.TypeMap, Elem: schema.TypeString, - Required: false, Optional: true, Description: "Dependencies of this hook used by webtask server", }, @@ -123,14 +122,19 @@ func deleteHook(d *schema.ResourceData, m interface{}) error { } func buildHook(d *schema.ResourceData) *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") - return &management.Hook{ - Name: String(d, "name"), - Script: String(d, "script"), - TriggerID: String(d, "trigger_id", IsNewResource()), - Enabled: Bool(d, "enabled"), - Dependencies: &deps, + if deps != nil { + h.Dependencies = &deps } + + return h } func validateHookNameFunc() schema.SchemaValidateFunc { diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index 20fe9fea..bf3278f1 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -18,7 +18,6 @@ func TestAccHook(t *testing.T) { Config: testAccHookCreate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"), - resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.#", "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"), @@ -28,8 +27,7 @@ func TestAccHook(t *testing.T) { Config: testAccHookUpdate, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("auth0_hook.my_hook", "name", "pre-user-reg-hook"), - resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.#", "1"), - resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.0.auth0", "2.30.0"), + resource.TestCheckResourceAttr("auth0_hook.my_hook", "dependencies.auth0", "2.30.0"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "script", "function (user, context, callback) { console.log(user); callback(null, { user }); }"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "trigger_id", "pre-user-registration"), resource.TestCheckResourceAttr("auth0_hook.my_hook", "enabled", "false"), From 15dad5eeb445995dc47e2210680c612ff2998716 Mon Sep 17 00:00:00 2001 From: woz5999 Date: Mon, 11 Jan 2021 15:10:37 -0800 Subject: [PATCH 5/9] typo --- docs/resources/hook.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/resources/hook.md b/docs/resources/hook.md index 66c4a28d..c41ff41a 100644 --- a/docs/resources/hook.md +++ b/docs/resources/hook.md @@ -19,8 +19,8 @@ Depending on the extensibility point, you can use Hooks with Database Connection resource "auth0_hook" "my_hook" { name = "My Pre User Registration Hook" script = < Date: Tue, 23 Mar 2021 12:08:47 -0700 Subject: [PATCH 6/9] Update resource_auth0_hook_test.go --- auth0/resource_auth0_hook_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index 917cf06d..63a4076c 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -103,9 +103,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" - } + dependencies = { + auth0 = "2.30.0" + } enabled = true secrets = { foo = "%s" From 1c3181944394371557242b237335e5dec22dc2fb Mon Sep 17 00:00:00 2001 From: woz5999 Date: Tue, 23 Mar 2021 17:40:35 -0700 Subject: [PATCH 7/9] Update resource_auth0_hook_test.go --- auth0/resource_auth0_hook_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index 63a4076c..e0694331 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -61,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"), From 9e4befd140e8d9f90fa3e623df542d099a28299c Mon Sep 17 00:00:00 2001 From: woz5999 Date: Tue, 23 Mar 2021 17:41:22 -0700 Subject: [PATCH 8/9] Update resource_auth0_hook_test.go --- auth0/resource_auth0_hook_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index e0694331..b03dfcbc 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -61,7 +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", "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"), @@ -91,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" } } From 2c017fe4de62b24565ba8e13e2f33c1d8e949133 Mon Sep 17 00:00:00 2001 From: Yvo Date: Wed, 24 Mar 2021 10:44:44 +0100 Subject: [PATCH 9/9] Fix fmt Fix gofmt on L64 --- auth0/resource_auth0_hook_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth0/resource_auth0_hook_test.go b/auth0/resource_auth0_hook_test.go index b03dfcbc..61f6fe8f 100644 --- a/auth0/resource_auth0_hook_test.go +++ b/auth0/resource_auth0_hook_test.go @@ -61,7 +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", "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"),