33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import { RegistryCredentials , Secret } from "@azure/arm-appcontainers" ;
67import { AzureWizardExecuteStep , nonNullProp } from "@microsoft/vscode-azext-utils" ;
8+ import * as deepEqual from "deep-eql" ;
79import type { Progress } from "vscode" ;
810import { ext } from "../../../extensionVariables" ;
911import { ContainerAppModel , getContainerEnvelopeWithSecrets } from "../../../tree/ContainerAppItem" ;
@@ -15,11 +17,19 @@ export class UpdateRegistryAndSecretsStep extends AzureWizardExecuteStep<UpdateI
1517 public priority : number = 480 ;
1618
1719 public async execute ( context : UpdateImageContext , progress : Progress < { message ?: string | undefined ; increment ?: number | undefined } > ) : Promise < void > {
18- progress . report ( { message : localize ( 'configuringSecrets' , 'Configuring registry secrets...' ) } ) ;
19-
2020 const containerApp : ContainerAppModel = nonNullProp ( context , 'containerApp' ) ;
2121 const containerAppEnvelope = await getContainerEnvelopeWithSecrets ( context , context . subscription , containerApp ) ;
2222
23+ // If the credentials have not changed, we can skip this update
24+ if (
25+ this . areSecretsDeepEqual ( containerAppEnvelope . configuration . secrets , context . secrets ) &&
26+ this . areRegistriesDeepEqual ( containerAppEnvelope . configuration . registries , context . registries )
27+ ) {
28+ return ;
29+ }
30+
31+ progress . report ( { message : localize ( 'configuringSecrets' , 'Configuring registry secrets...' ) } ) ;
32+
2333 containerAppEnvelope . configuration . secrets = context . secrets ;
2434 containerAppEnvelope . configuration . registries = context . registries ;
2535
@@ -31,4 +41,22 @@ export class UpdateRegistryAndSecretsStep extends AzureWizardExecuteStep<UpdateI
3141 public shouldExecute ( context : UpdateImageContext ) : boolean {
3242 return ! ! context . registries && ! ! context . secrets ;
3343 }
44+
45+ private areSecretsDeepEqual ( originalSecrets : Secret [ ] | undefined , newSecrets : Secret [ ] | undefined ) : boolean {
46+ originalSecrets ?. sort ( ( a , b ) => sortAlphabeticallyByKey ( a , b , 'name' ) ) ;
47+ newSecrets ?. sort ( ( a , b ) => sortAlphabeticallyByKey ( a , b , 'name' ) ) ;
48+ return deepEqual ( originalSecrets , newSecrets ) ;
49+ }
50+
51+ private areRegistriesDeepEqual ( originalRegistries : RegistryCredentials [ ] | undefined , newRegistries : RegistryCredentials [ ] | undefined ) : boolean {
52+ originalRegistries ?. sort ( ( a , b ) => sortAlphabeticallyByKey ( a , b , 'passwordSecretRef' ) ) ;
53+ newRegistries ?. sort ( ( a , b ) => sortAlphabeticallyByKey ( a , b , 'passwordSecretRef' ) ) ;
54+ return deepEqual ( originalRegistries , newRegistries ) ;
55+ }
56+ }
57+
58+ function sortAlphabeticallyByKey < T extends Secret | RegistryCredentials > ( a : T , b : T , key : keyof T ) : number {
59+ const valOne = nonNullProp ( a , key ) as string ;
60+ const valTwo = nonNullProp ( b , key ) as string ;
61+ return valOne . localeCompare ( valTwo ) ;
3462}
0 commit comments