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

Commit

Permalink
improve support for custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkappa committed Sep 23, 2018
1 parent 5cae091 commit fbc76ea
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

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

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 39 additions & 20 deletions auth0/resource_auth0_connection.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
},
},
},
},
},
Expand Down Expand Up @@ -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,
},
})

Expand Down Expand Up @@ -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)),
Expand All @@ -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{}),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions auth0/resource_auth0_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand All @@ -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"
}
}
}
`
14 changes: 14 additions & 0 deletions example/connection/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<EOF
function getByEmail (email, callback) {
return callback(new Error("Whoops!"))
}
EOF
}

configuration = {
foo = "bar"
bar = "baz"
}
}
}
2 changes: 1 addition & 1 deletion vendor/github.com/yieldr/go-auth0/management/connection.go

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

0 comments on commit fbc76ea

Please sign in to comment.