Skip to content

Commit

Permalink
fix: convert map[string]interface{} to map[string]string. closes #84
Browse files Browse the repository at this point in the history
  • Loading branch information
MCBrandenburg committed Nov 13, 2021
1 parent 63394fa commit 3c21e99
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 37 deletions.
11 changes: 11 additions & 0 deletions fusionauth/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,14 @@ func setResourceData(resource string, data *schema.ResourceData, dataMapping map

return diags
}

func intMapToStringMap(intMap map[string]interface{}) map[string]string {
m := map[string]string{}
for k, v := range intMap {
if s, ok := v.(string); ok {
m[k] = s
}
}

return m
}
48 changes: 48 additions & 0 deletions fusionauth/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package fusionauth

import (
"reflect"
"testing"
)

func Test_intMapToStringMap(t *testing.T) {
type args struct {
intMap map[string]interface{}
}
tests := []struct {
name string
args args
want map[string]string
}{
{
name: "FA Issues #1482",
args: args{
intMap: map[string]interface{}{
"ar": "Test",
},
},
want: map[string]string{
"ar": "Test",
},
},
{
name: "FA Issues #1482",
args: args{
intMap: map[string]interface{}{
"ar": "Test",
"aaass": 2,
},
},
want: map[string]string{
"ar": "Test",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := intMapToStringMap(tt.args.intMap); !reflect.DeepEqual(got, tt.want) {
t.Errorf("intMapToStringMap() = %v, want %v", got, tt.want)
}
})
}
}
8 changes: 4 additions & 4 deletions fusionauth/resource_fusionauth_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ func buildEmail(data *schema.ResourceData) fusionauth.EmailTemplate {
}

if i, ok := data.GetOk("localized_from_names"); ok {
e.LocalizedFromNames = i.(map[string]string)
e.LocalizedFromNames = intMapToStringMap(i.(map[string]interface{}))
}

if i, ok := data.GetOk("localized_html_templates"); ok {
e.LocalizedHtmlTemplates = i.(map[string]string)
e.LocalizedHtmlTemplates = intMapToStringMap(i.(map[string]interface{}))
}

if i, ok := data.GetOk("localized_subjects"); ok {
e.LocalizedSubjects = i.(map[string]string)
e.LocalizedSubjects = intMapToStringMap(i.(map[string]interface{}))
}

if i, ok := data.GetOk("localized_text_templates"); ok {
e.LocalizedTextTemplates = i.(map[string]string)
e.LocalizedTextTemplates = intMapToStringMap(i.(map[string]interface{}))
}
return e
}
Expand Down
9 changes: 2 additions & 7 deletions fusionauth/resource_fusionauth_idp_external_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,8 @@ func buildIDPExternalJWT(data *schema.ResourceData) IDPExternalJWTProviderBody {
UniqueIdentityClaim: data.Get("unique_identity_claim").(string),
}

if x, ok := data.GetOk("claim_map"); ok {
m := make(map[string]string)
cm := x.(map[string]interface{})
for k, v := range cm {
m[k] = v.(string)
}
idp.ClaimMap = m
if i, ok := data.GetOk("claim_map"); ok {
idp.ClaimMap = intMapToStringMap(i.(map[string]interface{}))
}

ac := buildIDPExternalJWTAppConfig("application_configuration", data)
Expand Down
7 changes: 2 additions & 5 deletions fusionauth/resource_fusionauth_themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,8 @@ func buildTheme(data *schema.ResourceData) fusionauth.Theme {
},
}

m := data.Get("localized_messages").(map[string]interface{})
t.LocalizedMessages = make(map[string]string)

for k, v := range m {
t.LocalizedMessages[k] = v.(string)
if i, ok := data.GetOk("localized_messages"); ok {
t.LocalizedMessages = intMapToStringMap(i.(map[string]interface{}))
}

return t
Expand Down
18 changes: 4 additions & 14 deletions fusionauth/resource_fusionauth_user_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,8 @@ func buildUserAction(data *schema.ResourceData) fusionauth.UserAction {
if d, ok := data.GetOk("include_email_in_event_json"); ok {
ua.IncludeEmailInEventJSON = d.(bool)
}
if d, ok := data.GetOk("localized_names"); ok {
names := d.(map[string]interface{})
ua.LocalizedNames = make(map[string]string)

for k, v := range names {
ua.LocalizedNames[k] = v.(string)
}
if i, ok := data.GetOk("localized_names"); ok {
ua.LocalizedNames = intMapToStringMap(i.(map[string]interface{}))
}
if d, ok := data.GetOk("modify_email_template_id"); ok {
ua.ModifyEmailTemplateId = d.(string)
Expand Down Expand Up @@ -278,13 +273,8 @@ func buildUserActionOptions(d interface{}) []fusionauth.UserActionOption {
Name: v.Get("name").(string),
}

if lns, ok := v.GetOk("localized_names"); ok {
names := lns.(map[string]interface{})
uao.LocalizedNames = make(map[string]string)

for k, v := range names {
uao.LocalizedNames[k] = v.(string)
}
if i, ok := v.GetOk("localized_names"); ok {
uao.LocalizedNames = intMapToStringMap(i.(map[string]interface{}))
}

opts = append(opts, uao)
Expand Down
9 changes: 2 additions & 7 deletions fusionauth/resource_fusionauth_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,8 @@ func buildWebhook(data *schema.ResourceData) fusionauth.Webhook {
Url: data.Get("url").(string),
}

if hi, ok := data.GetOk("headers"); ok {
h := hi.(map[string]interface{})
m := make(map[string]string)
for k, v := range h {
m[k] = v.(string)
}
wh.Headers = m
if i, ok := data.GetOk("headers"); ok {
wh.Headers = intMapToStringMap(i.(map[string]interface{}))
}

return wh
Expand Down

0 comments on commit 3c21e99

Please sign in to comment.