@@ -51,6 +51,7 @@ interface Change {
51
51
[ mutation : string ] : string
52
52
} >
53
53
networkPoliciesMigration ?: boolean
54
+ teamSettingsMigration ?: boolean
54
55
teamResourceQuotaMigration ?: boolean
55
56
buildImageNameMigration ?: boolean
56
57
policiesMigration ?: boolean
@@ -303,6 +304,67 @@ const networkPoliciesMigration = async (values: Record<string, any>): Promise<vo
303
304
)
304
305
}
305
306
307
+ const teamSettingsMigration = ( values : Record < string , any > ) : void => {
308
+ const teams : Array < string > = Object . keys ( values ?. teamConfig as Record < string , any > )
309
+
310
+ teams . map ( ( teamName ) => {
311
+ // Get the alerts block for the team and remove email and opsgenie
312
+ const alerts = get ( values , `teamConfig.${ teamName } .settings.alerts` )
313
+ if ( alerts ?. email ) unset ( alerts , 'email' )
314
+ if ( alerts ?. opsgenie ) unset ( alerts , 'opsgenie' )
315
+ // Get the selfService block for the team
316
+ const selfService = get ( values , `teamConfig.${ teamName } .settings.selfService` )
317
+ if ( ! selfService ) return
318
+
319
+ // Initialize the new teamMembers structure with default boolean values
320
+ const teamMembers = {
321
+ createServices : false ,
322
+ editSecurityPolicies : false ,
323
+ useCloudShell : false ,
324
+ downloadKubeconfig : false ,
325
+ downloadDockerLogin : false ,
326
+ }
327
+
328
+ // Map selfService.service.ingress -> teamMembers.createServices
329
+ const servicePermissions = get ( selfService , 'service' , [ ] )
330
+ if ( Array . isArray ( servicePermissions ) && servicePermissions . includes ( 'ingress' ) ) {
331
+ teamMembers . createServices = true
332
+ }
333
+
334
+ // Map selfService.access keys to corresponding teamMembers fields
335
+ // - downloadKubeConfig -> downloadKubeconfig
336
+ // - downloadDockerConfig -> downloadDockerLogin
337
+ // - shell -> useCloudShell
338
+ const accessPermissions = get ( selfService , 'access' , [ ] )
339
+ if ( Array . isArray ( accessPermissions ) ) {
340
+ if ( accessPermissions . includes ( 'downloadKubeConfig' ) ) {
341
+ teamMembers . downloadKubeconfig = true
342
+ }
343
+ if ( accessPermissions . includes ( 'downloadDockerConfig' ) ) {
344
+ teamMembers . downloadDockerLogin = true
345
+ }
346
+ if ( accessPermissions . includes ( 'shell' ) ) {
347
+ teamMembers . useCloudShell = true
348
+ }
349
+ }
350
+
351
+ // Map selfService.policies.edit_policies -> teamMembers.editSecurityPolicies.
352
+ // Note: In the source schema, the string "edit policies" is used.
353
+ const policies = get ( selfService , 'policies' , [ ] )
354
+ if ( Array . isArray ( policies ) && policies . includes ( 'edit policies' ) ) {
355
+ teamMembers . editSecurityPolicies = true
356
+ }
357
+
358
+ // Set the new teamMembers object on selfService
359
+ set ( selfService , 'teamMembers' , teamMembers )
360
+
361
+ unset ( selfService , 'service' )
362
+ unset ( selfService , 'access' )
363
+ unset ( selfService , 'policies' )
364
+ unset ( selfService , 'apps' )
365
+ } )
366
+ }
367
+
306
368
export const getBuildName = ( name : string , tag : string ) : string => {
307
369
return `${ name } -${ tag } `
308
370
. toLowerCase ( )
@@ -437,6 +499,7 @@ export const applyChanges = async (
437
499
}
438
500
439
501
if ( c . networkPoliciesMigration ) await networkPoliciesMigration ( values )
502
+ if ( c . teamSettingsMigration ) teamSettingsMigration ( values )
440
503
if ( c . teamResourceQuotaMigration ) teamResourceQuotaMigration ( values )
441
504
if ( c . buildImageNameMigration ) await buildImageNameMigration ( values )
442
505
if ( c . policiesMigration ) await policiesMigration ( )
0 commit comments