@@ -61,24 +61,66 @@ func applyInto(a AutomationConfig, into *Deployment) error {
61
61
(* into )["ldap" ] = mergedLdap
62
62
}
63
63
64
- if _ , ok := a .Deployment ["oidcProviderConfigs" ]; ok || len (a .OIDCProviderConfigs ) > 0 {
65
- // TODO: this is not merged yet, but only overridden
66
- bytes , err := json .Marshal (a .OIDCProviderConfigs )
67
- if err != nil {
68
- return err
64
+ if len (a .OIDCProviderConfigs ) > 0 {
65
+ deploymentConfigs := make ([]map [string ]any , 0 )
66
+ if configs , ok := a .Deployment ["oidcProviderConfigs" ]; ok {
67
+ configsSlice := cast .ToSlice (configs )
68
+ for _ , config := range configsSlice {
69
+ deploymentConfigs = append (deploymentConfigs , config .(map [string ]any ))
70
+ }
69
71
}
70
72
71
- dst := make ([]map [string ]interface {}, 0 )
72
- err = json .Unmarshal (bytes , & dst )
73
- if err != nil {
74
- return err
73
+ result := make ([]map [string ]any , 0 )
74
+ for _ , config := range a .OIDCProviderConfigs {
75
+ deploymentConfig := findOrCreateEmptyDeploymentConfig (deploymentConfigs , config .AuthNamePrefix )
76
+
77
+ deploymentConfig ["authNamePrefix" ] = config .AuthNamePrefix
78
+ deploymentConfig ["audience" ] = config .Audience
79
+ deploymentConfig ["issuerUri" ] = config .IssuerUri
80
+ deploymentConfig ["userClaim" ] = config .UserClaim
81
+ deploymentConfig ["supportsHumanFlows" ] = config .SupportsHumanFlows
82
+ deploymentConfig ["useAuthorizationClaim" ] = config .UseAuthorizationClaim
83
+
84
+ if config .ClientId == util .MergoDelete {
85
+ delete (deploymentConfig , "clientId" )
86
+ } else {
87
+ deploymentConfig ["clientId" ] = config .ClientId
88
+ }
89
+
90
+ if len (config .RequestedScopes ) == 0 {
91
+ delete (deploymentConfig , "requestedScopes" )
92
+ } else {
93
+ deploymentConfig ["requestedScopes" ] = config .RequestedScopes
94
+ }
95
+
96
+ if config .GroupsClaim == util .MergoDelete {
97
+ delete (deploymentConfig , "groupsClaim" )
98
+ } else {
99
+ deploymentConfig ["groupsClaim" ] = config .GroupsClaim
100
+ }
101
+
102
+ result = append (result , deploymentConfig )
75
103
}
76
- (* into )["oidcProviderConfigs" ] = dst
104
+
105
+ (* into )["oidcProviderConfigs" ] = result
106
+ } else {
107
+ // Clear oidcProviderConfigs if no configs are provided
108
+ delete (* into , "oidcProviderConfigs" )
77
109
}
78
110
79
111
return nil
80
112
}
81
113
114
+ func findOrCreateEmptyDeploymentConfig (deploymentConfigs []map [string ]any , configName string ) map [string ]any {
115
+ for _ , deploymentConfig := range deploymentConfigs {
116
+ if configName == deploymentConfig ["authNamePrefix" ] {
117
+ return deploymentConfig
118
+ }
119
+ }
120
+
121
+ return make (map [string ]any )
122
+ }
123
+
82
124
// EqualsWithoutDeployment returns true if two AutomationConfig objects are meaningful equal by following the following conditions:
83
125
// - Not taking AutomationConfig.Deployment into consideration.
84
126
// - Serializing ac A and ac B to ensure that we remove util.MergoDelete before comparing those two.
@@ -450,9 +492,9 @@ func BuildAutomationConfigFromDeployment(deployment Deployment) (*AutomationConf
450
492
finalAutomationConfig .Ldap = acLdap
451
493
}
452
494
453
- oidcSlice , ok := deployment ["oidcProviderConfigs" ]
495
+ oidcConfigsArray , ok := deployment ["oidcProviderConfigs" ]
454
496
if ok {
455
- oidcMarshalled , err := json .Marshal (oidcSlice )
497
+ oidcMarshalled , err := json .Marshal (oidcConfigsArray )
456
498
if err != nil {
457
499
return nil , err
458
500
}
0 commit comments