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

Commit

Permalink
add computed to client grants
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkappa committed Sep 2, 2018
1 parent 2c73684 commit af2724e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
30 changes: 11 additions & 19 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func newClient() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"lifetime_in_seconds": {
Expand Down Expand Up @@ -129,6 +130,7 @@ func newClient() *schema.Resource {
"custom_login_page_on": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"custom_login_page": {
Type: schema.TypeString,
Expand All @@ -143,8 +145,9 @@ func newClient() *schema.Resource {
Optional: true,
},
"addons": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeMap},
},
"token_endpoint_auth_method": {
Expand Down Expand Up @@ -216,7 +219,7 @@ func createClient(d *schema.ResourceData, m interface{}) error {
return err
}
d.SetId(auth0.StringValue(c.ClientID))
return readClient(d, m)
return nil
}

func readClient(d *schema.ResourceData, m interface{}) error {
Expand Down Expand Up @@ -258,21 +261,10 @@ func readClient(d *schema.ResourceData, m interface{}) error {
})
}

if c.EncryptionKey != nil {
d.Set("encryption_key", c.EncryptionKey)
}

if c.Addons != nil {
d.Set("addons", c.Addons)
}

if c.ClientMetadata != nil {
d.Set("client_metadata", c.ClientMetadata)
}

if c.Mobile != nil {
d.Set("mobile", c.Mobile)
}
d.Set("encryption_key", c.EncryptionKey)
d.Set("addons", c.Addons)
d.Set("client_metadata", c.ClientMetadata)
d.Set("mobile", c.Mobile)

return nil
}
Expand Down Expand Up @@ -333,7 +325,7 @@ func buildClient(d *schema.ResourceData) *management.Client {
if v, ok := d.GetOk("encryption_key"); ok {
c.EncryptionKey = make(map[string]string)

for _, item := range v.([]interface{})[0].(map[string]interface{}) {
for _, item := range v.([]interface{}) {
for key, val := range item.(map[string]string) {
c.EncryptionKey[key] = val
}
Expand All @@ -344,7 +336,7 @@ func buildClient(d *schema.ResourceData) *management.Client {

c.Addons = make(map[string]interface{})

for _, item := range v.(*schema.Set).List() {
for _, item := range v.([]interface{}) {
for key, val := range item.(map[string]interface{}) {
c.Addons[key] = val
}
Expand Down
2 changes: 1 addition & 1 deletion auth0/resource_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "auth0_client" "my_client" {
oidc_conformant = false
callbacks = [ "https://example.com/callback" ]
allowed_origins = [ "https://example.com" ]
grant_types = [ "authorization_code", "http://auth0.com/oauth/grant-type/password-realm", "implicit", "password", "refresh_token" ]
grant_types = [ "authorization_code", "http://auth0.com/oauth/grant-type/password-realm", "implicit", "password", "refresh_token" ]
allowed_logout_urls = [ "https://example.com" ]
web_origins = [ "https://example.com" ]
jwt_configuration = {
Expand Down
10 changes: 5 additions & 5 deletions auth0/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func String(d *schema.ResourceData, key string) (s *string) {
v, ok := d.GetOk(key)
v, ok := d.GetOkExists(key)
if ok {
s = auth0.String(v.(string))
}
Expand All @@ -22,7 +22,7 @@ func MapString(m map[string]interface{}, key string) (s *string) {
}

func Int(d *schema.ResourceData, key string) (i *int) {
v, ok := d.GetOk(key)
v, ok := d.GetOkExists(key)
if ok {
i = auth0.Int(v.(int))
}
Expand All @@ -38,7 +38,7 @@ func MapInt(m map[string]interface{}, key string) (i *int) {
}

func Bool(d *schema.ResourceData, key string) (b *bool) {
v, ok := d.GetOk(key)
v, ok := d.GetOkExists(key)
if ok {
b = auth0.Bool(v.(bool))
}
Expand All @@ -54,15 +54,15 @@ func MapBool(m map[string]interface{}, key string) (b *bool) {
}

func Slice(d *schema.ResourceData, key string) (s []interface{}) {
v, ok := d.GetOk(key)
v, ok := d.GetOkExists(key)
if ok {
s = v.([]interface{})
}
return
}

func Map(d *schema.ResourceData, key string) (m map[string]interface{}) {
v, ok := d.GetOk(key)
v, ok := d.GetOkExists(key)
if ok {
m = v.(map[string]interface{})
}
Expand Down
4 changes: 2 additions & 2 deletions example/client/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ resource "auth0_client" "my_app_client" {
description = "Example Application Loooooong Description"
app_type = "non_interactive"
is_first_party = true
oidc_conformant = false
oidc_conformant = true
callbacks = ["https://example.com/callback"]
allowed_origins = ["https://example.com"]
web_origins = ["https://example.com"]
grant_types = [ "authorization_code", "http://auth0.com/oauth/grant-type/password-realm", "implicit", "password", "refresh_token" ]
grant_types = ["authorization_code", "http://auth0.com/oauth/grant-type/password-realm", "implicit", "password", "refresh_token"]

jwt_configuration = {
lifetime_in_seconds = 120
Expand Down

0 comments on commit af2724e

Please sign in to comment.