-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappconfig.sample.js
65 lines (62 loc) · 2.42 KB
/
appconfig.sample.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
65
/**
* THIS IS A SAMPLE APPCONFIG
*
* To use this file:
* 1. Copy it to appconfig.js, in the same directory
* 2. Go through each of the comments and replace the appropriate data to match your environment
*
* Within my personal implementation, I have this file located in a common directory so that other
* CLI utilities I've built can use it. That is why there would seem to be a little overkill
* on some of the variables - like the endpoints.
*/
const fs = require('fs');
/**
* The credentialsFile variable will read you AWS credentials. For Windows machines, this is normally located
* in your c:\\users\\<yourname>\\.aws\\credentials directory. Your location may be different
*
*/
const credentialsFile = fs.readFileSync("c:\\Users\\<yournamehere>\\.aws\\credentials").toString();
/**
* The AWSParams variable lets you specify different endpoints
* @type {{access: {cloud: {accessKeyId: string, secretAccessKey: string, region: string}, devserver: {accessKeyId: string, secretAccessKey: string, endpoint: string, region: string}, local: {accessKeyId: string, secretAccessKey: string, endpoint: string, region: string}}}}
*/
let AWSParams = {
access: {
// define where your AWS cloud is located. Don't worry about the accessKeyId or secretAccessKey.
// that is retrieved from your credentials
cloud: {
region: 'AWS-region-1',
},
// a devserver implementation
// accessKeyId and secretAccessKey doesn't matter
devserver: {
region: "local",
endpoint: "http://your-IP-address:port",
},
// a local computer implementation
// accessKeyId and secretAccessKey doesn't matter
local: {
region: "local",
endpoint: "localhost:port",
}
}
};
/**
* Now that we have the credentials, get the codes and build the variables
*/
const credentials = credentialsFile.split('\r\n');
let index = 0;
while (index < credentials.length && credentials[index] !== "[Publisher]") {
index++;
}
if (index < credentials.length - 3) {
const accessKeyId = credentials[index + 1].split('=')[1];
const secretAccessKey = credentials[index + 2].split('=')[1];
AWSParams.access.cloud.accessKeyId = accessKeyId;
AWSParams.access.cloud.secretAccessKey = secretAccessKey;
AWSParams.access.devserver.accessKeyId = accessKeyId;
AWSParams.access.devserver.secretAccessKey = secretAccessKey;
AWSParams.access.local.accessKeyId = accessKeyId;
AWSParams.access.local.secretAccessKey = secretAccessKey;
}
module.exports = { AWSParams };