Created
May 13, 2020 18:19
-
-
Save daffl/05634864f94917f834ecf99ff006fa65 to your computer and use it in GitHub Desktop.
Using the 1Password CLI in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runOp = args => { | |
const cmd = 'op'; | |
const proc = spawn(cmd, args, { | |
stdio: [ | |
'inherit', | |
'pipe', | |
'inherit' | |
] | |
}); | |
return new Promise((resolve, reject) => { | |
let stdout = ''; | |
proc.stdout.on('data', data => (stdout += data.toString())); | |
proc.on('close', code => code ? reject(new Error(`1Password CLI exited with error status ${code}`)) : resolve(stdout)); | |
}).then(stdout => JSON.parse(stdout)); | |
} | |
runOp([ 'get', 'item', 'my-secret-key' ]).then(item => { | |
const { password } = item.details; | |
// Use secret password here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment