From fbc76ea36fd2ca4fddf8dc910f290facff184f9f Mon Sep 17 00:00:00 2001 From: Alex Kalyvitis Date: Sun, 23 Sep 2018 23:05:22 +0200 Subject: [PATCH] improve support for custom scripts --- Gopkg.lock | 6 +- Gopkg.toml | 2 +- auth0/resource_auth0_connection.go | 59 ++++++++++++------- auth0/resource_auth0_connection_test.go | 8 +++ example/connection/main.tf | 14 +++++ .../yieldr/go-auth0/management/connection.go | 2 +- 6 files changed, 66 insertions(+), 25 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 70de3b26..39944992 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -359,8 +359,8 @@ ".", "management" ] - revision = "8078b2f1415b45483e718606220a48ae7276fade" - version = "v1.0.0-beta.5" + revision = "6443f7f784cfda5477010d9b1c9ce42caf6280b2" + version = "v1.0.0-beta.6" [[projects]] branch = "master" @@ -504,6 +504,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "8fc501cbd35965962e735c446577555422a60dfdb242a5b7c17b0aeee3058315" + inputs-digest = "710e99e73075c8a8ea7a15124bcf2d3cc984f882235db6f32791897b93e8b442" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 49808bb0..5ccc70e2 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -4,7 +4,7 @@ [[constraint]] name = "github.com/yieldr/go-auth0" - version = "v1.0.0-beta.5" + version = "v1.0.0-beta.6" [prune] go-tests = true diff --git a/auth0/resource_auth0_connection.go b/auth0/resource_auth0_connection.go index 98e99542..677d9202 100644 --- a/auth0/resource_auth0_connection.go +++ b/auth0/resource_auth0_connection.go @@ -1,6 +1,8 @@ package auth0 import ( + "strings" + "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" auth0 "github.com/yieldr/go-auth0" @@ -130,6 +132,20 @@ func newConnection() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "custom_scripts": { + Type: schema.TypeMap, + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + }, + "configuration": { + Type: schema.TypeMap, + Elem: &schema.Schema{Type: schema.TypeString}, + Sensitive: true, + Optional: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.HasPrefix(old, "2.0$") || new == old + }, + }, }, }, }, @@ -170,23 +186,25 @@ func readConnection(d *schema.ResourceData, m interface{}) error { d.Set("options", []map[string]interface{}{ { "validation": c.Options.Validation, - "password_policy": c.Options.PasswordPolicy, + "password_policy": auth0.StringValue(c.Options.PasswordPolicy), "password_history": c.Options.PasswordHistory, "password_no_personal_info": c.Options.PasswordNoPersonalInfo, "password_dictionary": c.Options.PasswordDictionary, - "api_enable_users": c.Options.APIEnableUsers, - "basic_profile": c.Options.BasicProfile, - "ext_admin": c.Options.ExtAdmin, - "ext_is_suspended": c.Options.ExtIsSuspended, - "ext_agreed_terms": c.Options.ExtAgreedTerms, - "ext_groups": c.Options.ExtGroups, - "ext_assigned_plans": c.Options.ExtAssignedPlans, - "ext_profile": c.Options.ExtProfile, - "enabled_database_customization": c.Options.EnabledDatabaseCustomization, - "brute_force_protection": c.Options.BruteForceProtection, - "import_mode": c.Options.ImportMode, - "disable_signup": c.Options.DisableSignup, - "requires_username": c.Options.RequiresUsername, + "api_enable_users": auth0.BoolValue(c.Options.APIEnableUsers), + "basic_profile": auth0.BoolValue(c.Options.BasicProfile), + "ext_admin": auth0.BoolValue(c.Options.ExtAdmin), + "ext_is_suspended": auth0.BoolValue(c.Options.ExtIsSuspended), + "ext_agreed_terms": auth0.BoolValue(c.Options.ExtAgreedTerms), + "ext_groups": auth0.BoolValue(c.Options.ExtGroups), + "ext_assigned_plans": auth0.BoolValue(c.Options.ExtAssignedPlans), + "ext_profile": auth0.BoolValue(c.Options.ExtProfile), + "enabled_database_customization": auth0.BoolValue(c.Options.EnabledDatabaseCustomization), + "brute_force_protection": auth0.BoolValue(c.Options.BruteForceProtection), + "import_mode": auth0.BoolValue(c.Options.ImportMode), + "disable_signup": auth0.BoolValue(c.Options.DisableSignup), + "requires_username": auth0.BoolValue(c.Options.RequiresUsername), + "custom_scripts": c.Options.CustomScripts, + "configuration": c.Options.Configuration, }, }) @@ -228,12 +246,11 @@ func buildConnection(d *schema.ResourceData) *management.Connection { if options, ok := v.(map[string]interface{}); ok { c.Options = &management.ConnectionOptions{ - Validation: options["validation"].(map[string]interface{}), - PasswordPolicy: auth0.String(options["password_policy"].(string)), - PasswordHistory: options["password_history"].(map[string]interface{}), - PasswordNoPersonalInfo: options["password_no_personal_info"].(map[string]interface{}), - PasswordDictionary: options["password_dictionary"].(map[string]interface{}), - + Validation: options["validation"].(map[string]interface{}), + PasswordPolicy: auth0.String(options["password_policy"].(string)), + PasswordHistory: options["password_history"].(map[string]interface{}), + PasswordNoPersonalInfo: options["password_no_personal_info"].(map[string]interface{}), + PasswordDictionary: options["password_dictionary"].(map[string]interface{}), APIEnableUsers: auth0.Bool(options["api_enable_users"].(bool)), BasicProfile: auth0.Bool(options["basic_profile"].(bool)), ExtAdmin: auth0.Bool(options["ext_admin"].(bool)), @@ -247,6 +264,8 @@ func buildConnection(d *schema.ResourceData) *management.Connection { ImportMode: auth0.Bool(options["import_mode"].(bool)), DisableSignup: auth0.Bool(options["disable_signup"].(bool)), RequiresUsername: auth0.Bool(options["requires_username"].(bool)), + CustomScripts: options["custom_scripts"].(map[string]interface{}), + Configuration: options["configuration"].(map[string]interface{}), } } } diff --git a/auth0/resource_auth0_connection_test.go b/auth0/resource_auth0_connection_test.go index 9ddebd8d..453c4659 100644 --- a/auth0/resource_auth0_connection_test.go +++ b/auth0/resource_auth0_connection_test.go @@ -25,6 +25,8 @@ func TestAccConnection(t *testing.T) { resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.import_mode", "true"), resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.disable_signup", "false"), resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.requires_username", "true"), + resource.TestCheckResourceAttr("auth0_connection.my_connection", "options.0.custom_scripts.get_user", "myFunction"), + resource.TestCheckResourceAttrSet("auth0_connection.my_connection", "options.0.configuration.foo"), ), }, }, @@ -44,6 +46,12 @@ resource "auth0_connection" "my_connection" { import_mode = true disable_signup = false requires_username = true + custom_scripts = { + get_user = "myFunction" + } + configuration = { + foo = "bar" + } } } ` diff --git a/example/connection/main.tf b/example/connection/main.tf index f3cd060c..f5127a8e 100644 --- a/example/connection/main.tf +++ b/example/connection/main.tf @@ -5,5 +5,19 @@ resource "auth0_connection" "my_connection" { strategy = "auth0" options = { password_policy = "excellent" + brute_force_protection = "true" + enabled_database_customization = "true" + custom_scripts = { + get_user = <