Skip to content

Commit

Permalink
GH-475: Prevent sending empty payloads for client addons (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored Jul 28, 2023
1 parent 48b575c commit f9a68b9
Show file tree
Hide file tree
Showing 5 changed files with 2,096 additions and 466 deletions.
84 changes: 80 additions & 4 deletions internal/auth0/client/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ func expandClientAddons(d *schema.ResourceData) *management.ClientAddons {
return stop
})

if addons == (management.ClientAddons{}) {
return nil
}

return &addons
}

Expand All @@ -315,6 +311,10 @@ func expandClientAddonAWS(awsCfg cty.Value) *management.AWSClientAddon {
return stop
})

if awsAddon == (management.AWSClientAddon{}) {
return nil
}

return &awsAddon
}

Expand All @@ -341,6 +341,10 @@ func expandClientAddonAzureBlob(azureCfg cty.Value) *management.AzureBlobClientA
return stop
})

if azureAddon == (management.AzureBlobClientAddon{}) {
return nil
}

return &azureAddon
}

Expand All @@ -359,6 +363,10 @@ func expandClientAddonAzureSB(azureCfg cty.Value) *management.AzureSBClientAddon
return stop
})

if azureAddon == (management.AzureSBClientAddon{}) {
return nil
}

return &azureAddon
}

Expand Down Expand Up @@ -428,6 +436,10 @@ func expandClientAddonSentry(sentryCfg cty.Value) *management.SentryClientAddon
return stop
})

if sentryAddon == (management.SentryClientAddon{}) {
return nil
}

return &sentryAddon
}

Expand All @@ -442,6 +454,10 @@ func expandClientAddonEchoSign(echoSignCfg cty.Value) *management.EchoSignClient
return stop
})

if echoSignAddon == (management.EchoSignClientAddon{}) {
return nil
}

return &echoSignAddon
}

Expand All @@ -456,6 +472,10 @@ func expandClientAddonEgnyte(egnyteCfg cty.Value) *management.EgnyteClientAddon
return stop
})

if egnyteAddon == (management.EgnyteClientAddon{}) {
return nil
}

return &egnyteAddon
}

Expand All @@ -474,6 +494,10 @@ func expandClientAddonFirebase(firebaseCfg cty.Value) *management.FirebaseClient
return stop
})

if firebaseAddon == (management.FirebaseClientAddon{}) {
return nil
}

return &firebaseAddon
}

Expand All @@ -488,6 +512,10 @@ func expandClientAddonNewRelic(newRelicCfg cty.Value) *management.NewRelicClient
return stop
})

if newRelicAddon == (management.NewRelicClientAddon{}) {
return nil
}

return &newRelicAddon
}

Expand All @@ -503,6 +531,10 @@ func expandClientAddonOffice365(office365Cfg cty.Value) *management.Office365Cli
return stop
})

if office365Addon == (management.Office365ClientAddon{}) {
return nil
}

return &office365Addon
}

Expand All @@ -517,6 +549,10 @@ func expandClientAddonSalesforce(salesforceCfg cty.Value) *management.Salesforce
return stop
})

if salesforceAddon == (management.SalesforceClientAddon{}) {
return nil
}

return &salesforceAddon
}

Expand All @@ -534,6 +570,10 @@ func expandClientAddonSalesforceAPI(salesforceCfg cty.Value) *management.Salesfo
return stop
})

if salesforceAddon == (management.SalesforceAPIClientAddon{}) {
return nil
}

return &salesforceAddon
}

Expand All @@ -551,6 +591,10 @@ func expandClientAddonSalesforceSandboxAPI(salesforceCfg cty.Value) *management.
return stop
})

if salesforceAddon == (management.SalesforceSandboxAPIClientAddon{}) {
return nil
}

return &salesforceAddon
}

Expand Down Expand Up @@ -592,6 +636,10 @@ func expandClientAddonSAPAPI(sapAPICfg cty.Value) *management.SAPAPIClientAddon
return stop
})

