Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Consolidate api gateway urls and keys #22

Merged
merged 2 commits into from
Sep 20, 2017
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
29 changes: 5 additions & 24 deletions lib/accessLicenceClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const config = require('./helpers/config');
const helpers = require('./helpers/helpers');

const options = Object.assign({}, config.fetchOptions);
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.ALS_API_KEY});
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.KAT_MEMB_API_KEY});

/**
* Gets the licence for a certain query
Expand All @@ -23,7 +23,7 @@ function getLicences (query) {

if (query.adminuserid || query.linkid || query.linktype || query.status || query.userid) {
const queryString = helpers.createParams(query);
const url = `${config.ALS_API_URL}/licences${queryString}`;
const url = `${config.API_GATEWAY_HOST}/licences${queryString}`;
return fetch(url, Object.assign({}, options))
.then(res => helpers.parseJsonRes(res, `${operation} ${queryString}`))
.then(res => {
Expand All @@ -33,24 +33,6 @@ function getLicences (query) {
}
return Promise.reject(Error('At least one of adminuserid | linkid | linktype | status | userid must be specified'));
}
// TODO: WIP
///**
// * Gets the uuid for a given users email address
// * @param {Object} query - of the user, can be one of the following: linktype | status
// * @return {Promise} response - an array of licences ids found
// */
//function getIDs(query) {
// const operation = 'accessLicenceClient.getIDs';
// const queryString = helpers.createParams(query);
// log.debug({operation, queryString});
// const url = `${config.ALS_API_URL}/licences/ids${queryString}`;
// return fetch(url, Object.assign({}, options))
// .then(res => helpers.parseJsonRes(res, `${operation} ${queryString}`))
// .then(res => {
// log.debug({operation, queryString, res: 'success'});
// return res.accessLicences;
// });
//}

