Skip to content

Commit 88d0466

Browse files
committed
Add in support for resource servers
1 parent 04b3118 commit 88d0466

File tree

2 files changed

+51
-45
lines changed

2 files changed

+51
-45
lines changed

es5/context.js

+25-22
Original file line numberDiff line numberDiff line change
@@ -123,67 +123,67 @@ var getRules = function getRules(dirPath) {
123123
/*
124124
* Process a single database script.
125125
*/
126-
var processClientConfig = function processClientConfig(clientName, clientFiles) {
127-
var client = {
128-
name: clientName
126+
var processConfigurableConfig = function processConfigurableConfig(configurableName, configurableFiles) {
127+
var configurable = {
128+
name: configurableName
129129
};
130130

131131
var attributeNames = [{ name: 'configFileName', content: 'configFile' }, { name: 'metadataFileName', content: 'metadataFile' }];
132132

133133
var filePromises = [];
134134
attributeNames.forEach(function (names) {
135-
if (names.name in clientFiles) {
136-
filePromises.push(fs.readFileAsync(clientFiles[names.name], 'utf8').then(function (contents) {
137-
client[names.content] = contents;
135+
if (names.name in configurableFiles) {
136+
filePromises.push(fs.readFileAsync(configurableFiles[names.name], 'utf8').then(function (contents) {
137+
configurable[names.content] = contents;
138138
}));
139139
}
140140
});
141141

142142
return _bluebird2.default.all(filePromises).then(function () {
143-
return client;
143+
return configurable;
144144
});
145145
};
146146

147147
/*
148-
* Get all database scripts.
148+
* Get all configurable items.
149149
*/
150-
var getClientConfigs = function getClientConfigs(dirPath) {
151-
var clients = {};
150+
var getConfigurableConfigs = function getConfigurableConfigs(dirPath, type) {
151+
var configurables = {};
152152

153153
// Determine if we have the script, the metadata or both.
154154
try {
155155
fs.accessSync(dirPath, fs.F_OK);
156156
return fs.readdirAsync(dirPath).then(function (files) {
157157
files.forEach(function (fileName) {
158-
_logger2.default.debug("Found client file: " + fileName);
158+
_logger2.default.debug("Found " + type + " file: " + fileName);
159159
/* check for meta/config pairs */
160160
var fullFileName = path.join(dirPath, fileName);
161-
var clientName = path.parse(fileName).name;
161+
var configurableName = path.parse(fileName).name;
162162
var meta = false;
163163

164164
/* check for meta files */
165-
if (clientName.endsWith('.meta')) {
166-
clientName = path.parse(clientName).name;
165+
if (configurableName.endsWith('.meta')) {
166+
configurableName = path.parse(configurableName).name;
167167
meta = true;
168168
}
169169

170170
/* Initialize object if needed */
171-
clients[clientName] = clients[clientName] || {};
171+
configurables[configurableName] = configurables[configurableName] || {};
172172

173173
if (meta) {
174-
clients[clientName].metadataFileName = fullFileName;
174+
configurables[configurableName].metadataFileName = fullFileName;
175175
} else {
176-
clients[clientName].configFileName = fullFileName;
176+
configurables[configurableName].configFileName = fullFileName;
177177
}
178178
});
179179
}).then(function () {
180-
return _bluebird2.default.map(Object.keys(clients), function (clientName) {
181-
return processClientConfig(clientName, clients[clientName]);
180+
return _bluebird2.default.map(Object.keys(configurables), function (configurableName) {
181+
return processConfigurableConfig(configurableName, configurables[configurableName]);
182182
}, { concurrency: 2 });
183183
});
184184
} catch (e) {
185185
if (e.code === "ENOENT") {
186-
_logger2.default.debug("No clients configured");
186+
_logger2.default.debug("No " + type + "s configured");
187187
} else {
188188
return _bluebird2.default.reject(e);
189189
}
@@ -372,15 +372,17 @@ var getChanges = function getChanges(filePath) {
372372
rules: getRules(path.join(fullPath, _auth0SourceControlExtensionTools.constants.RULES_DIRECTORY)),
373373
pages: getPages(path.join(fullPath, _auth0SourceControlExtensionTools.constants.PAGES_DIRECTORY)),
374374
databases: getDatabaseScripts(path.join(fullPath, _auth0SourceControlExtensionTools.constants.DATABASE_CONNECTIONS_DIRECTORY)),
375-
clients: getClientConfigs(path.join(fullPath, _auth0SourceControlExtensionTools.constants.CLIENTS_DIRECTORY))
375+
clients: getConfigurableConfigs(path.join(fullPath, _auth0SourceControlExtensionTools.constants.CLIENTS_DIRECTORY), 'client'),
376+
resourceServers: getConfigurableConfigs(path.join(fullPath, _auth0SourceControlExtensionTools.constants.RESOURCE_SERVERS_DIRECTORY), 'resource server')
376377
};
377378

378379
return _bluebird2.default.props(promises).then(function (result) {
379380
return {
380381
rules: (0, _auth0SourceControlExtensionTools.unifyScripts)(result.rules),
381382
databases: (0, _auth0SourceControlExtensionTools.unifyDatabases)(result.databases),
382383
pages: (0, _auth0SourceControlExtensionTools.unifyScripts)(result.pages),
383-
clients: (0, _auth0SourceControlExtensionTools.unifyConfigs)(result.clients)
384+
clients: (0, _auth0SourceControlExtensionTools.unifyConfigs)(result.clients),
385+
resourceServers: (0, _auth0SourceControlExtensionTools.unifyConfigs)(result.resourceServers)
384386
};
385387
});
386388
} else if (lstat.isFile()) {
@@ -410,6 +412,7 @@ var _class = function () {
410412
me.rules = data.rules || {};
411413
me.databases = data.databases || [];
412414
me.clients = data.clients || {};
415+
me.resourceServers = data.resourceServers || {};
413416
});
414417
}
415418
}]);

src/context.js

+26-23
Original file line numberDiff line numberDiff line change
@@ -98,67 +98,67 @@ const getRules = (dirPath) => {
9898
/*
9999
* Process a single database script.
100100
*/
101-
const processClientConfig = (clientName, clientFiles) => {
102-
const client = {
103-
name: clientName,
101+
const processConfigurableConfig = (configurableName, configurableFiles) => {
102+
const configurable = {
103+
name: configurableName,
104104
};
105105

106106
const attributeNames = [ { name: 'configFileName', content: 'configFile' }, { name: 'metadataFileName', content: 'metadataFile' } ];
107107

108108
const filePromises = [];
109109
attributeNames.forEach(function(names) {
110-
if (names.name in clientFiles) {
111-
filePromises.push(fs.readFileAsync(clientFiles[names.name], 'utf8').then(
110+
if (names.name in configurableFiles) {
111+
filePromises.push(fs.readFileAsync(configurableFiles[names.name], 'utf8').then(
112112
(contents) => {
113-
client[names.content] = contents;
113+
configurable[names.content] = contents;
114114
}));
115115
}
116116
});
117117

118118
return Promise.all(filePromises)
119-
.then(() => client);
119+
.then(() => configurable);
120120
};
121121

122122
/*
123-
* Get all database scripts.
123+
* Get all configurable items.
124124
*/
125-
const getClientConfigs = (dirPath) => {
126-
const clients = {};
125+
const getConfigurableConfigs = (dirPath, type) => {
126+
const configurables = {};
127127

128128
// Determine if we have the script, the metadata or both.
129129
try {
130130
fs.accessSync(dirPath, fs.F_OK);
131131
return fs.readdirAsync(dirPath).then((files) => {
132132
files.forEach(function (fileName) {
133-
logger.debug("Found client file: " + fileName);
133+
logger.debug("Found " + type + " file: " + fileName);
134134
/* check for meta/config pairs */
135135
const fullFileName = path.join(dirPath, fileName);
136-
let clientName = path.parse(fileName).name;
136+
let configurableName = path.parse(fileName).name;
137137
let meta = false;
138138

139139
/* check for meta files */
140-
if (clientName.endsWith('.meta')) {
141-
clientName = path.parse(clientName).name;
140+
if (configurableName.endsWith('.meta')) {
141+
configurableName = path.parse(configurableName).name;
142142
meta = true;
143143
}
144144

145145
/* Initialize object if needed */
146-
clients[clientName] = clients[clientName] || {};
146+
configurables[configurableName] = configurables[configurableName] || {};
147147

148148
if (meta) {
149-
clients[clientName].metadataFileName = fullFileName;
149+
configurables[configurableName].metadataFileName = fullFileName;
150150
} else {
151-
clients[clientName].configFileName = fullFileName;
151+
configurables[configurableName].configFileName = fullFileName;
152152
}
153153
});
154154
})
155-
.then(() => Promise.map(Object.keys(clients),
156-
(clientName) =>
157-
processClientConfig(clientName, clients[clientName]),
155+
.then(() => Promise.map(Object.keys(configurables),
156+
(configurableName) =>
157+
processConfigurableConfig(configurableName, configurables[configurableName]),
158158
{concurrency: 2}));
159159
} catch(e) {
160160
if (e.code === "ENOENT") {
161-
logger.debug("No clients configured");
161+
logger.debug("No " + type + "s configured");
162162
} else {
163163
return Promise.reject(e);
164164
}
@@ -349,15 +349,17 @@ const getChanges = (filePath) => {
349349
rules: getRules(path.join(fullPath, constants.RULES_DIRECTORY)),
350350
pages: getPages(path.join(fullPath, constants.PAGES_DIRECTORY)),
351351
databases: getDatabaseScripts((path.join(fullPath, constants.DATABASE_CONNECTIONS_DIRECTORY))),
352-
clients: getClientConfigs((path.join(fullPath, constants.CLIENTS_DIRECTORY)))
352+
clients: getConfigurableConfigs((path.join(fullPath, constants.CLIENTS_DIRECTORY)), 'client'),
353+
resourceServers: getConfigurableConfigs((path.join(fullPath, constants.RESOURCE_SERVERS_DIRECTORY)), 'resource server')
353354
};
354355

355356
return Promise.props(promises)
356357
.then((result) => ({
357358
rules: unifyScripts(result.rules),
358359
databases: unifyDatabases(result.databases),
359360
pages: unifyScripts(result.pages),
360-
clients: unifyConfigs(result.clients)
361+
clients: unifyConfigs(result.clients),
362+
resourceServers: unifyConfigs(result.resourceServers)
361363
}));
362364
} else if (lstat.isFile()) {
363365
/* If it is a file, parse it */
@@ -383,6 +385,7 @@ export default class {
383385
me.rules = data.rules || {};
384386
me.databases = data.databases || [];
385387
me.clients = data.clients || {};
388+
me.resourceServers = data.resourceServers || {};
386389
});
387390
}
388391
}

0 commit comments

Comments
 (0)