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

Commit

Permalink
upgrade to auth0 v1 to allow for zero values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkappa committed Aug 11, 2018
1 parent f1fccd9 commit 2c73684
Show file tree
Hide file tree
Showing 31 changed files with 684 additions and 312 deletions.
11 changes: 7 additions & 4 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 = "v0.2.1"
version = "v1.0.0-beta.1"

[prune]
go-tests = true
Expand Down
72 changes: 37 additions & 35 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package auth0
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/mitchellh/mapstructure"
auth0 "github.com/yieldr/go-auth0"
"github.com/yieldr/go-auth0/management"
)

Expand Down Expand Up @@ -65,7 +65,7 @@ func newClient() *schema.Resource {
"grant_types": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Computed: true,
Optional: true,
},
"allowed_origins": {
Expand Down Expand Up @@ -106,9 +106,9 @@ func newClient() *schema.Resource {
},
},
"encryption_key": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeMap},
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"sso": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -215,7 +215,7 @@ func createClient(d *schema.ResourceData, m interface{}) error {
if err := api.Client.Create(c); err != nil {
return err
}
d.SetId(c.ClientID)
d.SetId(auth0.StringValue(c.ClientID))
return readClient(d, m)
}

Expand Down Expand Up @@ -249,10 +249,13 @@ func readClient(d *schema.ResourceData, m interface{}) error {
d.Set("form_template", c.FormTemplate)
d.Set("token_endpoint_auth_method", c.TokenEndpointAuthMethod)

if c.JWTConfiguration != nil {
var jwt_config = make(map[string]string)
mapstructure.Decode(c.JWTConfiguration, &jwt_config)
d.Set("jwt_configuration", jwt_config)
if jwtConfiguration := c.JWTConfiguration; jwtConfiguration != nil {
d.Set("jwt_configuration", map[string]interface{}{
"lifetime_in_seconds": jwtConfiguration.Algorithm,
"secret_encoded": jwtConfiguration.LifetimeInSeconds,
"scopes": jwtConfiguration.Scopes,
"alg": jwtConfiguration.SecretEncoded,
})
}

if c.EncryptionKey != nil {
Expand Down Expand Up @@ -292,46 +295,45 @@ func deleteClient(d *schema.ResourceData, m interface{}) error {
func buildClient(d *schema.ResourceData) *management.Client {

c := &management.Client{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
AppType: d.Get("app_type").(string),
LogoURI: d.Get("logo_uri").(string),
IsFirstParty: d.Get("is_first_party").(bool),
OIDCConformant: d.Get("oidc_conformant").(bool),
Callbacks: d.Get("callbacks").([]interface{}),
AllowedLogoutURLs: d.Get("allowed_logout_urls").([]interface{}),
AllowedOrigins: d.Get("allowed_origins").([]interface{}),
GrantTypes: d.Get("grant_types").([]interface{}),
WebOrigins: d.Get("web_origins").([]interface{}),
SSO: d.Get("sso").(bool),
SSODisabled: d.Get("sso_disabled").(bool),
CrossOriginAuth: d.Get("cross_origin_auth").(bool),
CrossOriginLocation: d.Get("cross_origin_loc").(string),
CustomLoginPageOn: d.Get("custom_login_page_on").(bool),
CustomLoginPage: d.Get("custom_login_page").(string),
CustomLoginPagePreview: d.Get("custom_login_page_preview").(string),
FormTemplate: d.Get("form_template").(string),
TokenEndpointAuthMethod: d.Get("token_endpoint_auth_method").(string),
Name: String(d, "name"),
Description: String(d, "description"),
AppType: String(d, "app_type"),
LogoURI: String(d, "logo_uri"),
IsFirstParty: Bool(d, "is_first_party"),
OIDCConformant: Bool(d, "oidc_conformant"),
Callbacks: Slice(d, "callbacks"),
AllowedLogoutURLs: Slice(d, "allowed_logout_urls"),
AllowedOrigins: Slice(d, "allowed_origins"),
GrantTypes: Slice(d, "grant_types"),
WebOrigins: Slice(d, "web_origins"),
SSO: Bool(d, "sso"),
SSODisabled: Bool(d, "sso_disabled"),
CrossOriginAuth: Bool(d, "cross_origin_auth"),
CrossOriginLocation: String(d, "cross_origin_loc"),
CustomLoginPageOn: Bool(d, "custom_login_page_on"),
CustomLoginPage: String(d, "custom_login_page"),
CustomLoginPagePreview: String(d, "custom_login_page_preview"),
FormTemplate: String(d, "form_template"),
TokenEndpointAuthMethod: String(d, "token_endpoint_auth_method"),
}

if v, ok := d.GetOk("jwt_configuration"); ok {
vL := v.([]interface{})
for _, v := range vL {
jwtC := v.(map[string]interface{})
jwtConfiguration := v.(map[string]interface{})

c.JWTConfiguration = &management.ClientJWTConfiguration{
LifetimeInSeconds: jwtC["lifetime_in_seconds"].(int),
Scopes: jwtC["scopes"],
Algorithm: jwtC["alg"].(string),
LifetimeInSeconds: auth0.Int(jwtConfiguration["lifetime_in_seconds"].(int)),
Scopes: jwtConfiguration["scopes"],
Algorithm: auth0.String(jwtConfiguration["alg"].(string)),
}
}
}

if v, ok := d.GetOk("encryption_key"); ok {

c.EncryptionKey = make(map[string]string)

for _, item := range v.(*schema.Set).List() {
for _, item := range v.([]interface{})[0].(map[string]interface{}) {
for key, val := range item.(map[string]string) {
c.EncryptionKey[key] = val
}
Expand Down
15 changes: 8 additions & 7 deletions auth0/resource_auth0_client_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth0

import (
"github.com/hashicorp/terraform/helper/schema"
auth0 "github.com/yieldr/go-auth0"
"github.com/yieldr/go-auth0/management"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func createClientGrant(d *schema.ResourceData, m interface{}) error {
if err := api.ClientGrant.Create(g); err != nil {
return err
}
d.SetId(g.ID)
d.SetId(auth0.StringValue(g.ID))
return readClientGrant(d, m)
}

Expand All @@ -50,7 +51,7 @@ func readClientGrant(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
d.SetId(g.ID)
d.SetId(auth0.StringValue(g.ID))
d.Set("client_id", g.ClientID)
d.Set("audience", g.Audience)
d.Set("scope", g.Scope)
Expand All @@ -59,8 +60,8 @@ func readClientGrant(d *schema.ResourceData, m interface{}) error {

func updateClientGrant(d *schema.ResourceData, m interface{}) error {
g := buildClientGrant(d)
g.Audience = ""
g.ClientID = ""
g.Audience = nil
g.ClientID = nil
api := m.(*management.Management)
err := api.ClientGrant.Update(d.Id(), g)
if err != nil {
Expand All @@ -76,9 +77,9 @@ func deleteClientGrant(d *schema.ResourceData, m interface{}) error {

func buildClientGrant(d *schema.ResourceData) *management.ClientGrant {
g := &management.ClientGrant{
ClientID: d.Get("client_id").(string),
Audience: d.Get("audience").(string),
Scope: d.Get("scope").([]interface{}),
ClientID: String(d, "client_id"),
Audience: String(d, "audience"),
Scope: Slice(d, "scope"),
}

return g
Expand Down
44 changes: 22 additions & 22 deletions auth0/resource_auth0_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
auth0 "github.com/yieldr/go-auth0"
"github.com/yieldr/go-auth0/management"
)

Expand Down Expand Up @@ -118,7 +119,6 @@ func newConnection() *schema.Resource {
"brute_force_protection": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"import_mode": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -152,7 +152,7 @@ func createConnection(d *schema.ResourceData, m interface{}) error {
if err := api.Connection.Create(c); err != nil {
return err
}
d.SetId(c.ID)
d.SetId(auth0.StringValue(c.ID))
return readConnection(d, m)
}

Expand All @@ -162,7 +162,7 @@ func readConnection(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
d.SetId(c.ID)
d.SetId(auth0.StringValue(c.ID))
d.Set("name", c.Name)
d.Set("strategy", c.Strategy)
d.Set("options", []map[string]interface{}{
Expand Down Expand Up @@ -198,8 +198,8 @@ func readConnection(d *schema.ResourceData, m interface{}) error {

func updateConnection(d *schema.ResourceData, m interface{}) error {
c := buildConnection(d)
c.Strategy = ""
c.Name = ""
c.Strategy = nil
c.Name = nil
api := m.(*management.Management)
err := api.Connection.Update(d.Id(), c)
if err != nil {
Expand All @@ -216,10 +216,10 @@ func deleteConnection(d *schema.ResourceData, m interface{}) error {
func buildConnection(d *schema.ResourceData) *management.Connection {

c := &management.Connection{
Name: d.Get("name").(string),
Strategy: d.Get("strategy").(string),
EnabledClients: d.Get("enabled_clients").([]interface{}),
Realms: d.Get("realms").([]interface{}),
Name: String(d, "name"),
Strategy: String(d, "strategy"),
EnabledClients: Slice(d, "enabled_clients"),
Realms: Slice(d, "realms"),
}

if v, ok := d.GetOk("options"); ok {
Expand All @@ -230,22 +230,22 @@ 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: options["password_policy"].(string),
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: options["api_enable_users"].(bool),
BasicProfile: options["basic_profile"].(bool),
ExtAdmin: options["ext_admin"].(bool),
ExtIsSuspended: options["ext_is_suspended"].(bool),
ExtAgreedTerms: options["ext_agreed_terms"].(bool),
ExtGroups: options["ext_groups"].(bool),
ExtAssignedPlans: options["ext_assigned_plans"].(bool),
ExtProfile: options["ext_profile"].(bool),
EnabledDatabaseCustomization: options["enabled_database_customization"].(bool),
BruteForceProtection: options["brute_force_protection"].(bool),
ImportMode: options["import_mode"].(bool),
DisableSignup: options["disable_signup"].(bool),
APIEnableUsers: auth0.Bool(options["api_enable_users"].(bool)),
BasicProfile: auth0.Bool(options["basic_profile"].(bool)),
ExtAdmin: auth0.Bool(options["ext_admin"].(bool)),
ExtIsSuspended: auth0.Bool(options["ext_is_suspended"].(bool)),
ExtAgreedTerms: auth0.Bool(options["ext_agreed_terms"].(bool)),
ExtGroups: auth0.Bool(options["ext_groups"].(bool)),
ExtAssignedPlans: auth0.Bool(options["ext_assigned_plans"].(bool)),
ExtProfile: auth0.Bool(options["ext_profile"].(bool)),
EnabledDatabaseCustomization: auth0.Bool(options["enabled_database_customization"].(bool)),
BruteForceProtection: auth0.Bool(options["brute_force_protection"].(bool)),
ImportMode: auth0.Bool(options["import_mode"].(bool)),
DisableSignup: auth0.Bool(options["disable_signup"].(bool)),
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions auth0/resource_auth0_custom_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth0
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
auth0 "github.com/yieldr/go-auth0"
"github.com/yieldr/go-auth0/management"
)

Expand Down Expand Up @@ -67,7 +68,7 @@ func createCustomDomain(d *schema.ResourceData, m interface{}) error {
if err := api.CustomDomain.Create(c); err != nil {
return err
}
d.SetId(c.ID)
d.SetId(auth0.StringValue(c.ID))
return readCustomDomain(d, m)
}

Expand All @@ -77,7 +78,7 @@ func readCustomDomain(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
d.SetId(c.ID)
d.SetId(auth0.StringValue(c.ID))
d.Set("domain", c.Domain)
d.Set("type", c.Type)
d.Set("primary", c.Primary)
Expand Down Expand Up @@ -106,8 +107,8 @@ func deleteCustomDomain(d *schema.ResourceData, m interface{}) error {

func buildCustomDomain(d *schema.ResourceData) *management.CustomDomain {
return &management.CustomDomain{
Domain: d.Get("domain").(string),
Type: d.Get("type").(string),
VerificationMethod: d.Get("verification_method").(string),
Domain: String(d, "domain"),
Type: String(d, "type"),
VerificationMethod: String(d, "verification_method"),
}
}
Loading

0 comments on commit 2c73684

Please sign in to comment.