/**
* Gets the uuid of users from a licence
Expand All @@ -61,7 +43,7 @@ function getSeats (licenceID) {
const operation = 'accessLicenceClient.getSeats';
log.debug({operation, licenceID});

const url = `${config.ALS_API_URL}/licences/${licenceID}/seats`;
const url = `${config.API_GATEWAY_HOST}/licences/${licenceID}/seats`;
return fetch(url, Object.assign({}, options))
.then(res => helpers.parseJsonRes(res, `${operation} ${licenceID}`))
.then(res => {
Expand All @@ -79,7 +61,7 @@ function getLicenceInfo (licenceId) {
const operation = 'accessLicenceClient.getLicenceInfo';
log.debug({operation, licenceId});

const url = `${config.ALS_API_URL}/licences/${licenceId}`;
const url = `${config.API_GATEWAY_HOST}/licences/${licenceId}`;
return fetch(url, Object.assign({}, options))
.then(helpers.parseJsonRes)
.then(res => {
Expand All @@ -97,7 +79,7 @@ function getAdministrators (licenceId) {
const operation = 'accessLicenceClient.getAdministrators';
log.debug({operation, licenceId});

const url = `${config.ALS_API_URL}/licences/${licenceId}/administrators`;
const url = `${config.API_GATEWAY_HOST}/licences/${licenceId}/administrators`;
return fetch(url, Object.assign({}, options))
.then(helpers.parseJsonRes)
.then(res => {
Expand All @@ -108,7 +90,6 @@ function getAdministrators (licenceId) {

module.exports = {
getLicences,
//getIDs,// TODO: WIP
getSeats,
getLicenceInfo,
getAdministrators
Expand Down
4 changes: 2 additions & 2 deletions lib/acquisitionCtxClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = require('./helpers/config');
const helpers = require('./helpers/helpers');

const options = Object.assign({}, config.fetchOptions);
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.ACS_API_KEY});
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.KAT_MEMB_API_KEY});

/**
* Gets a list of acquisition contents based a filter
Expand All @@ -20,7 +20,7 @@ function getContexts (ctxFilter) {
const queryString = helpers.createParams(ctxFilter);
log.debug({operation, queryString});

const url = `${config.ACS_API_URL}/acquisition-contexts${queryString}`;
const url = `${config.API_GATEWAY_HOST}/acquisition-contexts${queryString}`;
return fetch(url, Object.assign({}, options))
.then(res => helpers.parseJsonRes(res, `${operation} ${queryString}`))
.then(res => {
Expand Down
6 changes: 0 additions & 6 deletions lib/emailNotification.js

This file was deleted.

6 changes: 1 addition & 5 deletions lib/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ const config = {
},
MYFT_API_URL: envVars.KAT_MYFT_API_URL || envVars.MYFT_API_URL,
MYFT_API_KEY: envVars.KAT_MYFT_API_KEY || envVars.MYFT_API_KEY,
ACS_API_URL: envVars.KAT_ACS_API_URL || envVars.ACS_API_URL,
ACS_API_KEY: envVars.KAT_ACS_API_KEY || envVars.ACS_API_KEY,
API_GATEWAY_HOST: envVars.KAT_API_GATEWAY_HOST || envVars.API_GATEWAY_HOST,
API_GATEWAY_KEY: envVars.KAT_API_GATEWAY_KEY || envVars.API_GATEWAY_KEY,
KAT_MEMB_API_KEY: envVars.KAT_MEMB_API_KEY || envVars.KAT_ALS_API_KEY || envVars.ALS_API_KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we now just remove KAT_ALS_API_KEY and ALS_API_KEY completely??

API_AUTH_CLIENT_ID: envVars.KAT_API_AUTH_CLIENT_ID || envVars.API_AUTH_CLIENT_ID,
DEFAULT_REDIRECT_URL: envVars.KAT_DEFAULT_REDIRECT_URL || envVars.DEFAULT_REDIRECT_URL,
USER_PROFILE_API_URL: envVars.KAT_USER_PROFILE_API_URL || envVars.USER_PROFILE_API_URL,
USER_PROFILE_API_KEY: envVars.KAT_USER_PROFILE_API_KEY || envVars.USER_PROFILE_API_KEY,
ALS_API_URL: envVars.KAT_ALS_API_URL || envVars.ALS_API_URL,
ALS_API_KEY: envVars.KAT_ALS_API_KEY || envVars.ALS_API_KEY,
FT_TOOL_ID: envVars.KAT_FT_TOOL_ID || envVars.FT_TOOL_ID || 'KAT',
FT_TOOL_ADMIN_ID: envVars.KAT_FT_TOOL_ADMIN_ID || envVars.FT_TOOL_ADMIN_ID,
FT_TOOL_DATE_ID: envVars.KAT_FT_TOOL_DATE_ID || envVars.FT_TOOL_DATE_ID || 'kmtRegistrationDate',
Expand All @@ -36,7 +33,6 @@ const config = {
DONT_WRITE_TO_KINESIS: envVars.KAT_DONT_WRITE_TO_KINESIS || envVars.DONT_WRITE_TO_KINESIS === 'true',
ELASTIC_SEARCH_URL: envVars.KAT_ELASTIC_SEARCH_URL || envVars.ELASTIC_SEARCH_URL,
FACETS_SEARCH_URL: envVars.KAT_FACETS_SEARCH_URL || envVars.FACETS_SEARCH_URL,
HUI_BASE_PATH: envVars.KAT_HUI_BASE_PATH || envVars.HUI_BASE_PATH,
HUI_API_KEY: envVars.KAT_HUI_API_KEY || envVars.HUI_API_KEY,
myftClientConstants: {
userNodeName: 'user',
Expand Down
4 changes: 2 additions & 2 deletions lib/huiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const log = require('@financial-times/n-logger').default;
const fetch = require('n-eager-fetch');
const config = require('./helpers/config');
const helpers = require('./helpers/helpers');
const huiBasePath = config.HUI_BASE_PATH;
const apiGateway = config.API_GATEWAY_HOST;
const licencePath = '/licences/';
const options = Object.assign({}, config.fetchOptions);
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.HUI_API_KEY});

function getUsage (licenceId, aggregation, startDate, endDate, type = '', filter = '') {
let start = '';
let end = '';
let url = `${huiBasePath}${licencePath}${licenceId}?aggregation=${aggregation}`;
let url = `${apiGateway}/hui${licencePath}${licenceId}?aggregation=${aggregation}`;

// Get the prev week/month data too. We make a clone of the start date because
// moments are mutable.
Expand Down
6 changes: 3 additions & 3 deletions lib/userProfileClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = require('./helpers/config');
const helpers = require('./helpers/helpers');

const options = Object.assign({}, config.fetchOptions);
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.ACS_API_KEY});
options.headers = Object.assign({}, options.headers, {'X-API-KEY': config.KAT_MEMB_API_KEY});

/**
* Gets the uuid for a given users email address
Expand All @@ -21,7 +21,7 @@ function getUUID (email) {
const operation = 'userProfileClient.getUUID';
log.debug({operation, email});
const queryString = helpers.createParams({email});
const url = `${config.USER_PROFILE_API_URL}/users${queryString}`;
const url = `${config.API_GATEWAY_HOST}/users${queryString}`;
return fetch(url, Object.assign({}, options))
.then(res => helpers.parseJsonRes(res, `${operation} ${queryString}`))
.then(body => {
Expand Down Expand Up @@ -49,7 +49,7 @@ function exists (id) {
const operation = 'userProfileClient.exists';
log.debug({operation, id});
const queryString = helpers.createParams({id});
const url = `${config.USER_PROFILE_API_URL}/users${queryString}`;
const url = `${config.API_GATEWAY_HOST}/users${queryString}`;
const ops = Object.assign({}, options, {method: 'HEAD'});
return fetch(url, ops)
.then(res => {
Expand Down
2 changes: 1 addition & 1 deletion test/accessLicenceClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const clientErrors = proxies.clientErrors;
const env = require('./helpers/env');
const expectOwnProperties = require('./helpers/expectExtensions').expectOwnProperties;
const mockAPI = env.USE_MOCK_API;
const baseUrl = require('./../lib/helpers/config').ALS_API_URL;
const baseUrl = require('./../lib/helpers/config').API_GATEWAY_HOST;

describe('Access Licence Service Client', () => {
let logMessageStub;
Expand Down
2 changes: 1 addition & 1 deletion test/acquisitionCtxClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const logger = require('@financial-times/n-logger').default;
const env = require('./helpers/env');
const expectOwnProperties = require('./helpers/expectExtensions').expectOwnProperties;
const mockAPI = env.USE_MOCK_API;
const baseUrl = `${require('./../lib/helpers/config').ACS_API_URL}/acquisition-contexts`;
const baseUrl = `${require('./../lib/helpers/config').API_GATEWAY_HOST}/acquisition-contexts`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of consistency could we make this

const config = require('./../lib/helpers/config');
const baseUrl = `${config.API_GATEWAY_HOST}/acquisition-contexts`;


describe('Acquisition Context Service Client', () => {
let logMessageStub;
Expand Down
8 changes: 4 additions & 4 deletions test/huiClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const logger = require('@financial-times/n-logger').default;
const sinon = require('sinon');
const env = require('./helpers/env');
const mockAPI = env.USE_MOCK_API;
const baseUrl = require('./../lib/helpers/config').HUI_BASE_PATH;
const baseUrl = require('./../lib/helpers/config').API_GATEWAY_HOST;

describe('HUI Service Client',() => {
const weekDateFormat = '[wk]W/GGGG';
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('HUI Service Client',() => {
const invalidAggregation = 'invalidaggregation';

if (mockAPI) {
nock(baseUrl)
nock(`${baseUrl}/hui`)
.get(`/licences/${licenceId}?aggregation=${invalidAggregation}&from=${weekStartDate}&to=${weekEndDate}&device=media%20player`)
.reply(400, 'Bad Request');
}
Expand All @@ -67,7 +67,7 @@ describe('HUI Service Client',() => {
const aggregation = 'week';

if (mockAPI) {
nock(baseUrl)
nock(`${baseUrl}/hui`)
.get(`/licences/${licenceId}?aggregation=${aggregation}&from=${weekStartDate}&to=${weekEndDate}&device=media%20player`)
.reply(200, require('./mocks/fixtures/getUsageByWeek'));
}
Expand All @@ -86,7 +86,7 @@ describe('HUI Service Client',() => {
const aggregation = 'month';

if (mockAPI) {
nock(baseUrl)
nock(`${baseUrl}/hui`)
.get(`/licences/${licenceId}?aggregation=${aggregation}&from=${monthStartDate}&to=${monthEndDate}&device=media%20player`)
.reply(200, require('./mocks/fixtures/getUsageByMonth'));
}
Expand Down
2 changes: 1 addition & 1 deletion test/userProfileClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const env = require('./helpers/env');
const qs = require('querystring');
const expectOwnProperties = require('./helpers/expectExtensions').expectOwnProperties;
const mockAPI = env.USE_MOCK_API;
const baseUrl = `${require('./../lib/helpers/config').USER_PROFILE_API_URL}/users`;
const baseUrl = `${require('./../lib/helpers/config').API_GATEWAY_HOST}/users`;

describe('User Profile Service Client', () => {
let logMessageStub;
Expand Down