Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix: Resolves issues running plugin (#141)
Browse files Browse the repository at this point in the history
Fixes plugin after conversion to TypeScript
  • Loading branch information
wbreza authored and tbarlow12 committed May 22, 2019
1 parent 0c3e10d commit e839a84
Show file tree
Hide file tree
Showing 24 changed files with 261 additions and 198 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
/lib
*.dll
.env
106 changes: 102 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"author": "Azure Functions",
"scripts": {
"test": "eslint src/**/*.js",
"prebuild": "rm lib/ -rf && npm test",
"build": "tsc && cp src/shared/bindings.json lib/shared"
"prebuild": "rm -rf lib/ && npm test",
"build": "tsc"
},
"repository": {
"git": "https://github.com/serverless/serverless-azure-functions"
Expand All @@ -34,17 +34,20 @@
"az-login": "^0.3.0",
"azure-arm-resource": "^2.0.0-preview",
"jsonpath": "^0.2.11",
"lodash": "^4.16.6",
"lodash": "^4.17.11",
"open": "^6.3.0",
"request": "^2.81.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@types/lodash": "^4.14.130",
"@types/open": "^6.1.0",
"@types/request": "^2.48.1",
"@types/serverless": "^1.18.2",
"eslint": "3.19.0"
"eslint": "3.19.0",
"tslint": "^5.16.0"
},
"optionalDependencies": {
"serverless-webpack": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ whole provider implementation.
*/

import * as 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 { AzurePackageFunction } from './plugins/package/azurePackageFunction';
import AzureProvider from './provider/azureProvider';
import { AzureDeployPlugin } from './plugins/deploy/azureDeployPlugin';
import { AzureDeployFunctionPlugin } from './plugins/deploy/azureDeployFunctionPlugin';
import { AzureLoginPlugin } from './plugins/login/loginPlugin';
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/deploy/azureDeployFunctionPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export class AzureDeployFunctionPlugin {
constructor(private serverless: Serverless, private options: Serverless.Options) {
this.hooks = {
'deploy:function:packageFunction': this.beforeDeploy.bind(this),
'deploy:function:deploy': this.deploy.bind(this, options)
'deploy:function:deploy': this.deploy.bind(this)
};
}

async beforeDeploy() {
private async beforeDeploy() {
// Spawn 'package:function' to create the single-function zip artifact
this.serverless.pluginManager.spawn('package:function');
}

async deploy() {
private async deploy() {
const functionAppService = new FunctionAppService(this.serverless, this.options);
const functionApp = await functionAppService.get();

Expand Down
13 changes: 0 additions & 13 deletions src/plugins/deploy/azureDeployPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ export class AzureDeployPlugin {
}
}

private async sync() {
const functionAppService = new FunctionAppService(this.serverless, this.options);
const functionApp = await functionAppService.get();

await functionAppService.syncTriggers(functionApp);
}

private async upload() {
const functionAppService = new FunctionAppService(this.serverless, this.options);
const functionApp = await functionAppService.get();
await functionAppService.uploadFunctions(functionApp);
}

private async deploy() {
const resourceService = new ResourceService(this.serverless, this.options);
await resourceService.deployResourceGroup();
Expand Down
27 changes: 17 additions & 10 deletions src/plugins/invoke/azureInvoke.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import * as Serverless from 'serverless';
import { invokeFunction } from './lib/invokeFunction';
import { getAdminKey } from '../../shared/getAdminKey';
import { join, isAbsolute } from 'path';
import AzureProvider from '../../provider/azureProvider';

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

constructor(private serverless: Serverless, private options: Serverless.Options) {
Object.assign(
this,
getAdminKey,
invokeFunction
);

this.provider = (this.serverless.getProvider('azure') as any) as AzureProvider;
const path = this.options['path'];

if (path) {
Expand All @@ -30,7 +25,19 @@ export class AzureInvoke {

this.hooks = {
'before:invoke:invoke': this.getAdminKey.bind(this),
'invoke:invoke': this.invokeFunction.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];

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

return this.provider.invoke(func, eventType, this.options['data']);
}
}
14 changes: 0 additions & 14 deletions src/plugins/invoke/lib/invokeFunction.ts

This file was deleted.

14 changes: 10 additions & 4 deletions src/plugins/login/loginPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Serverless from 'serverless';
import * as open from 'open';
import { interactiveLoginWithAuthResponse, loginWithServicePrincipalSecretWithAuthResponse } from '@azure/ms-rest-nodeauth';
import * as Serverless from 'serverless';
import AzureProvider from '../../provider/azureProvider';

export class AzureLoginPlugin {
Expand All @@ -11,11 +11,16 @@ export class AzureLoginPlugin {
this.provider = (this.serverless.getProvider('azure') as any) as AzureProvider;

this.hooks = {
'before:deploy:initialize': this.login.bind(this)
'before:package:initialize': this.login.bind(this)
};
}

async login() {
private async login() {
// If credentials have already been set then short circuit
if (this.serverless.variables['azureCredentials']) {
return;
}

this.serverless.cli.log('Logging into Azure');

let authResult = null;
Expand All @@ -28,7 +33,8 @@ export class AzureLoginPlugin {
try {
if (subscriptionId && clientId && secret && tenantId) {
authResult = await loginWithServicePrincipalSecretWithAuthResponse(clientId, secret, tenantId);
} else {
}
else {
await open('https://microsoft.com/devicelogin');
authResult = await interactiveLoginWithAuthResponse();
}
Expand Down
17 changes: 10 additions & 7 deletions src/plugins/logs/azureLogs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as Serverless from 'serverless';
import { retrieveLogs } from './lib/retrieveLogs';
import AzureProvider from '../../provider/azureProvider';

export class AzureLogs {
public hooks: { [eventName: string]: Promise<any> };
private retrieveLogs: () => Promise<any>;

constructor(private serverless: Serverless, private options: Serverless.Options) {
Object.assign(
this,
retrieveLogs
);
private provider: AzureProvider;

constructor(private serverless: Serverless, private options: Serverless.Options) {
this.provider = (this.serverless.getProvider('azure') as any) as AzureProvider;

this.hooks = {
'logs:logs': this.retrieveLogs.bind(this)
};
}

private async retrieveLogs() {
await this.provider.pingHostStatus(this.options.function);
await this.provider.getLogsStream(this.options.function);
}
}
8 changes: 0 additions & 8 deletions src/plugins/logs/lib/retrieveLogs.ts

This file was deleted.

Loading

0 comments on commit e839a84

Please sign in to comment.