Skip to content

Commit

Permalink
fix(chromeos): Create private key folder if missing (#90)
Browse files Browse the repository at this point in the history
In our deployment under a service account in `shaka-lab-node`, ~/.ssh
may not exist yet.
  • Loading branch information
joeyparrish authored May 15, 2024
1 parent f35eece commit f576b6c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backends/chromeos/chromeos-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ async function fetchPrivateKey(flags, log) {

const response = await fetch(flags.privateKeyUrl);
// The URL gives us the key in base64, but we can have the fs module
// decode it for us.
// decode it for us in writeFileSync.
const privateKeyBase64 = await response.text();

// If the folder doesn't exist, try to create it.
const privateKeyFolder = path.dirname(flags.privateKey);
if (!fs.existsSync(privateKeyFolder)) {
fs.mkdirSync(privateKeyFolder, {recursive: true});
}

// Write the file and set the permissions.
fs.writeFileSync(flags.privateKey, privateKeyBase64, 'base64');
fs.chmodSync(flags.privateKey, 0o600);
} else {
Expand Down

0 comments on commit f576b6c

Please sign in to comment.