-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredentials
executable file
·38 lines (31 loc) · 961 Bytes
/
credentials
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
#!/usr/bin/env node
const crypto = require('crypto')
const authentication = require('../policies/gatekeeper/authentication')
const randomString = () => crypto.randomBytes(16).toString('hex')
const createCredentials = (id) => {
const [password, passwordSalt] = [randomString(), randomString()]
return [
password,
{
passwordSalt,
passwordHash: authentication.hashPassword(password, passwordSalt)
}
]
}
const [action, id] = process.argv.slice(2)
let password, cred
switch (action) {
case 'create':
case 'update':
[password, cred] = createCredentials(id)
console.log(`\nConfig entry to set in gateway.conf.yaml, below *.policies.gatekeeper.action.apps:\n
${id}:
passwordSalt: ${cred.passwordSalt}
passwordHash: ${cred.passwordHash}
`)
console.log(`\nBasic Auth token for ${id}:\n\n ${id}:${password}`)
break
default:
console.error('Usage: credentials (create|update) ID')
process.exit(1)
}