-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (38 loc) · 1.21 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
const core = require('@actions/core')
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3')
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
function parseInput () {
try {
return {
region: core.getInput('region', { required: true }),
accessKey: core.getInput('access_key', { required: true }),
secretAccessKey: core.getInput('secret_access_key', { required: true }),
bucket: core.getInput('bucket', { required: true }),
expiresIn: parseInt(core.getInput('expires_in', { required: false })),
path: core.getInput('path', { required: true })
}
} catch (error) {
core.setFailed('error parsing user input: ', error)
}
}
async function main () {
const { region, accessKey, secretAccessKey, bucket, expiresIn, path } = parseInput()
try {
const client = new S3Client({
region,
credentials: {
accessKeyId: accessKey,
secretAccessKey
}
})
const url = await getSignedUrl(client,
new GetObjectCommand({
Bucket: bucket,
Key: path
}), { expiresIn })
core.setOutput('url', url)
} catch (error) {
core.setFailed('error generating a presigned url: ', error)
}
}
main()