UNPKG

cloudapp-cli

Version:

39 lines (33 loc) 790 B
const os = require("os"); const fs = require("fs"); const path = require("path"); function getCredential() { try { const { secretId, secretKey } = JSON.parse( fs.readFileSync(getCredentialFilePath(), "utf8") ); return { secretId, secretKey }; } catch (error) { console.error("读取本地登录凭证失败"); process.exit(1); } } function getCredentialFilePath() { return path.join(os.homedir(), ".cloudapp-credential.json"); } function writeCredential(credential) { fs.writeFileSync( getCredentialFilePath(), JSON.stringify(credential, null, 4), "utf8" ); } function cleanCredential() { fs.unlinkSync(getCredentialFilePath()); } module.exports = { getCredential, getCredentialFilePath, writeCredential, cleanCredential, };