if sapAPIAddon == (management.SAPAPIClientAddon{}) {
return nil
}

return &sapAPIAddon
}

Expand All @@ -607,6 +655,10 @@ func expandClientAddonSharepoint(sharepointCfg cty.Value) *management.SharePoint
return stop
})

if sharepointAddon == (management.SharePointClientAddon{}) {
return nil
}

return &sharepointAddon
}

Expand All @@ -621,6 +673,10 @@ func expandClientAddonSpringCM(springCMCfg cty.Value) *management.SpringCMClient
return stop
})

if springCMAddon == (management.SpringCMClientAddon{}) {
return nil
}

return &springCMAddon
}

Expand All @@ -635,6 +691,10 @@ func expandClientAddonWAMS(wamsCfg cty.Value) *management.WAMSClientAddon {
return stop
})

if wamsAddon == (management.WAMSClientAddon{}) {
return nil
}

return &wamsAddon
}

Expand All @@ -649,6 +709,10 @@ func expandClientAddonZendesk(zendeskCfg cty.Value) *management.ZendeskClientAdd
return stop
})

if zendeskAddon == (management.ZendeskClientAddon{}) {
return nil
}

return &zendeskAddon
}

Expand All @@ -663,6 +727,10 @@ func expandClientAddonZoom(zoomCfg cty.Value) *management.ZoomClientAddon {
return stop
})

if zoomAddon == (management.ZoomClientAddon{}) {
return nil
}

return &zoomAddon
}

Expand All @@ -678,6 +746,10 @@ func expandClientAddonSSOIntegration(ssoCfg cty.Value) *management.SSOIntegratio
return stop
})

if ssoAddon == (management.SSOIntegrationClientAddon{}) {
return nil
}

return &ssoAddon
}

Expand Down Expand Up @@ -770,6 +842,10 @@ func expandClientAddonSAMLP(samlpCfg cty.Value) *management.SAML2ClientAddon {
return stop
})

if samlpAddon == (management.SAML2ClientAddon{}) {
return nil
}

return &samlpAddon
}

Expand Down
33 changes: 20 additions & 13 deletions internal/auth0/client/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,26 @@ func flattenClientAddons(addons *management.ClientAddons) []interface{} {
"zoom": flattenClientAddonZoom(addons.GetZoom()),
"sso_integration": flattenClientAddonSSOIntegration(addons.GetSSOIntegration()),
"samlp": flattenClientAddonSAML2(addons.GetSAML2()),
"box": flattenClientAddonWithNoConfig(addons.GetBox()),
"cloudbees": flattenClientAddonWithNoConfig(addons.GetCloudBees()),
"concur": flattenClientAddonWithNoConfig(addons.GetConcur()),
"dropbox": flattenClientAddonWithNoConfig(addons.GetDropbox()),
"wsfed": flattenClientAddonWithNoConfig(addons.GetWSFED()),
}

if addons.GetBox() != nil {
m["box"] = []interface{}{map[string]interface{}{}}
}

if addons.GetCloudBees() != nil {
m["cloudbees"] = []interface{}{map[string]interface{}{}}
}

if addons.GetConcur() != nil {
m["concur"] = []interface{}{map[string]interface{}{}}
}

if addons.GetDropbox() != nil {
m["dropbox"] = []interface{}{map[string]interface{}{}}
}

if addons.GetWSFED() != nil {
m["wsfed"] = []interface{}{map[string]interface{}{}}
}

return []interface{}{m}
Expand Down Expand Up @@ -491,14 +506,6 @@ func flattenClientAddonSAML2(addon *management.SAML2ClientAddon) []interface{} {
}
}

func flattenClientAddonWithNoConfig(addon interface{}) []interface{} {
if addon == nil {
return nil
}

return []interface{}{map[string]interface{}{}}
}

func flattenClient(d *schema.ResourceData, client *management.Client) error {
result := multierror.Append(
d.Set("client_id", client.GetClientID()),
Expand Down
Loading

0 comments on commit f9a68b9

Please sign in to comment.