This repository has been archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstoring-logs.js
64 lines (57 loc) · 1.95 KB
/
storing-logs.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
/***************************************************************************
*
* (C) Copyright IBM Corp. 2018
*
* This program and the accompanying materials are made available
* under the terms of the Apache License v2.0 which accompanies
* this distribution.
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* Contributors:
* Multiple authors (IBM Corp.) - initial implementation and documentation
***************************************************************************/
const IBMCloudObjectStore = require("ibm-cos-sdk");
const fs = require('fs');
const BUCKET = "module-insights-logs";
const API_KEY = process.env.API_KEY;
const INSTANCE_ID = process.env.INSTANCE_ID;
const MODULE = process.env.MODULE;
const MODULE_VERSION = process.env.MODULE_VERSION;
const OS = process.env.OS;
const ARCH = process.env.ARCH;
const NODE_VERSION = process.env.NODE_VERSION;
const WORKSPACE = process.env.WORKSPACE;
const LOG_FILE = `${WORKSPACE}/${MODULE}.tap`;
const FILE_NAME= `${MODULE}@${MODULE_VERSION}-${OS}-${ARCH}-${NODE_VERSION}.txt`;
const config = {
endpoint: "s3-api.us-geo.objectstorage.softlayer.net",
apiKeyId: API_KEY,
ibmAuthEndpoint: "https://iam.bluemix.net/identity/token",
serviceInstanceId: INSTANCE_ID
};
const objectStoreClient = new IBMCloudObjectStore.S3(config);
function createLogFile(BUCKET, FILE_NAME, LOG_FILE) {
console.log(`\nCreating new item: ${FILE_NAME}`);
const body = fs.readFileSync(LOG_FILE, 'utf8')
return objectStoreClient.putObject({
Bucket: BUCKET,
Key: FILE_NAME,
Body: body,
ACL: "public-read"
}).promise()
.then(() => {
return console.log(`Item: ${FILE_NAME} created!`);
})
.catch((e) => {
return console.log(`ERROR: ${e.code} - ${e.message}\n`);
});
}
async function creating(){
await createLogFile(BUCKET, FILE_NAME, LOG_FILE);
console.log("Finshed Adding Logs");
process.exit(0);
}
creating();