Skip to content

Commit 263aa55

Browse files
authored
Update app service rest package (#485)
* Update app service rest package * nit fixes * update package * updating design for sidecar (#486) * update tests
1 parent 66eae17 commit 263aa55

File tree

15 files changed

+153
-125
lines changed

15 files changed

+153
-125
lines changed

__tests__/ActionInputValidator/ValidatorFactory.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('Test Validator Factory', () => {
2626
jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype);
2727
jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix');
2828

29-
let validators = await ValidatorFactory.getValidator(type);
30-
expect(validators[0]).toBeInstanceOf(PublishProfileWebAppValidator);
29+
let validator = await ValidatorFactory.getValidator(type);
30+
expect(validator).toBeInstanceOf(PublishProfileWebAppValidator);
3131
});
3232

3333
it("Get Container Validator for Publish Profile auth flow", async() => {
@@ -42,8 +42,8 @@ describe('Test Validator Factory', () => {
4242
jest.spyOn(PublishProfile, 'getPublishProfile').mockImplementation(() => PublishProfile.prototype);
4343
jest.spyOn(PublishProfile.prototype, 'getAppOS').mockImplementation(async() => 'unix');
4444

45-
let validators = await ValidatorFactory.getValidator(type);
46-
expect(validators[0]).toBeInstanceOf(PublishProfileContainerWebAppValidator);
45+
let validator = await ValidatorFactory.getValidator(type);
46+
expect(validator).toBeInstanceOf(PublishProfileContainerWebAppValidator);
4747
});
4848

4949
});
@@ -70,8 +70,8 @@ describe('Test Validator Factory', () => {
7070
};
7171
});
7272

73-
let validators = await ValidatorFactory.getValidator(type);
74-
expect(validators[0]).toBeInstanceOf(SpnLinuxContainerWebAppValidator);
73+
let validator = await ValidatorFactory.getValidator(type);
74+
expect(validator).toBeInstanceOf(SpnLinuxContainerWebAppValidator);
7575
});
7676

7777
it("Get Linux/Kube Code Validator for SPN auth flow", async() => {
@@ -90,8 +90,8 @@ describe('Test Validator Factory', () => {
9090
};
9191
});
9292

93-
let validators = await ValidatorFactory.getValidator(type);
94-
expect(validators[0]).toBeInstanceOf(SpnLinuxWebAppValidator);
93+
let validator = await ValidatorFactory.getValidator(type);
94+
expect(validator).toBeInstanceOf(SpnLinuxWebAppValidator);
9595
});
9696

9797
it("Get Windows Container Validator for SPN auth flow", async() => {
@@ -111,8 +111,8 @@ describe('Test Validator Factory', () => {
111111
};
112112
});
113113

114-
let validators = await ValidatorFactory.getValidator(type);
115-
expect(validators[0]).toBeInstanceOf(SpnWindowsContainerWebAppValidator);
114+
let validator = await ValidatorFactory.getValidator(type);
115+
expect(validator).toBeInstanceOf(SpnWindowsContainerWebAppValidator);
116116
});
117117

118118
it("Get Windows Code Validator for SPN auth flow", async() => {
@@ -131,8 +131,8 @@ describe('Test Validator Factory', () => {
131131
};
132132
});
133133

134-
let validators = await ValidatorFactory.getValidator(type);
135-
expect(validators[0]).toBeInstanceOf(SpnWindowsWebAppValidator);
134+
let validator = await ValidatorFactory.getValidator(type);
135+
expect(validator).toBeInstanceOf(SpnWindowsWebAppValidator);
136136
});
137137

138138
});

__tests__/DeploymentProvider/DeploymentProviderFactory.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ describe('Test Deployment Provider Factory', () => {
1919
it("Get Code Deployment Provider for Publish Profile auth flow", async() => {
2020
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE;
2121

22-
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
23-
expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider);
22+
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
23+
expect(provider).toBeInstanceOf(WebAppDeploymentProvider);
2424
});
2525

2626
it("Get Container Deployment Provider for Publish Profile auth flow", async() => {
@@ -32,8 +32,8 @@ describe('Test Deployment Provider Factory', () => {
3232

3333
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE;
3434

35-
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
36-
expect(providers[0]).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider);
35+
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
36+
expect(provider).toBeInstanceOf(PublishProfileWebAppContainerDeploymentProvider);
3737
});
3838

3939
});
@@ -48,8 +48,8 @@ describe('Test Deployment Provider Factory', () => {
4848

4949
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN;
5050

51-
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
52-
expect(providers[0]).toBeInstanceOf(WebAppDeploymentProvider);
51+
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
52+
expect(provider).toBeInstanceOf(WebAppDeploymentProvider);
5353
});
5454

