55
66import { AzureWizardPromptStep , nonNullProp , type AzureWizardExecuteStep , type IAzureQuickPickItem , type IWizardOptions } from "@microsoft/vscode-azext-utils" ;
77import { acrDomain , type SupportedRegistries } from "../../constants" ;
8- import { detectRegistryDomain } from "../../utils/imageNameUtils" ;
8+ import { getRegistryDomainFromContext } from "../../utils/imageNameUtils" ;
99import { localize } from "../../utils/localize" ;
1010import { AcrEnableAdminUserConfirmStep } from "./dockerLogin/AcrEnableAdminUserConfirmStep" ;
1111import { AcrEnableAdminUserStep } from "./dockerLogin/AcrEnableAdminUserStep" ;
@@ -23,24 +23,34 @@ export enum RegistryCredentialType {
2323}
2424
2525export class RegistryCredentialsAddConfigurationListStep extends AzureWizardPromptStep < RegistryCredentialsContext > {
26- private hasExistingRegistry ? : boolean ;
26+ private requiresRegistryConfiguration : boolean ;
2727
2828 public async configureBeforePrompt ( context : RegistryCredentialsContext ) : Promise < void > {
29- this . hasExistingRegistry = ! ! context . containerApp ?. configuration ?. registries ?. some ( r => {
29+ const registryDomain : SupportedRegistries | undefined = getRegistryDomainFromContext ( context ) ;
30+ const hasExistingConfiguration : boolean = ! ! context . containerApp ?. configuration ?. registries ?. some ( r => {
3031 if ( ! r . server ) {
3132 return false ;
3233 }
3334
34- const registryDomain : SupportedRegistries | undefined = this . getRegistryDomain ( context ) ;
3535 if ( registryDomain === acrDomain ) {
3636 return r . server === context . registry ?. loginServer ;
37- } else {
37+ } else if ( context . registryName ) {
3838 return r . server === DockerLoginRegistryCredentialsAddConfigurationStep . getThirdPartyLoginServer (
3939 registryDomain ,
4040 nonNullProp ( context , 'registryName' ) ,
4141 ) ;
4242 }
43- } )
43+
44+ // At this point, there is the small possibility of an existing configuration existing that we don't have
45+ // enough information to match. This edge case usually happens for public repositories that are under the same
46+ // private account configuration. The good news is that these public repositories don't actually need a configuration
47+ // to be registered because they are public, so the 'requiresRegistryConfiguration' check should be sufficient to handle these cases.
48+ return false ;
49+ } ) ;
50+
51+ // Rule 1: If we're configuring a new ACR and don't have an existing configuration, we need to create one
52+ // Rule 2: If we're configuring a new third party registry and don't have an existing configuration -- only do so if it's not a public repository. We can detect this with the registryName, username, and secret
53+ this . requiresRegistryConfiguration = ( registryDomain === acrDomain || ( ! ! context . registryName && ! ! context . username && ! ! context . secret ) ) && ! hasExistingConfiguration ;
4454 }
4555
4656 public async prompt ( context : RegistryCredentialsContext ) : Promise < void > {
@@ -51,14 +61,14 @@ export class RegistryCredentialsAddConfigurationListStep extends AzureWizardProm
5161 }
5262
5363 public shouldPrompt ( context : RegistryCredentialsContext ) : boolean {
54- return ! this . hasExistingRegistry && ! context . newRegistryCredentialType ;
64+ return this . requiresRegistryConfiguration && ! context . newRegistryCredentialType ;
5565 }
5666
5767 public async getSubWizard ( context : RegistryCredentialsContext ) : Promise < IWizardOptions < RegistryCredentialsContext > | undefined > {
5868 const promptSteps : AzureWizardPromptStep < RegistryCredentialsContext > [ ] = [ ] ;
5969 const executeSteps : AzureWizardExecuteStep < RegistryCredentialsContext > [ ] = [ ] ;
6070
61- const registryDomain : SupportedRegistries | undefined = this . getRegistryDomain ( context ) ;
71+ const registryDomain : SupportedRegistries | undefined = getRegistryDomainFromContext ( context ) ;
6272 switch ( context . newRegistryCredentialType ) {
6373 case RegistryCredentialType . SystemAssigned :
6474 executeSteps . push (
@@ -86,18 +96,11 @@ export class RegistryCredentialsAddConfigurationListStep extends AzureWizardProm
8696 } ;
8797 }
8898
89- private getRegistryDomain ( context : RegistryCredentialsContext ) : SupportedRegistries | undefined {
90- if ( context . registry ?. loginServer || context . registryName ) {
91- return detectRegistryDomain ( context . registry ?. loginServer || nonNullProp ( context , 'registryName' ) ) ;
92- } else {
93- // If no registries exist, we can assume we're creating a new ACR
94- return acrDomain ;
95- }
96- }
99+
97100
98101 public async getPicks ( context : RegistryCredentialsContext ) : Promise < IAzureQuickPickItem < RegistryCredentialType > [ ] > {
99102 const picks : IAzureQuickPickItem < RegistryCredentialType > [ ] = [ ] ;
100- const registryDomain = this . getRegistryDomain ( context ) ;
103+ const registryDomain = getRegistryDomainFromContext ( context ) ;
101104
102105 if ( registryDomain === acrDomain ) {
103106 picks . push ( {
0 commit comments