From e3831ca1f97a5e5655189e93c6a9f6c1b0785c29 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Sun, 12 Nov 2023 15:21:45 -0800 Subject: [PATCH 1/3] Refactor --- azurecontainerapps.ts | 13 ++++++------ dist/index.js | 46 +++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 9fde8924..fb883a3a 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -235,27 +235,26 @@ export class azurecontainerapps { let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); - // If no location was provided, attempt to discover the location of the existing Container App - // or Container App Environment in the resource group or use the default location. - if (this.util.isNullOrEmpty(location)) { + // If no location was provided, attempt to discover the location of the existing Container App Environment linked to the Container App + // or Container App Environment provided in the resource group or use the default location. + if (this.util.isNullOrEmpty(location)) { if (!this.util.isNullOrEmpty(resourceGroup)) { // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); - // Check if Container App Environment is provided and exits in the resource group provided - let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : null; if (doesContainerAppExist) { // Get the name of the Container App Environment linked to the Container App var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); // Check if environment exists in the resource group provided and get the location var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : null; - if (doesContainerAppEnvironmentExistInResourceGroup){ + if (doesContainerAppEnvironmentExistInResourceGroup) { // Get the location of the Container App Environment linked to the Container App location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); return location; } } - // Check if Container App Environment exists in the resource group provided and get the location + // Check if Container App Environment is provided and exits in the resource group provided and get the location + let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : null; if (doesContainerAppEnvironmentExist) { location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); return location; diff --git a/dist/index.js b/dist/index.js index dd2aad1f..3f6aeab1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -264,7 +264,7 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.getLocation = function () { return __awaiter(this, void 0, void 0, function () { - var location, resourceGroup, containerAppEnvironment, doesContainerAppExist, doesContainerAppEnvironmentExist, _a, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _b; + var location, resourceGroup, containerAppEnvironment, doesContainerAppExist, environmentName, doesContainerAppEnvironmentExistInResourceGroup, _a, doesContainerAppEnvironmentExist, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: @@ -276,37 +276,37 @@ var azurecontainerapps = /** @class */ (function () { return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; case 1: doesContainerAppExist = _c.sent(); - if (!!this.util.isNullOrEmpty(containerAppEnvironment)) return [3 /*break*/, 3]; - return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup)]; + if (!doesContainerAppExist) return [3 /*break*/, 7]; + return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; case 2: - _a = _c.sent(); - return [3 /*break*/, 4]; + environmentName = _c.sent(); + if (!!this.util.isNullOrEmpty(environmentName)) return [3 /*break*/, 4]; + return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup)]; case 3: - _a = null; - _c.label = 4; + _a = _c.sent(); + return [3 /*break*/, 5]; case 4: - doesContainerAppEnvironmentExist = _a; - if (!doesContainerAppExist) return [3 /*break*/, 10]; - return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; + _a = null; + _c.label = 5; case 5: - environmentName = _c.sent(); - if (!!this.util.isNullOrEmpty(environmentName)) return [3 /*break*/, 7]; - return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup)]; - case 6: - _b = _c.sent(); - return [3 /*break*/, 8]; - case 7: - _b = null; - _c.label = 8; - case 8: - doesContainerAppEnvironmentExistInResourceGroup = _b; - if (!doesContainerAppEnvironmentExistInResourceGroup) return [3 /*break*/, 10]; + doesContainerAppEnvironmentExistInResourceGroup = _a; + if (!doesContainerAppEnvironmentExistInResourceGroup) return [3 /*break*/, 7]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup)]; - case 9: + case 6: // Get the location of the Container App Environment linked to the Container App location = _c.sent(); return [2 /*return*/, location]; + case 7: + if (!!this.util.isNullOrEmpty(containerAppEnvironment)) return [3 /*break*/, 9]; + return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup)]; + case 8: + _b = _c.sent(); + return [3 /*break*/, 10]; + case 9: + _b = null; + _c.label = 10; case 10: + doesContainerAppEnvironmentExist = _b; if (!doesContainerAppEnvironmentExist) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup)]; case 11: From ecc33566f4fffe724c058129e9760a68c5c43ad2 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Sun, 12 Nov 2023 15:44:52 -0800 Subject: [PATCH 2/3] Reorder arguments --- dist/index.js | 2 +- src/ContainerAppHelper.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3f6aeab1..cda04011 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5003,7 +5003,7 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "az containerapp env show -n " + containerAppEnvironment + " -g " + resourceGroup + " -o none"; + command = "az containerapp env show -o none -g " + resourceGroup + " -n " + containerAppEnvironment; return [4 /*yield*/, util.execute(command)]; case 2: executionResult = _a.sent(); diff --git a/src/ContainerAppHelper.ts b/src/ContainerAppHelper.ts index 9a107736..58ecdd8b 100644 --- a/src/ContainerAppHelper.ts +++ b/src/ContainerAppHelper.ts @@ -194,7 +194,7 @@ export class ContainerAppHelper { public async doesContainerAppEnvironmentExist(containerAppEnvironment: string, resourceGroup: string): Promise { toolHelper.writeDebug(`Attempting to determine if Container App Environment with name "${containerAppEnvironment}" exists in resource group "${resourceGroup}"`); try { - let command = `az containerapp env show -n ${containerAppEnvironment} -g ${resourceGroup} -o none`; + let command = `az containerapp env show -o none -g ${resourceGroup} -n ${containerAppEnvironment}`; let executionResult = await util.execute(command); return executionResult.exitCode === 0; } catch (err) { From 601c03dc9f3ac6df7ae3c90636d482fbfa5d4403 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Mon, 13 Nov 2023 13:14:58 -0800 Subject: [PATCH 3/3] Address PR comments --- azurecontainerapps.ts | 45 +++++++++++++++++++++++-------------------- dist/index.js | 11 ++++++----- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index fb883a3a..9b8e0933 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -235,37 +235,40 @@ export class azurecontainerapps { let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); + if (!this.util.isNullOrEmpty(location)) { + return location; + } + // If no location was provided, attempt to discover the location of the existing Container App Environment linked to the Container App // or Container App Environment provided in the resource group or use the default location. - if (this.util.isNullOrEmpty(location)) { - if (!this.util.isNullOrEmpty(resourceGroup)) { - // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it - let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); - if (doesContainerAppExist) { - // Get the name of the Container App Environment linked to the Container App - var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); - // Check if environment exists in the resource group provided and get the location - var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : null; - if (doesContainerAppEnvironmentExistInResourceGroup) { - // Get the location of the Container App Environment linked to the Container App - location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); - return location; - } - } - // Check if Container App Environment is provided and exits in the resource group provided and get the location - let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : null; - if (doesContainerAppEnvironmentExist) { - location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); + if (!this.util.isNullOrEmpty(resourceGroup)) { + // Check if Container App exists in the resource group provided and get the location from the Container App Environment linked to it + let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); + if (doesContainerAppExist) { + // Get the name of the Container App Environment linked to the Container App + var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); + // Check if environment exists in the resource group provided and get the location + var doesContainerAppEnvironmentExistInResourceGroup = !this.util.isNullOrEmpty(environmentName) ? await this.appHelper.doesContainerAppEnvironmentExist(environmentName, resourceGroup) : false; + if (doesContainerAppEnvironmentExistInResourceGroup) { + // Get the location of the Container App Environment linked to the Container App + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); return location; } } - // Get the default location for if the Container App or Container App Environment was not found in the resource group provided. - location = await this.appHelper.getDefaultContainerAppLocation(); + // Check if Container App Environment is provided and exits in the resource group provided and get the location + let doesContainerAppEnvironmentExist = !this.util.isNullOrEmpty(containerAppEnvironment) ? await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup) : false; + if (doesContainerAppEnvironmentExist) { + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); + return location; + } } + // Get the default location for if the Container App or Container App Environment was not found in the resource group provided. + location = await this.appHelper.getDefaultContainerAppLocation(); return location; + } /** diff --git a/dist/index.js b/dist/index.js index cda04011..9dbc5bc5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -271,7 +271,9 @@ var azurecontainerapps = /** @class */ (function () { location = this.toolHelper.getInput('location', false); resourceGroup = this.toolHelper.getInput('resourceGroup', false); containerAppEnvironment = this.toolHelper.getInput('containerAppEnvironment', false); - if (!this.util.isNullOrEmpty(location)) return [3 /*break*/, 14]; + if (!this.util.isNullOrEmpty(location)) { + return [2 /*return*/, location]; + } if (!!this.util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 12]; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; case 1: @@ -286,7 +288,7 @@ var azurecontainerapps = /** @class */ (function () { _a = _c.sent(); return [3 /*break*/, 5]; case 4: - _a = null; + _a = false; _c.label = 5; case 5: doesContainerAppEnvironmentExistInResourceGroup = _a; @@ -303,7 +305,7 @@ var azurecontainerapps = /** @class */ (function () { _b = _c.sent(); return [3 /*break*/, 10]; case 9: - _b = null; + _b = false; _c.label = 10; case 10: doesContainerAppEnvironmentExist = _b; @@ -316,8 +318,7 @@ var azurecontainerapps = /** @class */ (function () { case 13: // Get the default location for if the Container App or Container App Environment was not found in the resource group provided. location = _c.sent(); - _c.label = 14; - case 14: return [2 /*return*/, location]; + return [2 /*return*/, location]; } }); });