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