diff --git a/README.md b/README.md index f0417f5e..9e1cab7c 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,9 @@ Microservice to manage CRUD operations for all things Projects. ```bash NODE_ENV=development npm run sync:db ``` - This command will crate tables in `postgres` db. + This command will crate tables in `postgres` db. - *NOTE: this will drop tables if they already exist.* + *NOTE: this will drop tables if they already exist.* * Sync ES indices ```bash @@ -72,9 +72,11 @@ Microservice to manage CRUD operations for all things Projects. ### Import sample metadata ```bash -node migrations/seedMetadata.js +CONNECT_USER_TOKEN= node migrations/seedMetadata.js ``` -To create sample metadata entries (duplicate what is currently in development environment). +This command will create sample metadata entries in the DB (duplicate what is currently in development environment). + +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. ### Run Connect App with Project Service locally diff --git a/migrations/seedMetadata.js b/migrations/seedMetadata.js index 431daa8f..6309fe21 100644 --- a/migrations/seedMetadata.js +++ b/migrations/seedMetadata.js @@ -3,19 +3,31 @@ const _ = require('lodash') const axios = require('axios'); const Promise = require('bluebird'); +if (!process.env.CONNECT_USER_TOKEN) { + 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.') + exit(1); +} + +// we need to know any logged in Connect user token to retrieve data from DEV +const CONNECT_USER_TOKEN = process.env.CONNECT_USER_TOKEN; var url = 'https://api.topcoder-dev.com/v4/projects/metadata'; var targetUrl = 'http://localhost:8001/v4/'; var destUrl = targetUrl + 'projects/'; var destTimelines = targetUrl; -axios.get(url) +axios.get(url, { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${CONNECT_USER_TOKEN}` + } +}) .then(async function (response) { let data = response.data; var headers = { 'Content-Type': 'application/json', - 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw' + 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw' } @@ -62,11 +74,9 @@ axios.get(url) .catch(e=>resolve()); //ignore the error }) }); - - // handle success console.log('Done'); }).catch(err=>{ - console.log(err); + console.log(err && err.response ? err.response.data : err); });