-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 2.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var FormData = require('form-data');
var fs = require('fs');
var http = require('http');
// abstract and promisify actual network request
async function makeRequest(formData, options) {
return new Promise((resolve, reject) => {
const req = formData.submit(options, (err, res) => {
if (err) {
return reject(new Error(err.message))
}
if (res.statusCode < 200 || res.statusCode > 299) {
return reject(new Error(`HTTP status code ${res.statusCode}`))
}
const body = []
res.on('data', (chunk) => body.push(chunk))
res.on('end', () => {
const resString = Buffer.concat(body).toString()
resolve(resString)
})
})
})
}
const formData = new FormData()
formData.append('manifest', fs.createReadStream('./lx-manifest-demo.yml'))
formData.append('dependencies', fs.createReadStream('./mvn-licenses.xml'))
formData.append('data', JSON.stringify({"version": "9.1.0", "dependencyManager": "MAVEN"}), {contentType: 'application/json'})
const options = {
host: 'localhost:9690',
path: '/deployment',
method: 'POST',
protocol: 'https:', // note : in the end
headers: {
Authorization: `Bearer eyJraWQiOiI0MDJjODg3NTBjZmJhOGQzZTQ0NjE0YzQ5YjBlYzg3NiIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJhcmF2aW5kLm1ldGt1QGxlYW5peC5uZXQiLCJwcmluY2lwYWwiOnsiaWQiOiJjYzU2MDA5NC1kMTNhLTRmZjMtYTI1Yi05ZTlhYTBlMmY3NWMiLCJ1c2VybmFtZSI6ImFyYXZpbmQubWV0a3VAbGVhbml4Lm5ldCIsInJvbGUiOiJBQ0NPVU5UVVNFUiIsInN0YXR1cyI6IkFDVElWRSIsImFjY291bnQiOnsiaWQiOiI1YjA1NWMxYi0yZWEyLTQ1YmItOTMwNS00ODZkODMxZGU0YjUiLCJuYW1lIjoibGVhbml4In0sInBlcm1pc3Npb24iOnsiaWQiOiJjOGExZTRiOC04NmUwLTRmOTAtODFhYi1jZDc5M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