diff --git a/src/common/utility.ts b/src/common/utility.ts index 1910575e..8703b38c 100644 --- a/src/common/utility.ts +++ b/src/common/utility.ts @@ -389,6 +389,15 @@ export class Utility { return hostname; } + public static getRepositoryNameFromImageName(imageName: string): string { + const index = imageName.lastIndexOf(":"); + if (index === -1) { + return imageName; + } else { + return imageName.substring(0, index); + } + } + private static getLocalRegistryState(): ContainerState { try { const isRunning = Executor.execSync("docker inspect registry --format='{{.State.Running}}'"); diff --git a/src/container/acrManager.ts b/src/container/acrManager.ts index dee72d70..4abb6f0b 100644 --- a/src/container/acrManager.ts +++ b/src/container/acrManager.ts @@ -39,8 +39,6 @@ export class AcrManager { throw new UserCancelledError(); } - this.loginToAcr(acrRegistryItem.registry, acrRegistryItem.azureSubscription); - return acrTagItem.description; } @@ -230,41 +228,4 @@ export class AcrManager { throw error; } } - - private async loginToAcr(registry: Registry, azureSubscription: AzureSubscription) { - try { - const adminUserEnabled: boolean = registry.adminUserEnabled; - const registryUrl: string = registry.loginServer; - const loginMessage = adminUserEnabled ? `Looks like the registry "${registryUrl}" has admin user enabled. ` - + `Would you like to add the admin user credentials to IoT Edge runtime?` - : `Looks like the registry "${registryUrl}" does not have admin user enabled. ` - + `Would you like to enable admin user and add the admin user credentials to IoT Edge runtime?`; - const option: string = await vscode.window.showInformationMessage(loginMessage, "Yes", "No"); - if (option === "Yes") { - vscode.window.withProgress({ title: `Adding registry "${registryUrl}" credentials to IoT Edge runtime...`, location: vscode.ProgressLocation.Window }, async (progress) => { - const registryName: string = registry.name; - const resourceGroup: string = registry.id.slice(registry.id.toLowerCase().search("resourcegroups/") + "resourcegroups/".length, registry.id.toLowerCase().search("/providers/")); - const client = new ContainerRegistryManagementClient( - azureSubscription.session.credentials, - azureSubscription.subscription.subscriptionId!, - ); - - if (!adminUserEnabled) { - progress.report({ message: `Enabling admin user for registry "${registryUrl}"...` }); - await client.registries.update(resourceGroup, registryName, { adminUserEnabled: true }); - } - - progress.report({ message: `Fetching admin user credentials for registry "${registryUrl}"...` }); - const creds: RegistryListCredentialsResult = await client.registries.listCredentials(resourceGroup, registryName); - const username: string = creds.username; - const password: string = creds.passwords[0].value; - - Executor.runInTerminal(Utility.adjustTerminalCommand(`iotedgectl login --address ${registryUrl} --username ${username} --password ${password}`)); - }); - } - } catch (error) { - error.message = `Error fetching registry credentials: ${error.message}`; - throw error; - } - } } diff --git a/src/edge/edgeManager.ts b/src/edge/edgeManager.ts index 56d45909..e05a2e22 100644 --- a/src/edge/edgeManager.ts +++ b/src/edge/edgeManager.ts @@ -352,8 +352,10 @@ export class EdgeManager { if (template === Constants.ACR_MODULE) { const acrManager = new AcrManager(); imageName = await acrManager.selectAcrImage(); + repositoryName = Utility.getRepositoryNameFromImageName(imageName); } else if (template === Constants.EXISTING_MODULE) { imageName = await Utility.showInputBox(Constants.imagePattern, Constants.imagePrompt); + repositoryName = Utility.getRepositoryNameFromImageName(imageName); } else { repositoryName = await this.inputRepository(module); imageName = `\${${Utility.getModuleKey(module, "amd64")}}`;