5555
it("Get Container Deployment Provider for SPN auth flow", async() => {
@@ -61,8 +61,8 @@ describe('Test Deployment Provider Factory', () => {
6161

6262
let type: DEPLOYMENT_PROVIDER_TYPES = DEPLOYMENT_PROVIDER_TYPES.SPN;
6363

64-
let providers = await DeploymentProviderFactory.getDeploymentProvider(type);
65-
expect(providers[0]).toBeInstanceOf(WebAppContainerDeploymentProvider);
64+
let provider = await DeploymentProviderFactory.getDeploymentProvider(type);
65+
expect(provider).toBeInstanceOf(WebAppContainerDeploymentProvider);
6666
});
6767

6868
});

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ describe('Test azure-webapps-deploy', () => {
3535
}
3636
return '';
3737
});
38-
let getValidatorFactorySpy = jest.spyOn(ValidatorFactory, 'getValidator').mockImplementation(async _type => [new PublishProfileWebAppValidator()]);
38+
let getValidatorFactorySpy = jest.spyOn(ValidatorFactory, 'getValidator').mockImplementation(async _type => new PublishProfileWebAppValidator());
3939
let ValidatorFactoryValidateSpy = jest.spyOn(PublishProfileWebAppValidator.prototype, 'validate');
40-
let getDeploymentProviderSpy = jest.spyOn(DeploymentProviderFactory, 'getDeploymentProvider').mockImplementation(type => [new WebAppDeploymentProvider(type)]);
40+
let getDeploymentProviderSpy = jest.spyOn(DeploymentProviderFactory, 'getDeploymentProvider').mockImplementation(type => new WebAppDeploymentProvider(type));
4141
let deployWebAppStepSpy = jest.spyOn(WebAppDeploymentProvider.prototype, 'DeployWebAppStep');
4242
let updateDeploymentStatusSpy = jest.spyOn(WebAppDeploymentProvider.prototype, 'UpdateDeploymentStatus');
4343

