Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions lib/helperFunctions/validateSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ export function githubSettingsValid (settings) {
}

// Validates Api umbrella configuration settings
export function apiUmbrellaSettingsValid (settings) {
export function apiUmbrellaSettingsValid (proxy) {

if ((typeof settings !== 'undefined') && settings.apiUmbrella) {
if ((typeof proxy !== 'undefined') && proxy.type === "apiUmbrella") {
if (
settings.apiUmbrella.host &&
settings.apiUmbrella.apiKey &&
settings.apiUmbrella.authToken &&
settings.apiUmbrella.baseUrl
proxy.apiUmbrella.url &&
proxy.apiUmbrella.apiKey &&
proxy.apiUmbrella.authToken
) {
return true;
}
Expand Down
36 changes: 14 additions & 22 deletions proxies/server/methods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { apiUmbrellaSettingsValid } from '/lib/helperFunctions/validateSettings';
import { Settings } from '/settings/collection';
import { Proxies } from '/proxies/collection';

Meteor.methods({
'syncApiUmbrellaUsers': function () {
Expand All @@ -23,34 +24,25 @@ Meteor.methods({
}
},
'createApiUmbrellaWeb': function () {
const settings = Settings.findOne();
// Assume one proxy only
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a TODO here mentioning that we need to refactor this method for multi-proxy support. That way we will remember what files to edit.

const proxy = Proxies.findOne();

// Check if API Umbrella Web settings are valid
if (apiUmbrellaSettingsValid(settings)) {
if (apiUmbrellaSettingsValid(proxy)) {
// Create config object for API Umbrella Web REST API
const config = {
baseUrl: settings.apiUmbrella.baseUrl,
apiKey: settings.apiUmbrella.apiKey,
authToken: settings.apiUmbrella.authToken,
baseUrl: proxy.apiUmbrella.url + '/api-umbrella/',
apiKey: proxy.apiUmbrella.apiKey,
authToken: proxy.apiUmbrella.authToken,
};

// Check whether API Umbrella Web instance exists
if (typeof apiUmbrellaWeb === 'undefined') {
try {
// Create new API Umbrella Web object for REST calls
apiUmbrellaWeb = new ApiUmbrellaWeb(config);
} catch (error) {
console.log(error);
}
} else {
try {
// Update existing API Umbrella Web object with new settings
apiUmbrellaWeb.baseUrl = config.baseUrl;
apiUmbrellaWeb.apiKey = config.apiKey;
apiUmbrellaWeb.authToken = config.authToken;
} catch (error) {
console.log(error);
}
try {
// Create new API Umbrella Web object for REST calls
const apiUmbrellaWeb = new ApiUmbrellaWeb(config);
// Return created object
return apiUmbrellaWeb;
} catch (error) {
console.log(error);
}
}
},
Expand Down