Skip to content

Commit

Permalink
Get correct repositoryName from image name (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
formulahendry committed Jun 22, 2018
1 parent a55b7f0 commit d375d7d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
9 changes: 9 additions & 0 deletions src/common/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}'");
Expand Down
39 changes: 0 additions & 39 deletions src/container/acrManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class AcrManager {
throw new UserCancelledError();
}

this.loginToAcr(acrRegistryItem.registry, acrRegistryItem.azureSubscription);

return acrTagItem.description;
}

Expand Down Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/edge/edgeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,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")}}`;
Expand Down

0 comments on commit d375d7d

Please sign in to comment.