Skip to content

Commit a8f8b50

Browse files
build: use azure function to hash assets instead of lambda (#34119)
Co-authored-by: Samuel Attard <sattard@salesforce.com>
1 parent eb320cb commit a8f8b50

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

script/release/get-url-hash.js

+19-28
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
const AWS = require('aws-sdk');
2-
3-
const lambda = new AWS.Lambda({
4-
credentials: {
5-
accessKeyId: process.env.AWS_LAMBDA_EXECUTE_KEY,
6-
secretAccessKey: process.env.AWS_LAMBDA_EXECUTE_SECRET
7-
},
8-
region: 'us-east-1'
9-
});
1+
const got = require('got');
2+
const url = require('url');
103

114
module.exports = async function getUrlHash (targetUrl, algorithm = 'sha256', attempts = 3) {
5+
const options = {
6+
code: process.env.ELECTRON_ARTIFACT_HASHER_FUNCTION_KEY,
7+
targetUrl,
8+
algorithm
9+
};
10+
const search = new url.URLSearchParams(options);
11+
const functionUrl = url.format({
12+
protocol: 'https:',
13+
hostname: 'electron-artifact-hasher.azurewebsites.net',
14+
pathname: '/api/HashArtifact',
15+
search: search.toString()
16+
});
1217
try {
13-
return new Promise((resolve, reject) => {
14-
lambda.invoke({
15-
FunctionName: 'hasher',
16-
Payload: JSON.stringify({
17-
targetUrl,
18-
algorithm
19-
})
20-
}, (err, data) => {
21-
if (err) return reject(err);
22-
try {
23-
const response = JSON.parse(data.Payload);
24-
if (response.statusCode !== 200) return reject(new Error('non-200 status code received from hasher function'));
25-
if (!response.hash) return reject(new Error('Successful lambda call but failed to get valid hash'));
26-
resolve(response.hash);
27-
} catch (err) {
28-
return reject(err);
29-
}
30-
});
31-
});
18+
const resp = await got(functionUrl);
19+
if (resp.statusCode !== 200) throw new Error('non-200 status code received from hasher function');
20+
if (!resp.body) throw new Error('Successful lambda call but failed to get valid hash');
21+
22+
return resp.body.trim();
3223
} catch (err) {
3324
if (attempts > 1) {
3425
console.error('Failed to get URL hash for', targetUrl, 'we will retry', err);

0 commit comments

Comments
 (0)