Skip to content

Commit

Permalink
adding support for userid based search
Browse files Browse the repository at this point in the history
  • Loading branch information
Parth Shah committed Jul 15, 2016
1 parent f7beb08 commit 3ff7df9
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 177 deletions.
66 changes: 0 additions & 66 deletions .travis.yml

This file was deleted.

79 changes: 47 additions & 32 deletions event.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
{
"body": {},
"params": {
"path": {},
"querystring": {
"query": "MEMBER_SEARCH",
"handle": "%271%27=%271%27",
"limit": 10,
"offset": 0
},
"header": {}
},
"stage-variables": {},
"context": {
"account-id": "811668436784",
"api-id": "bd1cmoh5ag",
"api-key": "test-invoke-api-key",
"authorizer-principal-id": "",
"caller": "AIDAJUYC3TUFF3VEGQ5PQ",
"cognito-authentication-provider": "",
"cognito-authentication-type": "",
"cognito-identity-id": "",
"cognito-identity-pool-id": "",
"http-method": "GET",
"stage": "test-invoke-stage",
"source-ip": "test-invoke-source-ip",
"user": "AIDAJUYC3TUFF3VEGQ5PQ",
"user-agent": "Apache-HttpClient/4.3.4 (java 1.5)",
"user-arn": "arn:aws:iam::811668436784:user/nlitwin",
"request-id": "test-invoke-request",
"resource-id": "m3zey8",
"resource-path": "/v3/members/_search"
}
"body": {},
"params": {
"path": {},
"querystring": {
"handle": "albert",
"limit": "10",
"offset": "0",
"query": "MEMBER_SEARCH"
},
"header": {
"Accept": "*%2F*",
"Accept-Encoding": "gzip%2C+deflate%2C+sdch%2C+br",
"Accept-Language": "en-US%2Cen%3Bq%3D0.8",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Viewer-Country": "US",
"Host": "internal-api.topcoder-dev.com",
"Origin": "https%3A%2F%2Fwww.topcoder-dev.com",
"Referer": "https%3A%2F%2Fwww.topcoder-dev.com%2Fsearch%2Fmembers%2F%3Fq%3Dalbert",
"User-Agent": "Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_11_5%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F51.0.2704.103+Safari%2F537.36",
"Via": "1.1+3711209710286c6c954f8418c2d0a852.cloudfront.net+%28CloudFront%29",
"X-Amz-Cf-Id": "MTtIVsvgQ98uzUrUb1-EqvQU08K88I27E7AULnwODM__xuBe5c3Otg%3D%3D",
"X-Forwarded-For": "52.21.65.101%2C+54.239.145.86",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
}
},
"stage-variables": {},
"context": {
"account-id": "",
"api-id": "bd1cmoh5ag",
"api-key": "",
"authorizer-principal-id": "",
"caller": "",
"cognito-authentication-provider": "",
"cognito-authentication-type": "",
"cognito-identity-id": "",
"cognito-identity-pool-id": "",
"http-method": "GET",
"stage": "dev",
"source-ip": "52.21.65.101",
"user": "",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
"user-arn": "",
"request-id": "6037542d-4aba-11e6-80e9-01ababcc3c56",
"resource-id": "s4tezq",
"resource-path": "/v3/members/_search"
}
}
98 changes: 88 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,91 @@
var gulp = require('gulp');
var runSequence = require('run-sequence');
require('tc-lambda-gulp-tasks')(gulp);
var path = require('path');

gulp.task('test', function(cb) {
var lc = require("./lambda-config.js")
console.log(lc);
return cb
})
"use strict";

var gulp = require('gulp'),
zip = require('gulp-zip'),
del = require('del'),
install = require('gulp-install'),
awsLambda = require('node-aws-lambda'),
envify = require('gulp-envify'),
_ = require('lodash'),
runSequence = require('run-sequence'),
sys = require('sys'),
exec = require('child_process').exec,
path = require('path');


gulp.task('clean', function(cb) {
return del(['./dist', './dist.zip'], cb);
});

gulp.task('js', function() {
return gulp.src(['src/index.js'])
.pipe(envify(process.env))
.pipe(gulp.dest('dist/'));
});

gulp.task('node-mods', function() {
return gulp.src('./package.json')
.pipe(gulp.dest('dist/'))
.pipe(install({
production: true
}));
});

