Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
],
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-parameter-properties": 0,
"@typescript-eslint/explicit-member-accessibility": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-use-before-define": 0
"@typescript-eslint/no-parameter-properties": 0
}
}
30 changes: 15 additions & 15 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
export const constants = {
bearer: 'Bearer ',
functionAppApiPath: '/api/',
functionAppDomain: '.azurewebsites.net',
functionsAdminApiPath: '/admin/functions/',
functionsApiPath: '/api/functions',
jsonContentType: 'application/json',
logInvocationsApiPath: '/azurejobs/api/functions/definitions/',
logOutputApiPath: '/azurejobs/api/log/output/',
logStreamApiPath: '/api/logstream/application/functions/function/',
masterKeyApiPath: '/api/functions/admin/masterkey',
providerName: 'azure',
scmCommandApiPath: '/api/command',
scmDomain: '.scm.azurewebsites.net',
scmVfsPath: '/api/vfs/site/wwwroot/',
scmZipDeployApiPath: '/api/zipdeploy'
bearer: "Bearer ",
functionAppApiPath: "/api/",
functionAppDomain: ".azurewebsites.net",
functionsAdminApiPath: "/admin/functions/",
functionsApiPath: "/api/functions",
jsonContentType: "application/json",
logInvocationsApiPath: "/azurejobs/api/functions/definitions/",
logOutputApiPath: "/azurejobs/api/log/output/",
logStreamApiPath: "/api/logstream/application/functions/function/",
masterKeyApiPath: "/api/functions/admin/masterkey",
providerName: "azure",
scmCommandApiPath: "/api/command",
scmDomain: ".scm.azurewebsites.net",
scmVfsPath: "/api/vfs/site/wwwroot/",
scmZipDeployApiPath: "/api/zipdeploy"
};

export default constants;
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ This way only one plugin needs to be added to the service in order to get access
whole provider implementation.
*/

import Serverless from 'serverless';
import AzureProvider from './provider/azureProvider';
import { AzureInvoke } from './plugins/invoke/azureInvoke';
import { AzureLogs } from './plugins/logs/azureLogs';
import { AzureRemove } from './plugins/remove/azureRemove';
import { AzurePackage } from './plugins/package/azurePackage';
import { AzureDeployPlugin } from './plugins/deploy/azureDeployPlugin';
import { AzureLoginPlugin } from './plugins/login/loginPlugin';
import { AzureApimServicePlugin } from './plugins/apim/apimServicePlugin';
import { AzureApimFunctionPlugin } from './plugins/apim/apimFunctionPlugin';
import Serverless from "serverless";
import AzureProvider from "./provider/azureProvider";
import { AzureInvoke } from "./plugins/invoke/azureInvoke";
import { AzureLogs } from "./plugins/logs/azureLogs";
import { AzureRemove } from "./plugins/remove/azureRemove";
import { AzurePackage } from "./plugins/package/azurePackage";
import { AzureDeployPlugin } from "./plugins/deploy/azureDeployPlugin";
import { AzureLoginPlugin } from "./plugins/login/loginPlugin";
import { AzureApimServicePlugin } from "./plugins/apim/apimServicePlugin";
import { AzureApimFunctionPlugin } from "./plugins/apim/apimFunctionPlugin";

