init: add ubuntu keyserver
This commit is contained in:
parent
e5c8dc252a
commit
81ff06001c
|
@ -1,11 +1,12 @@
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common';
|
||||||
import { HKPController } from './controllers/hkp.controller.js'
|
import { HKPController } from './controllers/hkp.controller.js';
|
||||||
import { OpenPGPKeysProvider } from './providers/openpgp.provider.js'
|
import { OpenPGPKeysProvider } from './providers/openpgp.provider.js';
|
||||||
import { AllKeysProvider } from './providers/all.provider.js'
|
import { AllKeysProvider } from './providers/all.provider.js';
|
||||||
|
import { UbuntuKeysProvider } from './providers/ubuntu.provider.js';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [OpenPGPKeysProvider, AllKeysProvider],
|
providers: [OpenPGPKeysProvider, UbuntuKeysProvider, AllKeysProvider],
|
||||||
controllers: [HKPController],
|
controllers: [HKPController],
|
||||||
exports: [OpenPGPKeysProvider, AllKeysProvider],
|
exports: [OpenPGPKeysProvider, UbuntuKeysProvider, AllKeysProvider],
|
||||||
})
|
})
|
||||||
export class KeysModule {}
|
export class KeysModule {}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
} from './abstract.provider.js'
|
} from './abstract.provider.js'
|
||||||
import { Indexes, InfoLine } from '../indexes.js'
|
import { Indexes, InfoLine } from '../indexes.js'
|
||||||
import { OpenPGPKeysProvider } from './openpgp.provider.js'
|
import { OpenPGPKeysProvider } from './openpgp.provider.js'
|
||||||
|
import { UbuntuKeysProvider } from './ubuntu.provider.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This provider searches all key providers and returns their combined result
|
* 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');
|
readonly url = Object.freeze('http://none');
|
||||||
|
|
||||||
constructor(private openPgpKeysProvider: OpenPGPKeysProvider) {}
|
constructor(private openPgpKeysProvider: OpenPGPKeysProvider, private ubuntuKeysProvider: UbuntuKeysProvider) {}
|
||||||
|
|
||||||
getAll(): AbstractKeysProvider[] {
|
getAll(): AbstractKeysProvider[] {
|
||||||
return [this.openPgpKeysProvider]
|
return [this.openPgpKeysProvider, this.ubuntuKeysProvider]
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { ResponsePromise } from 'ky';
|
import type { KyResponse, ResponsePromise } from 'ky';
|
||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
import type {
|
import type {
|
||||||
AdditionalData,
|
AdditionalData,
|
||||||
|
@ -30,11 +30,12 @@ export function proxyRequest(
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Cupid (https://cupid.blek.codes)',
|
'User-Agent': 'Cupid (https://cupid.blek.codes)',
|
||||||
},
|
},
|
||||||
|
timeout: 15000,
|
||||||
searchParams: {
|
searchParams: {
|
||||||
op,
|
op,
|
||||||
search,
|
search,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function proxyGetOp(
|
export async function proxyGetOp(
|
||||||
|
@ -42,12 +43,17 @@ export async function proxyGetOp(
|
||||||
search: string,
|
search: string,
|
||||||
data: AdditionalData
|
data: AdditionalData
|
||||||
): Promise<GetOperationReturn> {
|
): 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) {
|
if (httpRes.status !== 200) {
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
return 404
|
return 404
|
||||||
}
|
}
|
||||||
|
|
||||||
return getKey(await httpRes.text())
|
return getKey(await httpRes.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function proxyIndexOp(
|
export async function proxyIndexOp(
|
||||||
|
@ -55,10 +61,15 @@ export async function proxyIndexOp(
|
||||||
search: string,
|
search: string,
|
||||||
data: AdditionalData
|
data: AdditionalData
|
||||||
): Promise<Indexes> {
|
): 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) {
|
if (httpRes.status !== 200) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
const rawIndexes = await httpRes.text()
|
const rawIndexes = await httpRes.text()
|
||||||
return parseIndexes(rawIndexes.split('\n'))
|
return parseIndexes(rawIndexes.split('\n'))
|
||||||
|
|
Loading…
Reference in New Issue