feat: add deno-github-mod.ts, update deno-sshsig-mod.ts
This commit is contained in:
38
libraries/deno-github-mod.ts
Normal file
38
libraries/deno-github-mod.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
getFetchAutoProxyInit,
|
||||
} from "https://hatter.ink/script/fetch/library/deno-fetch-auto-proxy-mod.ts?202501191421";
|
||||
|
||||
export class SshKey {
|
||||
algorithm: string;
|
||||
material: string;
|
||||
description?: string;
|
||||
|
||||
constructor(
|
||||
algorithm: string,
|
||||
material: string,
|
||||
description: string | undefined,
|
||||
) {
|
||||
this.algorithm = algorithm;
|
||||
this.material = material;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
static parseSshKey(key: string): SshKey {
|
||||
const keyParts = key.split(/\s+/);
|
||||
if (keyParts.length < 2 || keyParts.length > 3) {
|
||||
throw `Bad SSH key format ${key}`;
|
||||
}
|
||||
return new SshKey(
|
||||
keyParts[0],
|
||||
keyParts[1],
|
||||
(keyParts.length > 2) ? keyParts[2] : undefined,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchKeys(username: string): Promise<Array<SshKey>> {
|
||||
const url = `https://github.com/${username}.keys`;
|
||||
const response = await fetch(url, getFetchAutoProxyInit());
|
||||
const responseText = await response.text();
|
||||
return responseText.trim().split("\n").map((k) => SshKey.parseSshKey(k));
|
||||
}
|
||||
Reference in New Issue
Block a user