Skip to content
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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
config/local.js
config/sample.local.js
config/mock.local.js
config/m2m.local.js
node_modules
dist
.ebextensions
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,33 @@ 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`.<br>
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
```
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.<br>
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
Expand Down
35 changes: 35 additions & 0 deletions config/m2m.local.js
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
2 changes: 2 additions & 0 deletions src/tests/serviceMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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'));
};
6 changes: 3 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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: {
Expand Down Expand Up @@ -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 });
Expand Down