Skip to content

Commit

Permalink
Merge branch 'snehapar/Remove-hardcoded-location' into snehpar/test-oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
snehapar9 committed Nov 13, 2023
2 parents 65c009f + 601c03d commit a27cb86
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 68 deletions.
49 changes: 26 additions & 23 deletions azurecontainerapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,37 +235,40 @@ 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 (!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){
location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup);
return location;
}
}
if (!this.util.isNullOrEmpty(location)) {
return location;
}

// Check if Container App Environment exists in the resource group provided and get the location
if (doesContainerAppEnvironmentExist) {
location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup);
// 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(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;

}

/**
Expand Down
89 changes: 45 additions & 44 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var azurecontainerapps = /** @class */ (function () {
this.toolHelper.setFailed(err_1.message);
this.telemetryHelper.setFailedResult(err_1.message);
return [3 /*break*/, 14];
case 12:
case 12:
// If telemetry is enabled, will log metadata for this task run
return [4 /*yield*/, this.telemetryHelper.sendLogs()];
case 13:
Expand Down Expand Up @@ -256,49 +256,51 @@ 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:
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:
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 = false;
_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 = false;
_c.label = 10;
case 10:
doesContainerAppEnvironmentExist = _b;
if (!doesContainerAppEnvironmentExist) return [3 /*break*/, 12];
return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup)];
case 11:
Expand All @@ -308,8 +310,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];
}
});
});
Expand Down Expand Up @@ -476,7 +477,7 @@ var azurecontainerapps = /** @class */ (function () {
this.toolHelper.writeInfo("Dockerfile found at root of application source.");
dockerfilePath = rootDockerfilePath;
return [3 /*break*/, 3];
case 1:
case 1:
// No Dockerfile found or provided, build the image using the builder
return [4 /*yield*/, this.buildImageFromBuilderAsync(this.appSourcePath, this.imageToBuild)];
case 2:
Expand All @@ -495,7 +496,7 @@ var azurecontainerapps = /** @class */ (function () {
// Build the image from the provided/discovered Dockerfile
_a.sent();
_a.label = 7;
case 7:
case 7:
// Push the image to the Container Registry
return [4 /*yield*/, this.registryHelper.pushImageToContainerRegistry(this.imageToBuild)];
case 8:
Expand All @@ -516,7 +517,7 @@ var azurecontainerapps = /** @class */ (function () {
var environmentVariables, runtimeStack, runtimeStackSplit, platformName, platformVersion, builderStack;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
case 0:
// Install the pack CLI
return [4 /*yield*/, this.appHelper.installPackCliAsync()];
case 1:
Expand Down Expand Up @@ -673,7 +674,7 @@ var azurecontainerapps = /** @class */ (function () {
case 3:
_a.sent();
return [3 /*break*/, 6];
case 4:
case 4:
// Create the Container App from command line arguments
return [4 /*yield*/, this.appHelper.createContainerApp(this.containerAppName, this.resourceGroup, this.containerAppEnvironment, this.commandLineArgs)];
case 5:
Expand All @@ -696,7 +697,7 @@ var azurecontainerapps = /** @class */ (function () {
case 10:
_a.sent();
_a.label = 11;
case 11:
case 11:
// Update the Container App using the 'update' command
return [4 /*yield*/, this.appHelper.updateContainerApp(this.containerAppName, this.resourceGroup, this.commandLineArgs)];
case 12:
Expand All @@ -709,7 +710,7 @@ var azurecontainerapps = /** @class */ (function () {
case 14:
_a.sent();
return [3 /*break*/, 17];
case 15:
case 15:
// Update the Container App using the 'up' command
return [4 /*yield*/, this.appHelper.updateContainerAppWithUp(this.containerAppName, this.resourceGroup, this.commandLineArgs, this.ingress, this.targetPort)];
case 16:
Expand Down Expand Up @@ -1290,8 +1291,8 @@ class OidcClient {
const res = yield httpclient
.getJson(id_token_url)
.catch(error => {
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
Error Message: ${error.message}`);
});
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
Expand Down Expand Up @@ -4995,7 +4996,7 @@ var ContainerAppHelper = /** @class */ (function () {
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
command = "az containerapp env show -g " + resourceGroup + " -o none -n " + containerAppEnvironment;
command = "az containerapp env show -o none -g " + resourceGroup + " -n " + containerAppEnvironment;
return [4 /*yield*/, util.execute(command)];
case 2:
executionResult = _a.sent();
Expand Down Expand Up @@ -6157,7 +6158,7 @@ module.exports = require("util");
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/
/******/ // The require function
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
Expand All @@ -6171,7 +6172,7 @@ module.exports = require("util");
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
Expand All @@ -6180,23 +6181,23 @@ module.exports = require("util");
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
/******/ }
/******/
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/******/
/************************************************************************/
/******/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(3238);
/******/ module.exports = __webpack_exports__;
/******/
/******/
/******/ })()
;
2 changes: 1 addition & 1 deletion src/ContainerAppHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class ContainerAppHelper {
public async doesContainerAppEnvironmentExist(containerAppEnvironment: string, resourceGroup: string): Promise<boolean> {
toolHelper.writeDebug(`Attempting to determine if Container App Environment with name "${containerAppEnvironment}" exists in resource group "${resourceGroup}"`);
try {
let command = `az containerapp env show -g ${resourceGroup} -o none -n ${containerAppEnvironment}`;
let command = `az containerapp env show -o none -g ${resourceGroup} -n ${containerAppEnvironment}`;
let executionResult = await util.execute(command);
return executionResult.exitCode === 0;
} catch (err) {
Expand Down

0 comments on commit a27cb86

Please sign in to comment.