Skip to content

Commit 5990484

Browse files
authored
Merge pull request #325 from smartdevicelink/develop
3.1.1 Release
2 parents 3d66fd1 + 573788f commit 5990484

File tree

8 files changed

+851
-1535
lines changed

8 files changed

+851
-1535
lines changed

app/v1/about/controller.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const app = require('../app');
22
const config = require('../../../settings.js');
33
const packageJson = require('../../../package.json'); //configuration module
4-
const requestjs = require('request');
4+
const https = require('https');
55
const semver = require('semver');
66
const certificateController = require('../certificates/controller.js');
77

@@ -34,25 +34,41 @@ exports.getInfo = function (req, res, next) {
3434
};
3535

3636
// cannot use promisify: there are two returns we need
37-
requestjs({
38-
"method": "GET",
39-
"uri": "https://raw.githubusercontent.com/smartdevicelink/sdl_server/master/package.json",
40-
"timeout": 5000,
41-
"json": true
42-
}, async function (err, response, body) {
43-
if (!err && response.statusCode >= 200 && response.statusCode < 300) {
44-
// success!
45-
data.latest_version = body.version;
46-
data.is_update_available = semver.lt(data.current_version, data.latest_version);
47-
data.update_type = semver.diff(data.current_version, data.latest_version);
48-
}
49-
if (data.certificate_authority) {
50-
const isAuthorityValid = await certificateController.checkAuthorityValidity();
51-
data.is_authority_valid = isAuthorityValid && data.certificate_authority;
52-
}
53-
54-
res.parcel.setStatus(200)
55-
.setData(data)
56-
.deliver();
57-
});
37+
const httpOptions = {
38+
method: "GET",
39+
timeout: 5000,
40+
}
41+
https.request("https://raw.githubusercontent.com/smartdevicelink/sdl_server/master/package.json", httpOptions,
42+
async function (response) {
43+
let aggregateResponse = '';
44+
response.setEncoding('utf8');
45+
response.on('data', (chunk) => {
46+
aggregateResponse += chunk;
47+
});
48+
response.on('end', async () => {
49+
if (response.statusCode >= 200 && response.statusCode < 300) {
50+
// success!
51+
data.latest_version = JSON.parse(aggregateResponse).version;
52+
data.is_update_available = semver.lt(data.current_version, data.latest_version);
53+
data.update_type = semver.diff(data.current_version, data.latest_version);
54+
}
55+
if (data.certificate_authority) {
56+
const isAuthorityValid = await certificateController.checkAuthorityValidity();
57+
data.is_authority_valid = isAuthorityValid && data.certificate_authority;
58+
}
59+
60+
res.parcel.setStatus(200)
61+
.setData(data)
62+
.deliver();
63+
})
64+
}).on('error', async () => {
65+
if (data.certificate_authority) {
66+
const isAuthorityValid = await certificateController.checkAuthorityValidity();
67+
data.is_authority_valid = isAuthorityValid && data.certificate_authority;
68+
}
69+
70+
res.parcel.setStatus(200)
71+
.setData(data)
72+
.deliver();
73+
}).end();
5874
}

app/v1/messages/helper.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const setupSql = app.locals.db.setupSqlCommand;
44
const sql = require('./sql.js');
55
const model = require('./model.js');
66
const parseXml = require('xml2js').parseString;
7-
const request = require('request');
7+
const https = require('https');
88
const promisify = require('util').promisify;
99

