Skip to content

Commit

Permalink
Refactored env name sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
harryli0108 committed Jan 24, 2024
1 parent 8466af4 commit 93284c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
9 changes: 4 additions & 5 deletions azurecontainerapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,9 @@ export class azurecontainerapps {

// See if we can reuse an existing Container App environment found in the resource group
if (this.util.isNullOrEmpty(containerAppEnvironment)) {
let existingContainerAppEnvironment: string = await this.appHelper.getExistingContainerAppEnvironment(resourceGroup);
const existingContainerAppEnvironment: string = await this.appHelper.getExistingContainerAppEnvironment(resourceGroup);
if (!this.util.isNullOrEmpty(existingContainerAppEnvironment)) {
this.toolHelper.writeInfo(`Existing Container App environment found in resource group: ${existingContainerAppEnvironment}`);
existingContainerAppEnvironment = existingContainerAppEnvironment.replace(/(\r\n|\n|\r)/gm, "");
return existingContainerAppEnvironment
}
}
Expand All @@ -363,7 +362,7 @@ export class azurecontainerapps {
if (!containerAppEnvironmentExists) {
await this.appHelper.createContainerAppEnvironment(containerAppEnvironment, resourceGroup, location);
}
containerAppEnvironment = containerAppEnvironment.replace(/(\r\n|\n|\r)/gm, "");

return containerAppEnvironment;
}

Expand Down Expand Up @@ -607,12 +606,12 @@ export class azurecontainerapps {
}

const environmentVariables: string = this.toolHelper.getInput('environmentVariables', false);
const cappUpdateCommandUsed: boolean = this.noIngressUpdate || (!this.noIngressUpdate && !this.adminCredentialsProvided)
const isCappUpdateCommandUsed: boolean = this.noIngressUpdate || (!this.noIngressUpdate && !this.adminCredentialsProvided)
// Add user-specified environment variables
if (!this.util.isNullOrEmpty(environmentVariables)) {
// The --replace-env-vars flag is only used for the 'update' command,
// otherwise --env-vars is used for 'create' and 'up'
if (cappUpdateCommandUsed) {
if (isCappUpdateCommandUsed) {
this.commandLineArgs.push(`--replace-env-vars ${environmentVariables}`);
} else {
this.commandLineArgs.push(`--env-vars ${environmentVariables}`);
Expand Down
11 changes: 4 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ var azurecontainerapps = /** @class */ (function () {
existingContainerAppEnvironment = _a.sent();
if (!this.util.isNullOrEmpty(existingContainerAppEnvironment)) {
this.toolHelper.writeInfo("Existing Container App environment found in resource group: ".concat(existingContainerAppEnvironment));
existingContainerAppEnvironment = existingContainerAppEnvironment.replace(/(\r\n|\n|\r)/gm, "");
return [2 /*return*/, existingContainerAppEnvironment];
}
_a.label = 2;
Expand All @@ -418,9 +417,7 @@ var azurecontainerapps = /** @class */ (function () {
case 4:
_a.sent();
_a.label = 5;
case 5:
containerAppEnvironment = containerAppEnvironment.replace(/(\r\n|\n|\r)/gm, "");
return [2 /*return*/, containerAppEnvironment];
case 5: return [2 /*return*/, containerAppEnvironment];
}
});
});
Expand Down Expand Up @@ -693,12 +690,12 @@ var azurecontainerapps = /** @class */ (function () {
}
}
var environmentVariables = this.toolHelper.getInput('environmentVariables', false);
var cappUpdateCommandUsed = this.noIngressUpdate || (!this.noIngressUpdate && !this.adminCredentialsProvided);
var isCappUpdateCommandUsed = this.noIngressUpdate || (!this.noIngressUpdate && !this.adminCredentialsProvided);
// Add user-specified environment variables
if (!this.util.isNullOrEmpty(environmentVariables)) {
// The --replace-env-vars flag is only used for the 'update' command,
// otherwise --env-vars is used for 'create' and 'up'
if (cappUpdateCommandUsed) {
if (isCappUpdateCommandUsed) {
this.commandLineArgs.push("--replace-env-vars ".concat(environmentVariables));
}
else {
Expand Down Expand Up @@ -5226,7 +5223,7 @@ var ContainerAppHelper = /** @class */ (function () {
return [4 /*yield*/, util.execute(command)];
case 2:
executionResult = _a.sent();
return [2 /*return*/, executionResult.exitCode === 0 ? executionResult.stdout : null];
return [2 /*return*/, executionResult.exitCode === 0 ? executionResult.stdout.replace(/(\r\n|\n|\r)/gm, "") : null];
case 3:
err_13 = _a.sent();
toolHelper.writeInfo(err_13.message);
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerAppHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class ContainerAppHelper {
try {
let command = `az containerapp env list -g ${resourceGroup} --query "[0].name"`
let executionResult = await util.execute(command);
return executionResult.exitCode === 0 ? executionResult.stdout : null;
return executionResult.exitCode === 0 ? executionResult.stdout.replace(/(\r\n|\n|\r)/gm, "") : null;
} catch (err) {
toolHelper.writeInfo(err.message);
return null;
Expand Down

0 comments on commit 93284c9

Please sign in to comment.