-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support file storage for provisioned tokens in OSes != darwin (#…
…202)
- Loading branch information
1 parent
8726eed
commit a4be425
Showing
4 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { getConfigPaths } from "../info.ts"; | ||
|
||
export async function get(): Promise<string | null> { | ||
const { credentialsPath } = getConfigPaths(); | ||
try { | ||
const info = await Deno.lstat(credentialsPath); | ||
if (!info.isFile || (info.mode !== null && (info.mode & 0o777) !== 0o600)) { | ||
throw new Error( | ||
"The credentials file has been tampered with and will be ignored. Please delete it.", | ||
); | ||
} | ||
} catch (e) { | ||
if (e instanceof Deno.errors.NotFound) { | ||
return null; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
try { | ||
const token = JSON.parse(await Deno.readTextFile(credentialsPath)).token; | ||
return token || null; | ||
} catch (_) { | ||
throw new Error( | ||
`The credentials file has been tampered with and will be ignored. Please delete it.`, | ||
); | ||
} | ||
} | ||
|
||
export async function store(token: string): Promise<void> { | ||
const { credentialsPath, configDir } = getConfigPaths(); | ||
await Deno.mkdir(configDir, { recursive: true }); | ||
await Deno.writeTextFile( | ||
credentialsPath, | ||
JSON.stringify({ token }, null, 2), | ||
{ mode: 0o600 }, | ||
); | ||
return Promise.resolve(); | ||
} | ||
|
||
export async function remove(): Promise<void> { | ||
const { credentialsPath, configDir } = getConfigPaths(); | ||
await Deno.mkdir(configDir, { recursive: true }); | ||
await Deno.writeTextFile(credentialsPath, "{}", { mode: 0o600 }); | ||
return Promise.resolve(); | ||
} |
a4be425
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An internal server error occurred.