init: add ubuntu keyserver

This commit is contained in:
b1ek 2024-07-27 23:34:20 +10:00
parent e5c8dc252a
commit 81ff06001c
Signed by: blek
GPG Key ID: 14546221E3595D0C
4 changed files with 30 additions and 17 deletions

View File

@ -1,11 +1,12 @@
import { Module } from '@nestjs/common'
import { HKPController } from './controllers/hkp.controller.js'
import { OpenPGPKeysProvider } from './providers/openpgp.provider.js'
import { AllKeysProvider } from './providers/all.provider.js'
import { Module } from '@nestjs/common';
import { HKPController } from './controllers/hkp.controller.js';
import { OpenPGPKeysProvider } from './providers/openpgp.provider.js';
import { AllKeysProvider } from './providers/all.provider.js';
import { UbuntuKeysProvider } from './providers/ubuntu.provider.js';
@Module({
providers: [OpenPGPKeysProvider, AllKeysProvider],
providers: [OpenPGPKeysProvider, UbuntuKeysProvider, AllKeysProvider],
controllers: [HKPController],
exports: [OpenPGPKeysProvider, AllKeysProvider],
exports: [OpenPGPKeysProvider, UbuntuKeysProvider, AllKeysProvider],
})
export class KeysModule {}

View File

@ -5,6 +5,7 @@ import {
} from './abstract.provider.js'
import { Indexes, InfoLine } from '../indexes.js'
import { OpenPGPKeysProvider } from './openpgp.provider.js'
import { UbuntuKeysProvider } from './ubuntu.provider.js';
/**
* This provider searches all key providers and returns their combined result
@ -14,10 +15,10 @@ export class AllKeysProvider implements AbstractKeysProvider {
readonly url = Object.freeze('http://none');
constructor(private openPgpKeysProvider: OpenPGPKeysProvider) {}
constructor(private openPgpKeysProvider: OpenPGPKeysProvider, private ubuntuKeysProvider: UbuntuKeysProvider) {}
getAll(): AbstractKeysProvider[] {
return [this.openPgpKeysProvider]
return [this.openPgpKeysProvider, this.ubuntuKeysProvider]
}
@Get()

View File

@ -1,4 +1,4 @@
import type { ResponsePromise } from 'ky';
import type { KyResponse, ResponsePromise } from 'ky';
import ky from 'ky'
import type {
AdditionalData,
@ -30,11 +30,12 @@ export function proxyRequest(
headers: {
'User-Agent': 'Cupid (https://cupid.blek.codes)',
},
timeout: 15000,
searchParams: {
op,
search,
},
})
});
}
export async function proxyGetOp(
@ -42,12 +43,17 @@ export async function proxyGetOp(
search: string,
data: AdditionalData
): Promise<GetOperationReturn> {
const httpRes = await proxyRequest(url, 'get', search, data)
let httpRes: KyResponse;
try {
httpRes = await proxyRequest(url, 'index', search, data);
if (httpRes.status !== 200) {
return 404;
}
} catch {
return 404
}
return getKey(await httpRes.text())
return getKey(await httpRes.text());
}
export async function proxyIndexOp(
@ -55,10 +61,15 @@ export async function proxyIndexOp(
search: string,
data: AdditionalData
): Promise<Indexes> {
const httpRes = await proxyRequest(url, 'index', search, data)
let httpRes: KyResponse;
try {
httpRes = await proxyRequest(url, 'index', search, data);
if (httpRes.status !== 200) {
return []
}
} catch {
return []
}
const rawIndexes = await httpRes.text()
return parseIndexes(rawIndexes.split('\n'))