pub deno commons mod
This commit is contained in:
@@ -98,11 +98,11 @@ Deno.test("base64Url", () => {
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("test-key-ring-rs", () => {
|
||||
setKeyRingPassword("test-service", "test-user", "test-password");
|
||||
Deno.test("test-key-ring-rs", async () => {
|
||||
await setKeyRingPassword("test-service", "test-user", "test-password");
|
||||
assertEquals(
|
||||
"test-password",
|
||||
getKeyRingPassword("test-service", "test-user"),
|
||||
await getKeyRingPassword("test-service", "test-user"),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -791,17 +791,15 @@ export function encodeBase64Url(
|
||||
);
|
||||
}
|
||||
|
||||
export function getKeyRingPassword(
|
||||
export async function getKeyRingPassword(
|
||||
service: string,
|
||||
user: string,
|
||||
): string | null {
|
||||
const command = new Deno.Command("keyring.rs", {
|
||||
args: ["-g", "--json", "-S", service, "-U", user],
|
||||
});
|
||||
const { code, stdout, stderr } = command.outputSync();
|
||||
const stdoutString = new TextDecoder().decode(stdout);
|
||||
const stderrString = new TextDecoder().decode(stderr);
|
||||
if (code != 0) {
|
||||
const keyRingArgs = ["-g", "--json", "-S", service, "-U", user];
|
||||
const processOutput = await execCommand("keyring.rs", keyRingArgs);
|
||||
const stdoutString = processOutput.getStdoutAsStringThenTrim();
|
||||
const stderrString = processOutput.getStderrAsStringThenTrim();
|
||||
if (processOutput.code != 0) {
|
||||
if (stderrString && stderrString.includes("Error: NoEntry")) {
|
||||
return null;
|
||||
}
|
||||
@@ -815,18 +813,16 @@ export function getKeyRingPassword(
|
||||
return result.password;
|
||||
}
|
||||
|
||||
export function setKeyRingPassword(
|
||||
export async function setKeyRingPassword(
|
||||
service: string,
|
||||
user: string,
|
||||
password: string,
|
||||
): void {
|
||||
const command = new Deno.Command("keyring.rs", {
|
||||
args: ["-s", "-S", service, "-U", user, "-P", password],
|
||||
});
|
||||
const { code, stdout, stderr } = command.outputSync();
|
||||
const stdoutString = new TextDecoder().decode(stdout);
|
||||
const stderrString = new TextDecoder().decode(stderr);
|
||||
if (code != 0) {
|
||||
const keyRingArgs = ["-s", "-S", service, "-U", user, "-P", password];
|
||||
const processOutput = await execCommand("keyring.rs", keyRingArgs);
|
||||
const stdoutString = processOutput.getStdoutAsStringThenTrim();
|
||||
const stderrString = processOutput.getStderrAsStringThenTrim();
|
||||
if (processOutput.code != 0) {
|
||||
throw new Error(
|
||||
`keyring.rs -s failed, code: ${code}, stdout: ${stdoutString}, stderr: ${stderrString}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user