Skip to content

Commit 74c8fcf

Browse files
author
vikasrohit
authored
Merge pull request #268 from topcoder-platform/feature/use-m2m-token
use M2M token for Identity and Member services
2 parents 529a624 + 19f0767 commit 74c8fcf

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
config/local.js
2-
config/sample.local.js
2+
config/mock.local.js
3+
config/m2m.local.js
34
node_modules
45
dist
56
.ebextensions

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,33 @@ Microservice to manage CRUD operations for all things Projects.
3232
*NOTE: In production these dependencies / services are hosted & managed outside tc-projects-service.*
3333

3434
* Local config
35+
36+
There are two prepared configs:
37+
- if you have M2M environment variables provided: `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET`, `AUTH0_URL`, `AUTH0_AUDIENCE` then use `config/m2m.local.js`
38+
- otherwise use `config/mock.local.js`.
39+
40+
To apply any of these config copy it to `config/local.js`:
41+
3542
```bash
36-
# in the tc-project-service root folder, not inside local/ as above
37-
cp config/sample.local.js config/local.js
43+
cp config/mock.local.js config/local.js
44+
# or
45+
cp config/m2m.local.js config/local.js
3846
```
39-
Copy `config/sample.local.js` as `config/local.js`.<br>
40-
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.
4147

42-
**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.
48+
`config/local.js` has a prepared configuration which would replace values no matter what `NODE_ENV` value is.
49+
50+
**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.
4351
For example, you can add a the next line to your `/etc/hosts` file, if docker is run on IP `127.0.0.1`.
4452
```
4553
127.0.0.1 dockerhost
4654
```
4755
Alternatively, you may update `config/local.js` and replace `dockerhost` with your docker IP address.<br>
4856
You may try using command `docker-machine ip` to get your docker IP, but it works not for all systems.
4957

58+
Explanation of configs:
59+
- `config/mock.local.js` - Use local `mock-services` from docker to mock Identity and Member services instead of using deployed at Topcoder dev environment.
60+
- `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.
61+
5062
* Create tables in DB
5163
```bash
5264
NODE_ENV=development npm run sync:db

config/m2m.local.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// force using test.json for unit tests
2+
3+
let config;
4+
if (process.env.NODE_ENV === 'test') {
5+
config = require('./test.json');
6+
} else {
7+
config = {
8+
identityServiceEndpoint: "https://api.topcoder-dev.com/",
9+
authSecret: 'secret',
10+
authDomain: 'topcoder-dev.com',
11+
logLevel: 'debug',
12+
captureLogs: 'false',
13+
logentriesToken: '',
14+
rabbitmqURL: 'amqp://dockerhost:5672',
15+
fileServiceEndpoint: 'https://api.topcoder-dev.com/v3/files/',
16+
directProjectServiceEndpoint: 'https://api.topcoder-dev.com/v3/direct',
17+
connectProjectsUrl: 'https://connect.topcoder-dev.com/projects/',
18+
memberServiceEndpoint: 'https://api.topcoder-dev.com/v3/members',
19+
dbConfig: {
20+
masterUrl: 'postgres://coder:mysecretpassword@dockerhost:5432/projectsdb',
21+
maxPoolSize: 50,
22+
minPoolSize: 4,
23+
idleTimeout: 1000,
24+
},
25+
elasticsearchConfig: {
26+
host: 'dockerhost:9200',
27+
// target elasticsearch 2.3 version
28+
apiVersion: '2.3',
29+
indexName: 'projects',
30+
docType: 'projectV4'
31+
},
32+
whitelistedOriginsForUserIdAuth: "[\"\"]",
33+
};
34+
}
35+
module.exports = config;
File renamed without changes.

src/tests/serviceMocks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import _ from 'lodash';
66
// we do need to test elasticsearch indexing
77
import config from 'config';
88
import elasticsearch from 'elasticsearch';
9+
import util from '../util';
910

1011
module.exports = (app) => {
1112
_.assign(app.services, {
@@ -17,4 +18,5 @@ module.exports = (app) => {
1718
});
1819
sinon.stub(app.services.pubsub, 'init', () => Promise.resolve(true));
1920
sinon.stub(app.services.pubsub, 'publish', () => Promise.resolve(true));
21+
sinon.stub(util, 'getM2MToken', () => Promise.resolve('MOCK_TOKEN'));
2022
};

src/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ _.assignIn(util, {
339339
*/
340340
getMemberDetailsByUserIds: Promise.coroutine(function* (userIds, logger, requestId) { // eslint-disable-line func-names
341341
try {
342-
const token = yield this.getSystemUserToken(logger);
342+
const token = yield this.getM2MToken();
343343
const httpClient = this.getHttpClient({ id: requestId, log: logger });
344344
if (logger) {
345345
logger.trace(userIds);
@@ -364,7 +364,7 @@ _.assignIn(util, {
364364
*/
365365
getUserRoles: Promise.coroutine(function* (userId, logger, requestId) { // eslint-disable-line func-names
366366
try {
367-
const token = yield this.getSystemUserToken(logger);
367+
const token = yield this.getM2MToken();
368368
const httpClient = this.getHttpClient({ id: requestId, log: logger });
369369
return httpClient.get(`${config.identityServiceEndpoint}roles`, {
370370
params: {
@@ -449,7 +449,7 @@ _.assignIn(util, {
449449
filter += '&like=true';
450450
}
451451
req.log.trace('filter for users api call', filter);
452-
return util.getSystemUserToken(req.log)
452+
return util.getM2MToken()
453453
.then((token) => {
454454
req.log.debug(`Bearer ${token}`);
455455
const httpClient = util.getHttpClient({ id: req.id, log: req.log });

0 commit comments

Comments
 (0)