Skip to content

Commit 529a624

Browse files
author
vikasrohit
authored
Merge pull request #265 from topcoder-platform/feature/fix-metadata-seed-script
fix seed metadata script
2 parents f4474ce + 03645d1 commit 529a624

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Microservice to manage CRUD operations for all things Projects.
5151
```bash
5252
NODE_ENV=development npm run sync:db
5353
```
54-
This command will crate tables in `postgres` db.
54+
This command will crate tables in `postgres` db.
5555

56-
*NOTE: this will drop tables if they already exist.*
56+
*NOTE: this will drop tables if they already exist.*
5757

5858
* Sync ES indices
5959
```bash
@@ -72,9 +72,11 @@ Microservice to manage CRUD operations for all things Projects.
7272

7373
### Import sample metadata
7474
```bash
75-
node migrations/seedMetadata.js
75+
CONNECT_USER_TOKEN=<connect user token> node migrations/seedMetadata.js
7676
```
77-
To create sample metadata entries (duplicate what is currently in development environment).
77+
This command will create sample metadata entries in the DB (duplicate what is currently in development environment).
78+
79+
To retrieve data from DEV env we need to provide a valid user token. You may login to http://connect.topcoder-dev.com and find the Bearer token in the request headers using browser dev tools.
7880

7981
### Run Connect App with Project Service locally
8082

migrations/seedMetadata.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,31 @@ const _ = require('lodash')
33
const axios = require('axios');
44
const Promise = require('bluebird');
55

6+
if (!process.env.CONNECT_USER_TOKEN) {
7+
console.error('This script requires environment variable CONNECT_USER_TOKEN to be defined. Login to http://connect.topcoder-dev.com and get your user token from the requests headers.')
8+
exit(1);
9+
}
10+
11+
// we need to know any logged in Connect user token to retrieve data from DEV
12+
const CONNECT_USER_TOKEN = process.env.CONNECT_USER_TOKEN;
613

714
var url = 'https://api.topcoder-dev.com/v4/projects/metadata';
815
var targetUrl = 'http://localhost:8001/v4/';
916
var destUrl = targetUrl + 'projects/';
1017
var destTimelines = targetUrl;
1118

12-
axios.get(url)
19+
axios.get(url, {
20+
headers: {
21+
'Content-Type': 'application/json',
22+
'Authorization': `Bearer ${CONNECT_USER_TOKEN}`
23+
}
24+
})
1325
.then(async function (response) {
1426
let data = response.data;
1527

1628
var headers = {
1729
'Content-Type': 'application/json',
18-
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw'
30+
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw'
1931
}
2032

2133

@@ -62,11 +74,9 @@ axios.get(url)
6274
.catch(e=>resolve()); //ignore the error
6375
})
6476
});
65-
66-
6777

6878
// handle success
6979
console.log('Done');
7080
}).catch(err=>{
71-
console.log(err);
81+
console.log(err && err.response ? err.response.data : err);
7282
});

0 commit comments

Comments
 (0)