lib/ActionInputValidator/ActionValidators/SpnWebAppSiteContainersValidator.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1111
Object.defineProperty(exports, "__esModule", { value: true });
1212
exports.SpnWebAppSiteContainersValidator = void 0;
1313
const Validations_1 = require("../Validations");
14-
class SpnWebAppSiteContainersValidator {
14+
const SpnLinuxWebAppValidator_1 = require("./SpnLinuxWebAppValidator");
15+
const actionparameters_1 = require("../../actionparameters");
16+
class SpnWebAppSiteContainersValidator extends SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator {
1517
validate() {
18+
const _super = Object.create(null, {
19+
validate: { get: () => super.validate }
20+
});
1621
return __awaiter(this, void 0, void 0, function* () {
22+
let actionParams = actionparameters_1.ActionParameters.getActionParams();
23+
if (!!actionParams.blessedAppSitecontainers) {
24+
yield _super.validate.call(this);
25+
}
1726
(0, Validations_1.validateSiteContainersInputs)();
1827
});
1928
}

lib/ActionInputValidator/ValidatorFactory.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ class ValidatorFactory {
6868
let actionParams = actionparameters_1.ActionParameters.getActionParams();
6969
if (type === BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) {
7070
if (!!actionParams.blessedAppSitecontainers || !!actionParams.siteContainers) {
71-
return [new PublishProfileWebAppSiteContainersValidator_1.PublishProfileWebAppSiteContainersValidator()];
71+
return new PublishProfileWebAppSiteContainersValidator_1.PublishProfileWebAppSiteContainersValidator();
7272
}
7373
else if (!!actionParams.images) {
7474
yield this.setResourceDetails(actionParams);
75-
return [new PublishProfileContainerWebAppValidator_1.PublishProfileContainerWebAppValidator()];
75+
return new PublishProfileContainerWebAppValidator_1.PublishProfileContainerWebAppValidator();
7676
}
7777
else {
7878
try {
@@ -81,7 +81,7 @@ class ValidatorFactory {
8181
catch (error) {
8282
core.warning(`Failed to set resource details: ${error.message}`);
8383
}
84-
return [new PublishProfileWebAppValidator_1.PublishProfileWebAppValidator()];
84+
return new PublishProfileWebAppValidator_1.PublishProfileWebAppValidator();
8585
}
8686
}
8787
else if (type == BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.SPN) {
@@ -90,24 +90,22 @@ class ValidatorFactory {
9090
yield this.getResourceDetails(actionParams);
9191
if (!!actionParams.isLinux) {
9292
if (!!actionParams.siteContainers) {
93-
if (yield this.isBlessedSitecontainerApp(actionParams)) {
94-
return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator(), new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()];
95-
}
96-
return [new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator()];
93+
yield this.setBlessedSitecontainerApp(actionParams);
94+
return new SpnWebAppSiteContainersValidator_1.SpnWebAppSiteContainersValidator();
9795
}
9896
else if (!!actionParams.images || !!actionParams.multiContainerConfigFile) {
99-
return [new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator()];
97+
return new SpnLinuxContainerWebAppValidator_1.SpnLinuxContainerWebAppValidator();
10098
}
10199
else {
102-
return [new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator()];
100+
return new SpnLinuxWebAppValidator_1.SpnLinuxWebAppValidator();
103101
}
104102
}
105103
else {
106104
if (!!actionParams.images) {
107-
return [new SpnWindowsContainerWebAppValidator_1.SpnWindowsContainerWebAppValidator()];
105+
return new SpnWindowsContainerWebAppValidator_1.SpnWindowsContainerWebAppValidator();
108106
}
109107
else {
110-
return [new SpnWindowsWebAppValidator_1.SpnWindowsWebAppValidator()];
108+
return new SpnWindowsWebAppValidator_1.SpnWindowsWebAppValidator();
111109
}
112110
}
113111
}
@@ -133,16 +131,17 @@ class ValidatorFactory {
133131
actionParams.isLinux = appOS.includes(RuntimeConstants_1.default.Unix) || appOS.includes(RuntimeConstants_1.default.Unix.toLowerCase());
134132
});
135133
}
136-
static isBlessedSitecontainerApp(actionParams) {
134+
static setBlessedSitecontainerApp(actionParams) {
137135
return __awaiter(this, void 0, void 0, function* () {
138-
var _a, _b;
136+
var _a;
139137
const appService = new azure_app_service_1.AzureAppService(actionParams.endpoint, actionParams.resourceGroupName, actionParams.appName, actionParams.slotName);
140138
let config = yield appService.getConfiguration();
141139
core.debug(`LinuxFxVersion of app is: ${config.properties.linuxFxVersion}`);
142-
actionParams.blessedAppSitecontainers = (((_a = config.properties.linuxFxVersion) === null || _a === void 0 ? void 0 : _a.startsWith("DOCKER|")) !== true
143-
&& ((_b = config.properties.linuxFxVersion) === null || _b === void 0 ? void 0 : _b.startsWith("COMPOSE|")) !== true
144-
&& config.properties.linuxFxVersion !== "SITECONTAINERS");
145-
return actionParams.blessedAppSitecontainers;
140+
const linuxFxVersion = ((_a = config.properties.linuxFxVersion) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || "";
141+
actionParams.blessedAppSitecontainers = (!linuxFxVersion.startsWith("DOCKER|")
142+
&& !linuxFxVersion.startsWith("COMPOSE|")
143+
&& linuxFxVersion !== "SITECONTAINERS");
144+
core.debug(`Is blessed app sitecontainers: ${actionParams.blessedAppSitecontainers}`);
146145
});
147146
}
148147
}

lib/DeploymentProvider/DeploymentProviderFactory.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,21 @@ class DeploymentProviderFactory {
1111
static getDeploymentProvider(type) {
1212
if (type === BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE) {
1313
if (!!actionparameters_1.ActionParameters.getActionParams().images) {
14-
return [new PublishProfileWebAppContainerDeploymentProvider_1.PublishProfileWebAppContainerDeploymentProvider(type)];
14+
return new PublishProfileWebAppContainerDeploymentProvider_1.PublishProfileWebAppContainerDeploymentProvider(type);
1515
}
1616
else {
17-
return [new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type)];
17+
return new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type);
1818
}
1919
}
2020
else if (type == BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.SPN) {
21-
if (!!actionparameters_1.ActionParameters.getActionParams().blessedAppSitecontainers) {
22-
return [new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type), new WebAppSiteContainersDeploymentProvider_1.WebAppSiteContainersDeploymentProvider(type)];
23-
}
24-
else if (!!actionparameters_1.ActionParameters.getActionParams().siteContainers) {
25-
return [new WebAppSiteContainersDeploymentProvider_1.WebAppSiteContainersDeploymentProvider(type)];
21+
if (!!actionparameters_1.ActionParameters.getActionParams().blessedAppSitecontainers || !!actionparameters_1.ActionParameters.getActionParams().siteContainers) {
22+
return new WebAppSiteContainersDeploymentProvider_1.WebAppSiteContainersDeploymentProvider(type);
2623
}
2724
else if (!!actionparameters_1.ActionParameters.getActionParams().images || (!!actionparameters_1.ActionParameters.getActionParams().isLinux && !!actionparameters_1.ActionParameters.getActionParams().multiContainerConfigFile)) {
28-
return [new WebAppContainerDeployment_1.WebAppContainerDeploymentProvider(type)];
25+
return new WebAppContainerDeployment_1.WebAppContainerDeploymentProvider(type);
2926
}
3027
else {
31-
return [new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type)];
28+
return new WebAppDeploymentProvider_1.WebAppDeploymentProvider(type);
3229
}
3330
}
3431
else {

lib/DeploymentProvider/Providers/WebAppSiteContainersDeploymentProvider.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4343
};
4444
Object.defineProperty(exports, "__esModule", { value: true });
4545
exports.WebAppSiteContainersDeploymentProvider = void 0;
46-
const BaseWebAppDeploymentProvider_1 = require("./BaseWebAppDeploymentProvider");
4746
const SiteContainerDeploymentUtility_1 = require("azure-actions-appservice-rest/Utilities/SiteContainerDeploymentUtility");
4847
const core = __importStar(require("@actions/core"));
49-
class WebAppSiteContainersDeploymentProvider extends BaseWebAppDeploymentProvider_1.BaseWebAppDeploymentProvider {
48+
const WebAppDeploymentProvider_1 = require("./WebAppDeploymentProvider");
49+
class WebAppSiteContainersDeploymentProvider extends WebAppDeploymentProvider_1.WebAppDeploymentProvider {
5050
DeployWebAppStep() {
51+
const _super = Object.create(null, {
52+
DeployWebAppStep: { get: () => super.DeployWebAppStep }
53+
});
5154
return __awaiter(this, void 0, void 0, function* () {
55+
if (!!this.actionParams.blessedAppSitecontainers) {
56+
core.info("Blessed site containers detected, using WebAppDeploymentProvider for deployment.");
57+
yield _super.DeployWebAppStep.call(this);
58+
}
5259
let siteContainerDeploymentUtility = new SiteContainerDeploymentUtility_1.SiteContainerDeploymentUtility(this.appService);
5360
let siteContainers = this.actionParams.siteContainers;
5461
core.info("Updating site containers");
5562
for (let i = 0; i < siteContainers.length; i++) {
5663
let siteContainer = siteContainers[i];
57-
core.info("updating site container: " + siteContainer.getName);
64+
core.info("updating site container: " + siteContainer.getName());
5865
yield siteContainerDeploymentUtility.updateSiteContainer(siteContainer);
5966
}
6067
});

lib/main.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,13 @@ function main() {
7171
type = BaseWebAppDeploymentProvider_1.DEPLOYMENT_PROVIDER_TYPES.PUBLISHPROFILE;
7272
}
7373
// Validate action inputs
74-
let validators = yield ValidatorFactory_1.ValidatorFactory.getValidator(type);
75-
for (const validator of validators) {
76-
yield validator.validate();
77-
}
78-
var deploymentProviders = DeploymentProviderFactory_1.DeploymentProviderFactory.getDeploymentProvider(type);
79-
for (const provider of deploymentProviders) {
80-
core.info("Predeployment Step Started");
81-
yield provider.PreDeploymentStep();
82-
core.info("Deployment Step Started");
83-
yield provider.DeployWebAppStep();
84-
}
74+
let validator = yield ValidatorFactory_1.ValidatorFactory.getValidator(type);
75+
yield validator.validate();
76+
var deploymentProvider = DeploymentProviderFactory_1.DeploymentProviderFactory.getDeploymentProvider(type);
77+
core.info("Predeployment Step Started");
78+
yield deploymentProvider.PreDeploymentStep();
79+
core.info("Deployment Step Started");
80+
yield deploymentProvider.DeployWebAppStep();
8581
}
8682
catch (error) {
8783
isDeploymentSuccess = false;
@@ -95,8 +91,8 @@ function main() {
9591
}
9692
}
9793
finally {
98-
if (deploymentProviders != null) {
99-
yield deploymentProviders[0].UpdateDeploymentStatus(isDeploymentSuccess);
94+
if (deploymentProvider != null) {
95+
yield deploymentProvider.UpdateDeploymentStatus(isDeploymentSuccess);
10096
}
10197
// Reset AZURE_HTTP_USER_AGENT
10298
core.exportVariable('AZURE_HTTP_USER_AGENT', prefix);

0 commit comments

Comments
 (0)