-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruslan Malogulko
committed
Feb 17, 2021
1 parent
d3a11b1
commit f3c33be
Showing
1 changed file
with
31 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
const fs = require('fs'); | ||
const url = require('url'); | ||
const fetch = require('node-fetch'); | ||
const HttpsProxyAgent = require('https-proxy-agent'); | ||
const urlParams = url.parse('http://{ACCESS_CREDENTIALS}@{VAULT_HOST}:{PORT}'); | ||
const agent = new HttpsProxyAgent({ | ||
...urlParams, | ||
ca: [fs.readFileSync('{CERT_LOCATION}')], | ||
}); | ||
const request = require('axios'); | ||
const tunnel = require('tunnel'); | ||
|
||
async function getData() { | ||
let result; | ||
try { | ||
result = await fetch('{VGS_SAMPLE_ECHO_SERVER}/post', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
account_number: '{ALIAS}', | ||
}), | ||
agent, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
return await result.text(); | ||
const tunnelingAgent = tunnel.httpsOverHttp({ | ||
ca: [ fs.readFileSync('{CERT_LOCATION}')], | ||
proxy: { | ||
host: '{VAULT_HOST}', | ||
port: '{PORT}', | ||
proxyAuth: '{ACCESS_CREDENTIALS}' | ||
} | ||
}); | ||
|
||
const redactedPayload = { | ||
account_number: '{ALIAS}', | ||
}; | ||
|
||
return await request.post( | ||
'{VGS_SAMPLE_ECHO_SERVER}/post', | ||
JSON.stringify(redactedPayload), | ||
{ | ||
httpsAgent: tunnelingAgent, | ||
proxy: false, | ||
headers: { | ||
'Content-Type':'application/json' | ||
} | ||
}).then((r) => { | ||
console.log('\\nResponse from Axios request on REVEAL:'); | ||
console.log(r.data); | ||
return r.data; | ||
}); | ||
} | ||
|
||
getData().then(response => console.log(response)); |