gulp.task('zip', function() {
return gulp.src(['dist/**/*', '!dist/package.json'])
.pipe(zip('dist.zip'))
.pipe(gulp.dest('./'));
});

gulp.task('upload', function(callback) {
var packageDefinition = require(path.join(process.cwd(), './package.json'))
var lambdaConfig = packageDefinition.lambda;
// set defaults
_.defaultsDeep(lambdaConfig, {
profile: process.env.AWS_PROFILE,
region: 'us-east-1',
handler: 'index.handler',
description: "",
role: 'arn:aws:iam::' + process.env.AWS_ACCOUNT_ID + ':role/' + (packageDefinition.lambda.roleName || 'aws-lambda-default'),
timeout: 180,
memorySize: 512
});
// to work around jenkins multi-branch plugin
var cb = function(_cfg) {
console.log("Deploying with lambdaConfig: ", JSON.stringify(_cfg, null, 2))
awsLambda.deploy(
'./dist.zip', _cfg,
callback);
};
if (process.env.ENVIRONMENT === 'dev') {
lambdaConfig.functionName += "-dev";
cb(lambdaConfig);
} else if (process.env.ENVIRONMENT === 'qa') {
lambdaConfig.functionName += "-qa";
cb(lambdaConfig);
} else if (process.env.ENVIRONMENT === 'prod') {
lambdaConfig.functionName += "-prod";
cb(lambdaConfig);
} else {
exec("git symbolic-ref -q --short head", function(err, stdout, stderr) {
if (err) {
throw err;
} else if (stderr) {
throw new Error(stderr)
} else {
// update lambda functionName with branch
if (stdout.indexOf('master') > -1) {
lambdaConfig.functionName += "-prod";
} else if (stdout.indexOf('release') > -1) {
lambdaConfig.functionName += "-qa";
} else if (stdout.indexOf('dev') > -1) {
lambdaConfig.functionName += "-dev";
}
cb(lambdaConfig);
}
})
}
});

gulp.task('deploy', function(callback) {
return runSequence(
Expand Down
33 changes: 27 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,48 @@
"version": "1.0.0",
"description": "lambda function for member search",
"main": "index.js",
"lambda": {
"functionName": "tc-member-search-api",
"handler": "index.handler",
"roleName": "ap-lambda-default",
"runtime": "nodejs4.3",
"description": "Lambda function to search members"
},
"dependencies": {
"elasticsearch": "^10.1.3",
"elasticsearch": "^11.0.1",
"http-aws-es": "^1.1.3",
"lodash": "^4.6.1"
"lodash": "^4.13.1",
"jsonwebtoken": "^7.0.0",
"node-lambda": "^0.8.5"
},
"devDependencies": {
"aws-lambda-mock-context": "^1.1.0",
"aws-lambda-mock-context": "^3.0.0",
"aws-sdk": "^2.2.41",
"chai": "^3.5.0",
"dynamodb-doc": "^1.0.0",
"gulp": "^3.9.1",
"mocha": "^2.4.5",
"node-lambda": "^0.8.0",
"node-lambda": "^0.8.5",
"run-sequence": "^1.1.5",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"tc-lambda-gulp-tasks": "1.0.0"
"del": "^1.1.0",
"gulp": "^3.8.10",
"gulp-envify": "^1.0.0",
"gulp-install": "^0.2.0",
"gulp-rename": "^1.2.0",
"gulp-util": "^3.0.6",
"gulp-zip": "^2.0.3",
"lambda-local": "0.0.9",
"node-aws-lambda": "^0.1.8",
"node-lambda": "^0.8.0",
"run-sequence": "^1.0.2",
"stream": "0.0.2"
},
"scripts": {
"test": "./node_modules/.bin/mocha src/**/*.spec.js",
"test-lambda": "./node_modules/.bin/node-lambda run -h src/index.handler -j event.json"
"test-lambda": "./node_modules/.bin/node-lambda run -u nodejs4.3 --handler src/index.handler --eventFile event.json --contextFile context.json",
"deploy": "gulp deploy"
},
"author": "",
"license": "ISC"
Expand Down
Loading

0 comments on commit 3ff7df9

Please sign in to comment.