Skip to content

Commit

Permalink
v2.5.35
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed May 18, 2019
2 parents e7a65ba + 37a58da commit 64d10ed
Show file tree
Hide file tree
Showing 30 changed files with 863 additions and 115 deletions.
4 changes: 3 additions & 1 deletion cli/lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Gateway.prototype.start = (options) => {
} catch (e) {
// Socket does not exist
// so ignore and proceed
debug(e);
if (e.code !== "ENOENT") {
debug(e.message);
}
}

const source = configLocations.getSourcePath(options.org, options.env, options.configDir);
Expand Down
12 changes: 7 additions & 5 deletions cli/lib/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ module.exports = function() {

Token.prototype.decodeToken = function( options ) {
assert(options.file,"file is required")
const jtw = require('../api/helpers/jwt');
const token = fs.readFileSync(path.resolve(options.file), 'utf8').trim();
jtw.decode(token, function(err, result) {
if (err) { return printError(err); }
console.log(result);
});
try{
const decodedJWT = jwt.decode(token, {complete:true});
console.log(decodedJWT);
return decodedJWT;
}catch(err) {
console.error(err);
}
}

Token.prototype.verifyToken = function(options, cb) {
Expand Down
30 changes: 18 additions & 12 deletions kubernetes/docker/edgemicro/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
FROM node:8-alpine

COPY install.sh /tmp
COPY installnode.sh /tmp
COPY --chown=100:101 installedgemicro.sh /tmp

# create user and group for microgateway
RUN apk add --no-cache sed grep && \
addgroup -S apigee -g 101 && \
adduser -s /bin/sh -u 100 -S -G apigee apigee -h /opt/apigee

WORKDIR /opt/apigee

# copy entrypoint
COPY entrypoint.sh /opt/apigee

ENV NODE_ENV production

#install and initialize microgateway
RUN chmod +x /tmp/install.sh && \
sh /tmp/install.sh && \
rm -f /tmp/install.sh && \
#install node.js
RUN chmod +x /tmp/installnode.sh && \
sh /tmp/installnode.sh && \
rm -f /tmp/installnode.sh && \
deluser --remove-home node

USER apigee
WORKDIR /opt/apigee
RUN mkdir /opt/apigee/.edgemicro && mkdir /opt/apigee/logs && mkdir /opt/apigee/plugins
VOLUME /opt/apigee/.edgemicro
VOLUME /opt/apigee/logs
VOLUME /opt/apigee/plugins
Expand All @@ -28,8 +27,15 @@ VOLUME /opt/apigee/plugins
# COPY key.pem /opt/apigee/.edgemicro
# COPY cert.pem /opt/apigee/.edgemicro

# copy entrypoint
COPY --chown=100:101 entrypoint.sh /opt/apigee

# initialize edgemicro
RUN sh /tmp/installedgemicro.sh&& \
rm -f /tmp/installedgemicro.sh

# Expose ports
EXPOSE 8000
EXPOSE 8443
USER apigee
ENTRYPOINT ["entrypoint"]

ENTRYPOINT ["/opt/apigee/entrypoint.sh"]
17 changes: 0 additions & 17 deletions kubernetes/docker/edgemicro/install.sh

This file was deleted.

8 changes: 8 additions & 0 deletions kubernetes/docker/edgemicro/installedgemicro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set echo off

mkdir -p /opt/apigee/logs && \
mkdir -p /opt/apigee/plugins && \
edgemicro init && \
chmod +x /opt/apigee/entrypoint.sh
3 changes: 3 additions & 0 deletions kubernetes/docker/edgemicro/installnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
set echo off
npm install --only=production --no-optional -g edgemicro
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"gulp-sourcemaps": "^1.5.2",
"minimist": "^1.1.1",
"mocha": "^5.2.0",
"nyc": "^13.3.0",
"restify": "^4.0.4",
"run-sequence": "^1.1.0"
},
Expand All @@ -58,7 +59,8 @@
"start": "node app.js",
"stop": "node stop.js",
"package": "node cli/package.js",
"test": "mocha --timeout 17000 tests"
"test": "mocha --timeout 17000 tests/*.unit.test.js",
"test:integration": "nyc mocha tests/*.*.integ.test.js --timeout 90000"
},
"directories": {
"doc": "docs",
Expand Down
57 changes: 57 additions & 0 deletions tests/01.init.integ.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

const init = require('../cli/lib/init.js');
const loc = require('../config/locations.js');
const os = require('os');
const path = require('path');
const assert = require('assert');
const fs = require('fs');
const edgemicroCustomDir = 'edgemicroCustomDir';
const edgemicroCustomFilepath = path.join(edgemicroCustomDir, loc.defaultFile);

describe('init module', () => {

before((done) => {
try{
if(fs.existsSync(edgemicroCustomFilepath)) fs.unlinkSync(edgemicroCustomFilepath);
if(fs.existsSync(edgemicroCustomDir)) fs.rmdirSync(edgemicroCustomDir);
} catch(err){
console.error(err);
}
done();
});

after( (done) => {
try{
if(fs.existsSync(edgemicroCustomFilepath)) fs.unlinkSync(edgemicroCustomFilepath);
if(fs.existsSync(edgemicroCustomDir)) fs.rmdirSync(edgemicroCustomDir);
} catch(err){
console.error(err);
}
done();
});

it('creates init config file in default home directory', (done) => {
init({}, (err, location) => {
assert.equal(err, null);
assert.deepStrictEqual(loc.getDefaultPath(), location);
let srcFile = fs.readFileSync(loc.getDefaultPath(), 'utf8');
let destFile = fs.readFileSync(location, 'utf8');
assert.deepStrictEqual(srcFile, destFile);
done();
});
});


it('allows custom directory to store configuration files', (done) => {
init({configDir: edgemicroCustomDir}, (err, location) => {
assert.equal(err, null);
assert.deepStrictEqual(edgemicroCustomFilepath, location);
let srcFile = fs.readFileSync(loc.getDefaultPath(), 'utf8');
let destFile = fs.readFileSync(location, 'utf8');
assert.deepStrictEqual(srcFile, destFile);
done();
});
});

});
90 changes: 90 additions & 0 deletions tests/02.locations.integ.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"use strict";

const path = require("path");
const assert = require("assert");
const os = require("os");
const locations = require("../config/locations.js");
const configDir = path.join(__dirname, "../config");
const defaultFilename = "default.yaml";
const defaultDirName = '.edgemicro';
const configPath = path.join(__dirname, "../config", defaultFilename);


describe("locations module", () => {
it("provides default directory to save config as (HOME/.edgemicro)", done => {
const expectedDefaultDir = path.join(os.homedir(), defaultDirName);
assert.equal(expectedDefaultDir, locations.homeDir);
done();
});

it("provides default saved config filename", function (done) {
assert.deepStrictEqual(defaultFilename, locations.defaultFile);
done();
})

it('provides default init source directory', done => {
assert.deepStrictEqual(configDir, locations.defaultDir);
done();
});

it("provides default init source config path", done =>{
const initPath = locations.getInitPath();
assert.deepStrictEqual(configPath, initPath);
done();
});

it("provides default directory to save config", done => {
assert.equal(
path.join(os.homedir(), defaultDirName, defaultFilename),
locations.getDefaultPath()
);
done();
});

it("sets custom directory path ", done => {
assert.equal(
path.join("../tests/fixtures", defaultFilename),
locations.getDefaultPath("../tests/fixtures")
);
done();
//below provides absolute path
// path.join(configDir,'../tests/fixtures', defaultFilename));
});


it("will put together a properly named source file", done => {
var sourceFile = locations.getSourceFile("test", "foo");
assert.equal( "test-foo-config.yaml", sourceFile);
done();
});

it("will build a source path without a configDir", done => {
var configPath = locations.getSourcePath("test", "foo");
assert.equal(
path.join(locations.homeDir, "test-foo-config.yaml"),
configPath
);
done();
});

it("will build a source path with a configDir", done => {
var configPath = locations.getSourcePath("test", "foo", "foo");
assert.equal(configPath, "foo/test-foo-config.yaml");
done();
});

it("will build a cache path without a configDir", done => {
var cachePath = locations.getCachePath("test", "foo");
assert.equal(
cachePath,
path.join(locations.homeDir, "test-foo-cache-config.yaml")
);
done();
});

it("will build a cache path with a configDir", done => {
var cachePath = locations.getCachePath("test", "foo", "foo");
assert.equal(cachePath, "foo/test-foo-cache-config.yaml");
done();
});
});
Loading

0 comments on commit 64d10ed

Please sign in to comment.