export class AzureIndex {
constructor(private serverless: Serverless, private options) {
public constructor(private serverless: Serverless, private options) {
this.serverless.setProvider(AzureProvider.getProviderName(), new AzureProvider(serverless) as any);

// To be refactored
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/apim/apimFunctionPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { MockFactory } from "../../test/mockFactory";
import { invokeHook } from "../../test/utils";
import { AzureApimFunctionPlugin } from './apimFunctionPlugin';
import { AzureApimFunctionPlugin } from "./apimFunctionPlugin";

jest.mock('../../services/apimService');
import { ApimService } from '../../services/apimService';
jest.mock("../../services/apimService");
import { ApimService } from "../../services/apimService";

describe('APIM Function Plugin', () => {
it('calls deploy function', async () => {
describe("APIM Function Plugin", () => {
it("calls deploy function", async () => {
const deployFunction = jest.fn();

ApimService.prototype.deployFunction = deployFunction;

const sls = MockFactory.createTestServerless();
sls.service.provider['apim'] = 'apim config'
sls.service.provider["apim"] = "apim config"
const options = MockFactory.createTestServerlessOptions();
const plugin = new AzureApimFunctionPlugin(sls, options);

await invokeHook(plugin, 'after:deploy:function:deploy');
await invokeHook(plugin, "after:deploy:function:deploy");

expect(sls.cli.log).toBeCalledWith('Starting APIM function deployment')
expect(sls.cli.log).toBeCalledWith("Starting APIM function deployment")
expect(deployFunction).toBeCalled();
expect(sls.cli.log).lastCalledWith('Finished APIM function deployment')
expect(sls.cli.log).lastCalledWith("Finished APIM function deployment")
});
});
12 changes: 6 additions & 6 deletions src/plugins/apim/apimFunctionPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Serverless from 'serverless';
import { ApimService } from '../../services/apimService';
import Serverless from "serverless";
import { ApimService } from "../../services/apimService";

export class AzureApimFunctionPlugin {
public hooks: { [eventName: string]: Promise<any> };

constructor(private serverless: Serverless, private options: Serverless.Options) {
public constructor(private serverless: Serverless, private options: Serverless.Options) {
this.hooks = {
'after:deploy:function:deploy': this.deploy.bind(this)
"after:deploy:function:deploy": this.deploy.bind(this)
};
}

private async deploy() {
this.serverless.cli.log('Starting APIM function deployment');
this.serverless.cli.log("Starting APIM function deployment");

const apimService = new ApimService(this.serverless, this.options);
await apimService.deployFunction(this.options);

this.serverless.cli.log('Finished APIM function deployment');
this.serverless.cli.log("Finished APIM function deployment");
}
}
32 changes: 16 additions & 16 deletions src/plugins/apim/apimServicePlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import Serverless from 'serverless';
import Serverless from "serverless";
import { MockFactory } from "../../test/mockFactory";
import { invokeHook } from "../../test/utils";
import { AzureApimServicePlugin } from './apimServicePlugin';
import { AzureApimServicePlugin } from "./apimServicePlugin";

jest.mock('../../services/apimService');
import { ApimService } from '../../services/apimService';
jest.mock("../../services/apimService");
import { ApimService } from "../../services/apimService";

describe('APIM Service Plugin', () => {
it('is defined', () => {
describe("APIM Service Plugin", () => {
it("is defined", () => {
expect(AzureApimServicePlugin).toBeDefined();
});

it('can be instantiated', () => {
it("can be instantiated", () => {
const serverless = new Serverless();
const options: Serverless.Options = {
stage: '',
region: '',
stage: "",
region: "",
}
const plugin = new AzureApimServicePlugin(serverless, options);

expect(plugin).not.toBeNull();
});

it('calls deploy API and deploy functions', async () => {
it("calls deploy API and deploy functions", async () => {
const deployApi = jest.fn();
const deployFunctions = jest.fn();

ApimService.prototype.deployApi = deployApi;
ApimService.prototype.deployFunctions = deployFunctions;

const sls = MockFactory.createTestServerless();
sls.service.provider['apim'] = 'apim config'
sls.service.provider["apim"] = "apim config"
const options = MockFactory.createTestServerlessOptions();
const plugin = new AzureApimServicePlugin(sls, options);

await invokeHook(plugin, 'after:deploy:deploy');
await invokeHook(plugin, "after:deploy:deploy");

expect(sls.cli.log).toBeCalledWith('Starting APIM service deployment')
expect(sls.cli.log).toBeCalledWith("Starting APIM service deployment")
expect(deployApi).toBeCalled();
expect(deployFunctions).toBeCalled();
expect(sls.cli.log).lastCalledWith('Finished APIM service deployment')
expect(sls.cli.log).lastCalledWith("Finished APIM service deployment")
});

it('does not call deploy API or deploy functions when "apim" not included in config', async () => {
it("does not call deploy API or deploy functions when \"apim\" not included in config", async () => {
const deployApi = jest.fn();
const deployFunctions = jest.fn();

Expand All @@ -53,7 +53,7 @@ describe('APIM Service Plugin', () => {
const options = MockFactory.createTestServerlessOptions();
const plugin = new AzureApimServicePlugin(sls, options);

await invokeHook(plugin, 'after:deploy:deploy');
await invokeHook(plugin, "after:deploy:deploy");

expect(sls.cli.log).not.toBeCalled()
expect(deployApi).not.toBeCalled();
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/apim/apimServicePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import Serverless from 'serverless';
import { ApimService } from '../../services/apimService';
import Serverless from "serverless";
import { ApimService } from "../../services/apimService";

export class AzureApimServicePlugin {
public hooks: { [eventName: string]: Promise<any> };

constructor(private serverless: Serverless, private options: Serverless.Options) {
public constructor(private serverless: Serverless, private options: Serverless.Options) {
this.hooks = {
'after:deploy:deploy': this.deploy.bind(this)
"after:deploy:deploy": this.deploy.bind(this)
};
}

private async deploy() {
const apimConfig = this.serverless.service.provider['apim'];
const apimConfig = this.serverless.service.provider["apim"];
if (!apimConfig) {
return Promise.resolve();
}

this.serverless.cli.log('Starting APIM service deployment');
this.serverless.cli.log("Starting APIM service deployment");

const apimService = new ApimService(this.serverless, this.options);
await apimService.deployApi();
await apimService.deployFunctions();

this.serverless.cli.log('Finished APIM service deployment');
this.serverless.cli.log("Finished APIM service deployment");
}
}
6 changes: 3 additions & 3 deletions src/plugins/deploy/azureDeployPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { FunctionAppService } from "../../services/functionAppService";
jest.mock("../../services/resourceService");
import { ResourceService } from "../../services/resourceService";

describe('Deploy plugin', () => {
describe("Deploy plugin", () => {

it('calls deploy hook', async () => {
it("calls deploy hook", async () => {
const deployResourceGroup = jest.fn();
const functionAppStub = "Function App Stub";
const deploy = jest.fn(() => Promise.resolve(functionAppStub));
Expand All @@ -24,7 +24,7 @@ describe('Deploy plugin', () => {
const options = MockFactory.createTestServerlessOptions();
const plugin = new AzureDeployPlugin(sls, options);

await invokeHook(plugin, 'deploy:deploy');
await invokeHook(plugin, "deploy:deploy");

expect(deployResourceGroup).toBeCalled();
expect(deploy).toBeCalled();
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/deploy/azureDeployPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Serverless from 'serverless';
import { ResourceService } from '../../services/resourceService';
import { FunctionAppService } from '../../services/functionAppService';
import Serverless from "serverless";
import { ResourceService } from "../../services/resourceService";
import { FunctionAppService } from "../../services/functionAppService";

export class AzureDeployPlugin {
public hooks: { [eventName: string]: Promise<any> };

constructor(private serverless: Serverless, private options: Serverless.Options) {
public constructor(private serverless: Serverless, private options: Serverless.Options) {
this.hooks = {
'deploy:deploy': this.deploy.bind(this)
"deploy:deploy": this.deploy.bind(this)
};
}

Expand Down
28 changes: 14 additions & 14 deletions src/plugins/invoke/azureInvoke.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import Serverless from 'serverless';
import { join, isAbsolute } from 'path';
import AzureProvider from '../../provider/azureProvider';
import Serverless from "serverless";
import { join, isAbsolute } from "path";
import AzureProvider from "../../provider/azureProvider";

export class AzureInvoke {
public hooks: { [eventName: string]: Promise<any> };
private provider: AzureProvider;

constructor(private serverless: Serverless, private options: Serverless.Options) {
this.provider = (this.serverless.getProvider('azure') as any) as AzureProvider;
const path = this.options['path'];
public constructor(private serverless: Serverless, private options: Serverless.Options) {
this.provider = (this.serverless.getProvider("azure") as any) as AzureProvider;
const path = this.options["path"];

if (path) {
const absolutePath = isAbsolute(path)
? path
: join(this.serverless.config.servicePath, path);

if (!this.serverless.utils.fileExistsSync(absolutePath)) {
throw new Error('The file you provided does not exist.');
throw new Error("The file you provided does not exist.");
}
this.options['data'] = this.serverless.utils.readFileSync(absolutePath);
this.options["data"] = this.serverless.utils.readFileSync(absolutePath);
}

this.hooks = {
'before:invoke:invoke': this.provider.getAdminKey.bind(this),
'invoke:invoke': this.invoke.bind(this)
"before:invoke:invoke": this.provider.getAdminKey.bind(this),
"invoke:invoke": this.invoke.bind(this)
};
}

private async invoke() {
const func = this.options.function;
const functionObject = this.serverless.service.getFunction(func);
const eventType = Object.keys(functionObject['events'][0])[0];
const eventType = Object.keys(functionObject["events"][0])[0];

if (!this.options['data']) {
this.options['data'] = {};
if (!this.options["data"]) {
this.options["data"] = {};
}

return this.provider.invoke(func, eventType, this.options['data']);
return this.provider.invoke(func, eventType, this.options["data"]);
}
}
Loading