-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (35 loc) · 1018 Bytes
/
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
const fetch = require('node-fetch');
const aws4 = require('aws4');
const https = require('https');
const requestOptions = {
method: 'PUT',
headers: {
"Content-Type": "application/json",
},
service: 'es',
region: process.env.ES_REGION,
path: `/_snapshot/${process.env.SNAPSHOT_NAME}`,
agent: new https.Agent({
rejectUnauthorized: false,
}),
body: JSON.stringify({
type: "s3",
settings: {
bucket: process.env.BUCKET_NAME,
base_path: process.env.BUCKET_PATH,
region: process.env.S3_REGION,
role_arn: process.env.ROLE_ARN,
readonly: process.env.READ_ONLY || false,
}
})
};
const register = (options) => {
aws4.sign(options, {
accessKeyId: process.env.ACCESS_KEY,
secretAccessKey: process.env.SECRET_KEY,
});
return fetch(`https://localhost:${process.env.LOCAL_ES_PORT}/_snapshot/${process.env.SNAPSHOT_NAME}`, options)
.then(result => result.json())
.then(result => console.log('result', result))
}
register(requestOptions);