diff --git a/.eslintignore b/.eslintignore
index 5eb52385..7674d60e 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,5 +1,6 @@
config/local.js
-config/sample.local.js
+config/mock.local.js
+config/m2m.local.js
node_modules
dist
.ebextensions
diff --git a/README.md b/README.md
index f0417f5e..3b5b3f6f 100644
--- a/README.md
+++ b/README.md
@@ -32,14 +32,22 @@ Microservice to manage CRUD operations for all things Projects.
*NOTE: In production these dependencies / services are hosted & managed outside tc-projects-service.*
* Local config
+
+ There are two prepared configs:
+ - if you have M2M environment variables provided: `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE` then use `config/m2m.local.js`
+ - otherwise use `config/mock.local.js`.
+
+ To apply any of these config copy it to `config/local.js`:
+
```bash
- # in the tc-project-service root folder, not inside local/ as above
- cp config/sample.local.js config/local.js
+ cp config/mock.local.js config/local.js
+ # or
+ cp config/m2m.local.js config/local.js
```
- Copy `config/sample.local.js` as `config/local.js`.
- As project service depend on many third-party services we have to config how to access them. Some services are run locally and some services are used from Topcoder DEV environment. `config/local.js` has a prepared configuration which would replace values no matter what `NODE_ENV` value is.
- **IMPORTANT** This configuration file assumes that services run by docker use domain `dockerhost`. Depend on your system you have to make sure that domain `dockerhost` points to the IP address of docker.
+ `config/local.js` has a prepared configuration which would replace values no matter what `NODE_ENV` value is.
+
+ **IMPORTANT** These configuration files assume that docker containers are run on domain `dockerhost`. Depend on your system you have to make sure that domain `dockerhost` points to the IP address of docker.
For example, you can add a the next line to your `/etc/hosts` file, if docker is run on IP `127.0.0.1`.
```
127.0.0.1 dockerhost
@@ -47,6 +55,10 @@ Microservice to manage CRUD operations for all things Projects.
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.
You may try using command `docker-machine ip` to get your docker IP, but it works not for all systems.
+ Explanation of configs:
+ - `config/mock.local.js` - Use local `mock-services` from docker to mock Identity and Member services instead of using deployed at Topcoder dev environment.
+ - `config/m2m.local.js` - Use Identity and Member services deployed at Topcoder dev environment. This can be used only if you have M2M environment variables (`AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE`) provided to access Topcoder DEV environment services.
+
* Create tables in DB
```bash
NODE_ENV=development npm run sync:db
diff --git a/config/m2m.local.js b/config/m2m.local.js
new file mode 100644
index 00000000..9aef91f2
--- /dev/null
+++ b/config/m2m.local.js
@@ -0,0 +1,35 @@
+// force using test.json for unit tests
+
+let config;
+if (process.env.NODE_ENV === 'test') {
+ config = require('./test.json');
+} else {
+ config = {
+ identityServiceEndpoint: "https://api.topcoder-dev.com/",
+ authSecret: 'secret',
+ authDomain: 'topcoder-dev.com',
+ logLevel: 'debug',
+ captureLogs: 'false',
+ logentriesToken: '',
+ rabbitmqURL: 'amqp://dockerhost:5672',
+ fileServiceEndpoint: 'https://api.topcoder-dev.com/v3/files/',
+ directProjectServiceEndpoint: 'https://api.topcoder-dev.com/v3/direct',
+ connectProjectsUrl: 'https://connect.topcoder-dev.com/projects/',
+ memberServiceEndpoint: 'https://api.topcoder-dev.com/v3/members',
+ dbConfig: {
+ masterUrl: 'postgres://coder:mysecretpassword@dockerhost:5432/projectsdb',
+ maxPoolSize: 50,
+ minPoolSize: 4,
+ idleTimeout: 1000,
+ },
+ elasticsearchConfig: {
+ host: 'dockerhost:9200',
+ // target elasticsearch 2.3 version
+ apiVersion: '2.3',
+ indexName: 'projects',
+ docType: 'projectV4'
+ },
+ whitelistedOriginsForUserIdAuth: "[\"\"]",
+ };
+}
+module.exports = config;
diff --git a/config/sample.local.js b/config/mock.local.js
similarity index 100%
rename from config/sample.local.js
rename to config/mock.local.js
diff --git a/src/tests/serviceMocks.js b/src/tests/serviceMocks.js
index 70a2e9aa..662bd2c4 100644
--- a/src/tests/serviceMocks.js
+++ b/src/tests/serviceMocks.js
@@ -6,6 +6,7 @@ import _ from 'lodash';
// we do need to test elasticsearch indexing
import config from 'config';
import elasticsearch from 'elasticsearch';
+import util from '../util';
module.exports = (app) => {
_.assign(app.services, {
@@ -17,4 +18,5 @@ module.exports = (app) => {
});
sinon.stub(app.services.pubsub, 'init', () => Promise.resolve(true));
sinon.stub(app.services.pubsub, 'publish', () => Promise.resolve(true));
+ sinon.stub(util, 'getM2MToken', () => Promise.resolve('MOCK_TOKEN'));
};
diff --git a/src/util.js b/src/util.js
index d54d88d8..853e71c4 100644
--- a/src/util.js
+++ b/src/util.js
@@ -339,7 +339,7 @@ _.assignIn(util, {
*/
getMemberDetailsByUserIds: Promise.coroutine(function* (userIds, logger, requestId) { // eslint-disable-line func-names
try {
- const token = yield this.getSystemUserToken(logger);
+ const token = yield this.getM2MToken();
const httpClient = this.getHttpClient({ id: requestId, log: logger });
if (logger) {
logger.trace(userIds);
@@ -364,7 +364,7 @@ _.assignIn(util, {
*/
getUserRoles: Promise.coroutine(function* (userId, logger, requestId) { // eslint-disable-line func-names
try {
- const token = yield this.getSystemUserToken(logger);
+ const token = yield this.getM2MToken();
const httpClient = this.getHttpClient({ id: requestId, log: logger });
return httpClient.get(`${config.identityServiceEndpoint}roles`, {
params: {
@@ -449,7 +449,7 @@ _.assignIn(util, {
filter += '&like=true';
}
req.log.trace('filter for users api call', filter);
- return util.getSystemUserToken(req.log)
+ return util.getM2MToken()
.then((token) => {
req.log.debug(`Bearer ${token}`);
const httpClient = util.getHttpClient({ id: req.id, log: req.log });