-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathConfig.js
More file actions
68 lines (59 loc) · 1.9 KB
/
Config.js
File metadata and controls
68 lines (59 loc) · 1.9 KB
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
66
67
68
async function decrypt(
projectId = 'leverege-dev-yitaek', // Your GCP projectId
keyRingId = 'bb-pr-bot',
locationId = 'us-east4', // Name of the crypto key's key ring
cryptoKeyId = 'bb-pr-bot-key', // Name of the crypto key, e.g. "my-key"
ciphertextFileName = '.env.enc',
) {
const fs = require('fs');
const {promisify} = require('util')
const dotenv = require('dotenv')
const kms = require('@google-cloud/kms')
const client = new kms.KeyManagementServiceClient()
const readFile = promisify(fs.readFile)
const ciphertext = await readFile(ciphertextFileName)
const name = client.cryptoKeyPath(
projectId,
locationId,
keyRingId,
cryptoKeyId
)
// Decrypts the file using the specified crypto key
const [result] = await client.decrypt({name, ciphertext})
const envConfig = dotenv.parse(result.plaintext)
return envConfig
}
async function create() {
let envConfig = require('dotenv').config()
if (process.env.K_SERVICE) {
envConfig = await decrypt()
}
const config = {
bitbucket: {
auth: {
type: 'basic',
username: process.env.USERNAME || envConfig.USERNAME,
password: process.env.PASSWORD || envConfig.PASSWORD,
},
teamName: process.env.TEAMNAME || envConfig.TEAMNAME,
projects: process.env.BB_PROJECTS || envConfig.BB_PROJECTS
},
slack: {
webhook: {
url: process.env.SLACK_WEBHOOK_URL || envConfig.SLACK_WEBHOOK_URL,
defaults: {
username: process.env.SLACK_BOT_NAME || envConfig.SLACK_BOT_NAME,
icon_emoji: process.env.SLACK_BOT_EMOJI || envConfig.SLACK_BOT_EMOJI
}
}
},
parser: {
type: process.env.SLACK_MESSAGE_PARSER || envConfig.SLACK_MESSAGE_PARSER,
options: JSON.parse(process.env.SLACK_MESSAGE_PARSER_OPTIONS || envConfig.SLACK_MESSAGE_PARSER_OPTIONS || '{}')
}
}
return config
}
module.exports = {
create
}