Skip to content

Commit

Permalink
Merge pull request #43 from agility/envvars
Browse files Browse the repository at this point in the history
added ability to set configs using environment variables.
  • Loading branch information
James Vidler authored Jan 24, 2020
2 parents 47431d3 + 8ef9335 commit b643db9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,33 @@ const defaultConfig = {
}
};

function buildEnvConfig() {
let env = process.env;
let envConfig = {};
if (env.hasOwnProperty('AGILITY_BASEURL')) {
envConfig.baseUrl = env.AGILITY_BASEURL;
}
if (env.hasOwnProperty('AGILITY_GUID')) {
envConfig.guid = env.AGILITY_GUID;
}
if (env.hasOwnProperty('AGILITY_APIKEY')) {
envConfig.apiKey = env.AGILITY_APIKEY;
}
if (env.hasOwnProperty('AGILITY_ISPREVIEW')){
envConfig.isPreview = env.AGILITY_ISPREVIEW;
}

return envConfig;
}

export default function createClient(userConfig) {

let envConfig = buildEnvConfig();

//merge our config - user values will override our defaults
let config = {
...defaultConfig,
...envConfig,
...userConfig
};

Expand Down
3 changes: 2 additions & 1 deletion test/getContentList.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ describe('getContentList:', function() {
api.getContentList({
referenceName: 'posts',
languageCode: 'en-us',
filters: [{property: 'contentID', operator: api.types.FilterOperators.EQUAL_TO, value: '16'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}]
filters: [{property: 'contentID', operator: api.types.FilterOperators.EQUAL_TO, value: '16'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}],
filtersLogicOperator: api.types.FilterLogicOperators.AND
})
.then(function(contentList) {
assert.strictEqual(contentList.items[0].contentID, 16);
Expand Down

0 comments on commit b643db9

Please sign in to comment.