Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@everymundo/em-eureka

Package Overview
Dependencies
Maintainers
19
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everymundo/em-eureka - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

41

index.js

@@ -7,4 +7,4 @@ 'use strict';

const logr = require('@everymundo/simple-logr');
const { Resilient } = require('./load-resilient');
const { parseEureka } = require('./lib/parse-eureka');
const { Resilient } = require('./load-resilient');
const { parseEureka } = require('./lib/parse-eureka');
const { getMicroserviceName, getPrefixedMajorVersionNumber } = require('@everymundo/generate-microservice-name');

@@ -127,2 +127,16 @@

const regexp = /^([a-z]{2})([A-Z][a-z]+)(\d[a-z]?)/;
const transformKey = (key) => {
const match = key.match(regexp);
if (match) {
const [, countryCode, cardinalPoint, zoneId] = match;
return `${countryCode}-${cardinalPoint.toLowerCase()}-${zoneId}`;
}
return key;
};
const getEurekaFromConfigService = async (eureka = {}) => {

@@ -134,12 +148,25 @@ // const url = require('url');

const { serviceUrl } = parsed.eureka.client;
const availabilityZones = Object.keys(serviceUrl);
const { serviceUrl, availabilityZones = {}} = parsed.eureka.client;
Object
.keys(availabilityZones)
.forEach((region) => {
const newRegionName = transformKey(region);
availabilityZones[newRegionName] = availabilityZones[region].split(/\s*,\s*/);
if (newRegionName !== region) delete availabilityZones[region];
});
const serviceUrls = {};
availabilityZones.forEach((zone) => {
serviceUrls[zone] = [serviceUrl[zone]];
Object.keys(serviceUrl).forEach((zone) => {
const newZoneName = transformKey(zone);
serviceUrls[newZoneName] = [serviceUrl[zone]];
});
const config = { serviceUrls, availabilityZones, ...eureka };
const ec2Region = Object.keys(availabilityZones).shift();
const config = { serviceUrls, availabilityZones, ec2Region, ...eureka };
return config;

@@ -146,0 +173,0 @@ };

4

lib/parse-eureka.js

@@ -5,3 +5,3 @@ const assert = require('assert');

const parseEureka = (eureka = {}) => {
const { host, port, servicePath, serviceUrls, availabilityZones } = eureka;
const { host, port, servicePath, serviceUrls, availabilityZones, ec2Region } = eureka;

@@ -18,3 +18,3 @@ if (serviceUrls) {

return { availabilityZones, serviceUrls };
return { availabilityZones, serviceUrls, ec2Region };
}

@@ -21,0 +21,0 @@

{
"name": "@everymundo/em-eureka",
"version": "1.5.0",
"version": "1.5.1",
"description": "wrapper around eureka-js-client for everymundo microservice apps",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -384,28 +384,2 @@ 'require strict';

describe('#getEurekaFromConfigService', () => {
const cfgClientLib = require('@everymundo/config-service-client');
const fareConfig = { parsed: { eureka: { client: { serviceUrl: { any: 'http://eureka.test.com:1000/eureka' } } } } };
beforeEach(() => {
box.stub(cfgClientLib, 'getConfigsAsync').callsFake(() => fareConfig);
});
it('should return proper {host, port} object', () => {
const { getEurekaFromConfigService } = require('../index');
return getEurekaFromConfigService()
.then((config) => {
// const expected = { host: 'eureka.test.com', port: '1000' };
const expected = {
availabilityZones: ['any'],
serviceUrls: {
any: ['http://eureka.test.com:1000/eureka'],
},
};
expect(config).to.deep.equal(expected);
});
});
});
describe('#generateInstanceId', () => {

@@ -479,6 +453,6 @@ const fakeIp = '10.11.12.13';

});
/*
describe('#getEurekaFromConfigService', () => {
const cfgClientLib = require('@everymundo/config-service-client');
const fareConfig = {parsed: {eureka:{ client: {serviceUrl: {any: 'http://eureka.test.com:1000/eureka'}}}}};
const fareConfig = { parsed: { eureka: { client: { serviceUrl: { any: 'http://eureka.test.com:1000/eureka' } } } } };

@@ -494,10 +468,93 @@ beforeEach(() => {

.then((config) => {
// const expected = {host: 'eureka.test.com', port: '1000'};
// const expected = { host: 'eureka.test.com', port: '1000' };
const expected = {
availabilityZones: ['any'],
serviceUrls: { any: ['http://eureka.test.com:1000/eureka'] },
serviceUrls: {
any: ['http://eureka.test.com:1000/eureka'],
},
};
expect(config).to.deep.equal(expected);
});
});
}); */
describe('#getEurekaFromConfigService', () => {
const cfgClientLib = require('@everymundo/config-service-client');
context('receiving the keys with dashes', () => {
const fareConfig = {
parsed: {
eureka: {
client: {
availabilityZones: {'us-west-1': 'us-west-1a,us-west-1b'},
serviceUrl: {
'us-west-1a': 'http://us-west-1a.eureka.test.com:1000/eureka',
'us-west-1b': 'http://us-west-1b.eureka.test.com:1000/eureka',
},
},
},
},
};
beforeEach(() => {
box.stub(cfgClientLib, 'getConfigsAsync').callsFake(() => fareConfig);
});
it('should return proper {availabilityZones, serviceUrls, ec2Region} object', () => {
const { getEurekaFromConfigService } = require('../index');
return getEurekaFromConfigService()
.then((config) => {
// const expected = {host: 'eureka.test.com', port: '1000'};
const expected = {
ec2Region: 'us-west-1',
availabilityZones: { 'us-west-1': ['us-west-1a', 'us-west-1b']},
serviceUrls: {
'us-west-1a': ['http://us-west-1a.eureka.test.com:1000/eureka'],
'us-west-1b': ['http://us-west-1b.eureka.test.com:1000/eureka'],
},
};
expect(config).to.deep.equal(expected);
});
});
});
context('receiving the keys camelCased', () => {
const fareConfig = {
parsed: {
eureka: {
client: {
availabilityZones: {usWest1: 'us-west-1a,us-west-1b'},
serviceUrl: {
usWest1a: 'http://us-west-1a.eureka.test.com:1000/eureka',
usWest1b: 'http://us-west-1b.eureka.test.com:1000/eureka',
},
},
},
},
};
beforeEach(() => {
box.stub(cfgClientLib, 'getConfigsAsync').callsFake(() => fareConfig);
});
it('should return proper {availabilityZones, serviceUrls, ec2Region} object', () => {
const { getEurekaFromConfigService } = require('../index');
return getEurekaFromConfigService()
.then((config) => {
// const expected = {host: 'eureka.test.com', port: '1000'};
const expected = {
ec2Region: 'us-west-1',
availabilityZones: { 'us-west-1': ['us-west-1a', 'us-west-1b']},
serviceUrls: {
'us-west-1a': ['http://us-west-1a.eureka.test.com:1000/eureka'],
'us-west-1b': ['http://us-west-1b.eureka.test.com:1000/eureka'],
},
};
expect(config).to.deep.equal(expected);
});
});
});
});

@@ -504,0 +561,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc