@@ -12,6 +12,11 @@ import (
12
12
"github.com/pkg/errors"
13
13
)
14
14
15
+ const (
16
+ saasAuthTypeOIDC = "oidc"
17
+ saasAuthTypeSAML = "saml"
18
+ )
19
+
15
20
func resourceCloudflareAccessApplicationSchema () map [string ]* schema.Schema {
16
21
return map [string ]* schema.Schema {
17
22
consts .AccountIDSchemaKey : {
@@ -959,67 +964,70 @@ func convertOIDCClaimSchemaToStruct(data map[string]interface{}) cloudflare.OIDC
959
964
return cfg
960
965
}
961
966
962
- func convertSaasSchemaToStruct (d * schema.ResourceData ) * cloudflare.SaasApplication {
963
- SaasConfig := cloudflare.SaasApplication {}
964
- if _ , ok := d .GetOk ("saas_app" ); ok {
965
- authType := "saml"
966
- if rawAuthType , ok := d .GetOk ("saas_app.0.auth_type" ); ok {
967
- authType = rawAuthType .(string )
967
+ func convertSaasOIDCSchemaToStruct (d * schema.ResourceData ) * cloudflare.SaasApplication {
968
+ var oidcConfig cloudflare.SaasApplication
969
+ oidcConfig .AuthType = saasAuthTypeOIDC
970
+ oidcConfig .ClientID = d .Get ("saas_app.0.client_id" ).(string )
971
+ oidcConfig .AppLauncherURL = d .Get ("saas_app.0.app_launcher_url" ).(string )
972
+ oidcConfig .RedirectURIs = expandInterfaceToStringList (d .Get ("saas_app.0.redirect_uris" ).(* schema.Set ).List ())
973
+ oidcConfig .GrantTypes = expandInterfaceToStringList (d .Get ("saas_app.0.grant_types" ).(* schema.Set ).List ())
974
+ oidcConfig .Scopes = expandInterfaceToStringList (d .Get ("saas_app.0.scopes" ).(* schema.Set ).List ())
975
+ oidcConfig .GroupFilterRegex = d .Get ("saas_app.0.group_filter_regex" ).(string )
976
+ oidcConfig .AccessTokenLifetime = d .Get ("saas_app.0.access_token_lifetime" ).(string )
977
+ oidcConfig .AllowPKCEWithoutClientSecret = cloudflare .BoolPtr (d .Get ("saas_app.0.allow_pkce_without_client_secret" ).(bool ))
978
+ if _ , ok := d .GetOk ("saas_app.0.refresh_token_options" ); ok {
979
+ oidcConfig .RefreshTokenOptions = & cloudflare.RefreshTokenOptions {
980
+ Lifetime : d .Get ("saas_app.0.refresh_token_options.0.lifetime" ).(string ),
968
981
}
969
- SaasConfig .AuthType = authType
970
- if authType == "oidc" {
971
- SaasConfig .ClientID = d .Get ("saas_app.0.client_id" ).(string )
972
- SaasConfig .AppLauncherURL = d .Get ("saas_app.0.app_launcher_url" ).(string )
973
- SaasConfig .RedirectURIs = expandInterfaceToStringList (d .Get ("saas_app.0.redirect_uris" ).(* schema.Set ).List ())
974
- SaasConfig .GrantTypes = expandInterfaceToStringList (d .Get ("saas_app.0.grant_types" ).(* schema.Set ).List ())
975
- SaasConfig .Scopes = expandInterfaceToStringList (d .Get ("saas_app.0.scopes" ).(* schema.Set ).List ())
976
- SaasConfig .GroupFilterRegex = d .Get ("saas_app.0.group_filter_regex" ).(string )
977
- SaasConfig .AccessTokenLifetime = d .Get ("saas_app.0.access_token_lifetime" ).(string )
978
- SaasConfig .AllowPKCEWithoutClientSecret = cloudflare .BoolPtr (d .Get ("saas_app.0.allow_pkce_without_client_secret" ).(bool ))
979
- if _ , ok := d .GetOk ("saas_app.0.refresh_token_options" ); ok {
980
- SaasConfig .RefreshTokenOptions = & cloudflare.RefreshTokenOptions {
981
- Lifetime : d .Get ("saas_app.0.refresh_token_options.0.lifetime" ).(string ),
982
- }
983
- }
984
-
985
- if d .HasChange ("saas_app.0.custom_claim" ) {
986
- SaasConfig .CustomClaims = & []cloudflare.OIDCClaimConfig {}
987
- }
982
+ }
988
983
989
- customClaims , _ := d .Get ("saas_app.0.custom_claim" ).([]interface {})
990
- for _ , customClaims := range customClaims {
991
- claimAsMap := customClaims .(map [string ]interface {})
992
- claim := convertOIDCClaimSchemaToStruct (claimAsMap )
993
- * SaasConfig .CustomClaims = append (* SaasConfig .CustomClaims , claim )
994
- }
984
+ customClaims , _ := d .Get ("saas_app.0.custom_claim" ).([]interface {})
985
+ if len (customClaims ) != 0 {
986
+ oidcConfig .CustomClaims = & []cloudflare.OIDCClaimConfig {}
987
+ for _ , customClaims := range customClaims {
988
+ claimAsMap := customClaims .(map [string ]interface {})
989
+ claim := convertOIDCClaimSchemaToStruct (claimAsMap )
990
+ * oidcConfig .CustomClaims = append (* oidcConfig .CustomClaims , claim )
991
+ }
992
+ }
995
993
996
- if _ , ok := d .GetOk ("saas_app.0.hybrid_and_implicit_options" ); ok {
997
- SaasConfig .HybridAndImplicitOptions = & cloudflare.AccessApplicationHybridAndImplicitOptions {
998
- ReturnAccessTokenFromAuthorizationEndpoint : cloudflare .BoolPtr (d .Get ("saas_app.0.hybrid_and_implicit_options.0.return_access_token_from_authorization_endpoint" ).(bool )),
999
- ReturnIDTokenFromAuthorizationEndpoint : cloudflare .BoolPtr (d .Get ("saas_app.0.hybrid_and_implicit_options.0.return_id_token_from_authorization_endpoint" ).(bool )),
1000
- }
1001
- }
1002
- } else {
1003
- SaasConfig .SPEntityID = d .Get ("saas_app.0.sp_entity_id" ).(string )
1004
- SaasConfig .ConsumerServiceUrl = d .Get ("saas_app.0.consumer_service_url" ).(string )
1005
- SaasConfig .NameIDFormat = d .Get ("saas_app.0.name_id_format" ).(string )
1006
- SaasConfig .DefaultRelayState = d .Get ("saas_app.0.default_relay_state" ).(string )
1007
- SaasConfig .NameIDTransformJsonata = d .Get ("saas_app.0.name_id_transform_jsonata" ).(string )
1008
- SaasConfig .SamlAttributeTransformJsonata = d .Get ("saas_app.0.saml_attribute_transform_jsonata" ).(string )
1009
-
1010
- if d .HasChanges ("saas_app.0.custom_attribute" ) {
1011
- SaasConfig .CustomAttributes = & []cloudflare.SAMLAttributeConfig {}
1012
- }
994
+ if _ , ok := d .GetOk ("saas_app.0.hybrid_and_implicit_options" ); ok {
995
+ oidcConfig .HybridAndImplicitOptions = & cloudflare.AccessApplicationHybridAndImplicitOptions {
996
+ ReturnAccessTokenFromAuthorizationEndpoint : cloudflare .BoolPtr (d .Get ("saas_app.0.hybrid_and_implicit_options.0.return_access_token_from_authorization_endpoint" ).(bool )),
997
+ ReturnIDTokenFromAuthorizationEndpoint : cloudflare .BoolPtr (d .Get ("saas_app.0.hybrid_and_implicit_options.0.return_id_token_from_authorization_endpoint" ).(bool )),
998
+ }
999
+ }
1000
+ return & oidcConfig
1001
+ }
1013
1002
1014
- customAttributes , _ := d .Get ("saas_app.0.custom_attribute" ).([]interface {})
1015
- for _ , customAttributes := range customAttributes {
1016
- attributeAsMap := customAttributes .(map [string ]interface {})
1017
- attribute := convertSAMLAttributeSchemaToStruct (attributeAsMap )
1018
- * SaasConfig .CustomAttributes = append (* SaasConfig .CustomAttributes , attribute )
1019
- }
1003
+ func convertSaasSAMLSchemaToStruct (d * schema.ResourceData ) * cloudflare.SaasApplication {
1004
+ var samlConfig cloudflare.SaasApplication
1005
+ samlConfig .AuthType = saasAuthTypeSAML
1006
+ samlConfig .SPEntityID = d .Get ("saas_app.0.sp_entity_id" ).(string )
1007
+ samlConfig .ConsumerServiceUrl = d .Get ("saas_app.0.consumer_service_url" ).(string )
1008
+ samlConfig .NameIDFormat = d .Get ("saas_app.0.name_id_format" ).(string )
1009
+ samlConfig .DefaultRelayState = d .Get ("saas_app.0.default_relay_state" ).(string )
1010
+ samlConfig .NameIDTransformJsonata = d .Get ("saas_app.0.name_id_transform_jsonata" ).(string )
1011
+ samlConfig .SamlAttributeTransformJsonata = d .Get ("saas_app.0.saml_attribute_transform_jsonata" ).(string )
1012
+
1013
+ customAttributes , _ := d .Get ("saas_app.0.custom_attribute" ).([]interface {})
1014
+ if len (customAttributes ) != 0 {
1015
+ samlConfig .CustomAttributes = & []cloudflare.SAMLAttributeConfig {}
1016
+ for _ , customAttributes := range customAttributes {
1017
+ attributeAsMap := customAttributes .(map [string ]interface {})
1018
+ attribute := convertSAMLAttributeSchemaToStruct (attributeAsMap )
1019
+ * samlConfig .CustomAttributes = append (* samlConfig .CustomAttributes , attribute )
1020
1020
}
1021
1021
}
1022
- return & SaasConfig
1022
+ return & samlConfig
1023
+ }
1024
+
1025
+ func convertSaasSchemaToStruct (d * schema.ResourceData ) * cloudflare.SaasApplication {
1026
+ if authType , _ := d .GetOk ("saas_app.0.auth_type" ); authType == "oidc" {
1027
+ return convertSaasOIDCSchemaToStruct (d )
1028
+ } else {
1029
+ return convertSaasSAMLSchemaToStruct (d )
1030
+ }
1023
1031
}
1024
1032
1025
1033
func convertDestinationsToStruct (destinationPayloads []interface {}) ([]cloudflare.AccessDestination , error ) {
0 commit comments