1010
//validation functions
@@ -150,14 +150,16 @@ async function updateLanguages () {
150150

151151
async function getRpcSpec () {
152152
return new Promise(resolve => {
153-
request(
154-
{
155-
method: 'GET',
156-
url: app.locals.config.rpcSpecXmlUrl
157-
}, function (err, res, body) {
158-
resolve(body);
159-
}
160-
);
153+
https.request(app.locals.config.rpcSpecXmlUrl, { method: 'GET' }, (response) => {
154+
let aggregateResponse = '';
155+
response.setEncoding('utf8');
156+
response.on('data', (chunk) => {
157+
aggregateResponse += chunk;
158+
});
159+
response.on('end', () => {
160+
resolve(aggregateResponse);
161+
})
162+
}).end();
161163
});
162164
}
163165

app/v1/shaid/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const request = require('request');
21
const shaidkit = require('shaidkit');
32
const config = require('../../../settings.js');
43
const package = require('../../../package.json');

customizable/webengine-bundle/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// skeleton function for customized downloading and extracting of package information
22

3-
const request = require('request');
3+
const http = require('http');
44
const fs = require('fs');
55
const UUID = require('uuid');
66

docker/Dockerfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Copyright (c) 2022, Livio, Inc.
2-
FROM node:12
2+
FROM debian:11.7
33

44
ARG VERSION=master
55

66
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
ca-certificates \
78
openssl \
89
curl \
10+
wget \
11+
xz-utils \
912
git
1013

1114
# Download SDL Server from github
@@ -14,10 +17,17 @@ WORKDIR /usr
1417
RUN mkdir /usr/policy
1518
RUN git clone https://github.com/smartdevicelink/sdl_server.git /usr/policy -b $VERSION --depth=1
1619

20+
# Install node + npm
21+
RUN wget https://nodejs.org/dist/v16.20.1/node-v16.20.1-linux-x64.tar.xz
22+
RUN tar xvf node-v16.20.1-linux-x64.tar.xz
23+
RUN chmod +rx node-v16.20.1-linux-x64/bin/node node-v16.20.1-linux-x64/bin/npm
24+
RUN ln -s /usr/node-v16.20.1-linux-x64/bin/node /usr/local/bin/node
25+
RUN ln -s /usr/node-v16.20.1-linux-x64/bin/npm /usr/local/bin/npm
26+
1727
WORKDIR /usr/policy
1828

19-
RUN npm install
20-
RUN npm install aws-sdk node-stream-zip --save
29+
RUN npm install --legacy-peer-deps
30+
RUN npm install aws-sdk@2.1453.0 node-stream-zip@1.15.0 --save --legacy-peer-deps
2131

2232
COPY wait-for-it.sh wait-for-it.sh
2333
COPY keys customizable/ca

docker/webengine-bundle.js

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// skeleton function for customized downloading and extracting of package information
2-
const request = require('request');
2+
const http = require('http');
3+
const https = require('https');
34
const fs = require('fs');
45
const UUID = require('uuid');
56
const AWS = require('aws-sdk');
67
const StreamZip = require('node-stream-zip');
8+
// assumes the bucket already exists. make sure it is set up to allow writing objects to it from remote sources!
79
const BUCKET_NAME = process.env.BUCKET_NAME;
810

911
if (process.env.AWS_REGION !== undefined && BUCKET_NAME !== undefined) {
@@ -32,52 +34,42 @@ exports.handleBundle = function (package_url, cb) {
3234
let bucketUrl = '';
3335
const TMP_FILE_NAME = `${UUID.v4()}.zip`;
3436

35-
// create a new bucket if it doesn't already exist
36-
new AWS.S3().createBucket({Bucket: BUCKET_NAME, ACL: 'public-read'}, err => {
37-
38-
// OperationAborted errors are expected, as we are potentially
39-
// calling this API multiple times simultaneously
40-
if (err && err.code !== 'OperationAborted') {
41-
console.log(err);
42-
return cb(err);
43-
}
44-
// read the URL and save it to a buffer variable
45-
readUrlToBuffer(package_url)
46-
.then(zipBuffer => { // submit the file contents to S3
47-
compressedSize = zipBuffer.length;
48-
const randomString = UUID.v4();
49-
const fileName = `${randomString}.zip`;
50-
bucketUrl = `https://${BUCKET_NAME}.s3.amazonaws.com/${fileName}`;
51-
// make the bundle publicly accessible
52-
const objectParams = {Bucket: BUCKET_NAME, ACL: 'public-read', Key: fileName, Body: zipBuffer};
53-
// Create object upload promise
54-
return new AWS.S3().putObject(objectParams).promise();
55-
})
56-
.then(() => { // unzip the contents of the bundle to get its uncompressed data information
57-
return streamUrlToTmpFile(bucketUrl, TMP_FILE_NAME);
58-
})
59-
.then(() => {
60-
return unzipAndGetUncompressedSize(TMP_FILE_NAME);
61-
})
62-
.then(uncompressedSize => {
63-
// delete the tmp zip file
64-
fs.unlink(TMP_FILE_NAME, () => {
65-
// all the information has been collected
66-
cb(null, {
67-
url: bucketUrl,
68-
size_compressed_bytes: compressedSize,
69-
size_decompressed_bytes: uncompressedSize
70-
});
71-
});
72-
})
73-
.catch(err => {
74-
console.log(err);
75-
// delete the tmp zip file
76-
fs.unlink(TMP_FILE_NAME, () => {
77-
cb(err);
37+
// read the URL and save it to a buffer variable
38+
readUrlToBuffer(package_url)
39+
.then(zipBuffer => { // submit the file contents to S3
40+
compressedSize = zipBuffer.length;
41+
const randomString = UUID.v4();
42+
const fileName = `${randomString}.zip`;
43+
bucketUrl = `https://${BUCKET_NAME}.s3.amazonaws.com/${fileName}`;
44+
// make the bundle publicly accessible
45+
const objectParams = {Bucket: BUCKET_NAME, ACL: 'public-read', Key: fileName, Body: zipBuffer};
46+
// Create object upload promise
47+
return new AWS.S3().putObject(objectParams).promise();
48+
})
49+
.then(() => { // unzip the contents of the bundle to get its uncompressed data information
50+
return streamUrlToTmpFile(bucketUrl, TMP_FILE_NAME);
51+
})
52+
.then(() => {
53+
return unzipAndGetUncompressedSize(TMP_FILE_NAME);
54+
})
55+
.then(uncompressedSize => {
56+
// delete the tmp zip file
57+
fs.unlink(TMP_FILE_NAME, () => {
58+
// all the information has been collected
59+
cb(null, {
60+
url: bucketUrl,
61+
size_compressed_bytes: compressedSize,
62+
size_decompressed_bytes: uncompressedSize
7863
});
7964
});
80-
});
65+
})
66+
.catch(err => {
67+
console.log(err);
68+
// delete the tmp zip file
69+
fs.unlink(TMP_FILE_NAME, () => {
70+
cb(err);
71+
});
72+
});
8173
}
8274

8375
function unzipAndGetUncompressedSize (fileName) {
@@ -109,24 +101,37 @@ function unzipAndGetUncompressedSize (fileName) {
109101
}
110102

111103
function streamUrlToTmpFile (url, fileName) {
104+
const urlObj = new URL(url);
112105
return new Promise((resolve, reject) => {
113-
request(url)
114-
.pipe(fs.createWriteStream(fileName))
115-
.on('close', resolve);
106+
function resCallback (res) {
107+
res.pipe(fs.createWriteStream(fileName)).on('close', resolve);
108+
}
109+
if (urlObj.protocol === "https:") {
110+
https.get(url, resCallback).end();
111+
} else {
112+
http.get(url, resCallback).end();
113+
}
116114
});
117115
}
118116

119117
function readUrlToBuffer (url) {
118+
const urlObj = new URL(url);
120119
return new Promise((resolve, reject) => {
121120
let zipBuffer = [];
122-
123-
request(url)
124-
.on('data', data => {
121+
function resCallback (res) {
122+
res.on('data', data => {
125123
zipBuffer.push(data);
126124
})
127125
.on('close', function () { // file fully downloaded
128126
// put the zip contents to a buffer
129127
resolve(Buffer.concat(zipBuffer));
130128
});
129+
}
130+
131+
if (urlObj.protocol === "https:") {
132+
https.get(url, resCallback).end();
133+
} else {
134+
http.get(url, resCallback).end();
135+
}
131136
})
132137
}

0 commit comments

Comments
 (0)