feat(registry): add declarative protocol routing and request-scoped storage hook context across registries
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import type { IRegistryConfig } from '../../ts/core/interfaces.core.js';
|
||||
import type { IStorageHooks } from '../../ts/core/interfaces.storage.js';
|
||||
import { StaticUpstreamProvider } from '../../ts/upstream/interfaces.upstream.js';
|
||||
import type { IUpstreamProvider } from '../../ts/upstream/interfaces.upstream.js';
|
||||
|
||||
const testQenv = new qenv.Qenv('./', './.nogit');
|
||||
|
||||
async function getTestStorageConfig(): Promise<IRegistryConfig['storage']> {
|
||||
const s3AccessKey = await testQenv.getEnvVarOnDemand('S3_ACCESSKEY');
|
||||
const s3SecretKey = await testQenv.getEnvVarOnDemand('S3_SECRETKEY');
|
||||
const s3Endpoint = await testQenv.getEnvVarOnDemand('S3_ENDPOINT');
|
||||
const s3Port = await testQenv.getEnvVarOnDemand('S3_PORT');
|
||||
|
||||
return {
|
||||
accessKey: s3AccessKey || 'minioadmin',
|
||||
accessSecret: s3SecretKey || 'minioadmin',
|
||||
endpoint: s3Endpoint || 'localhost',
|
||||
port: parseInt(s3Port || '9000', 10),
|
||||
useSsl: false,
|
||||
region: 'us-east-1',
|
||||
bucketName: 'test-registry',
|
||||
};
|
||||
}
|
||||
|
||||
function getTestAuthConfig(): IRegistryConfig['auth'] {
|
||||
return {
|
||||
jwtSecret: 'test-secret-key',
|
||||
tokenStore: 'memory',
|
||||
npmTokens: {
|
||||
enabled: true,
|
||||
},
|
||||
ociTokens: {
|
||||
enabled: true,
|
||||
realm: 'https://auth.example.com/token',
|
||||
service: 'test-registry',
|
||||
},
|
||||
pypiTokens: {
|
||||
enabled: true,
|
||||
},
|
||||
rubygemsTokens: {
|
||||
enabled: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createDefaultTestUpstreamProvider(): IUpstreamProvider {
|
||||
return new StaticUpstreamProvider({
|
||||
npm: {
|
||||
enabled: true,
|
||||
upstreams: [{
|
||||
id: 'npmjs',
|
||||
name: 'npmjs',
|
||||
url: 'https://registry.npmjs.org',
|
||||
priority: 1,
|
||||
enabled: true,
|
||||
auth: { type: 'none' },
|
||||
}],
|
||||
},
|
||||
oci: {
|
||||
enabled: true,
|
||||
upstreams: [{
|
||||
id: 'dockerhub',
|
||||
name: 'dockerhub',
|
||||
url: 'https://registry-1.docker.io',
|
||||
priority: 1,
|
||||
enabled: true,
|
||||
auth: { type: 'none' },
|
||||
}],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function buildTestRegistryConfig(options?: {
|
||||
registryUrl?: string;
|
||||
storageHooks?: IStorageHooks;
|
||||
upstreamProvider?: IUpstreamProvider;
|
||||
}): Promise<IRegistryConfig> {
|
||||
const config: IRegistryConfig = {
|
||||
storage: await getTestStorageConfig(),
|
||||
auth: getTestAuthConfig(),
|
||||
...(options?.storageHooks ? { storageHooks: options.storageHooks } : {}),
|
||||
...(options?.upstreamProvider ? { upstreamProvider: options.upstreamProvider } : {}),
|
||||
oci: {
|
||||
enabled: true,
|
||||
basePath: '/oci',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/oci` } : {}),
|
||||
},
|
||||
npm: {
|
||||
enabled: true,
|
||||
basePath: '/npm',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/npm` } : {}),
|
||||
},
|
||||
maven: {
|
||||
enabled: true,
|
||||
basePath: '/maven',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/maven` } : {}),
|
||||
},
|
||||
composer: {
|
||||
enabled: true,
|
||||
basePath: '/composer',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/composer` } : {}),
|
||||
},
|
||||
cargo: {
|
||||
enabled: true,
|
||||
basePath: '/cargo',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/cargo` } : {}),
|
||||
},
|
||||
pypi: {
|
||||
enabled: true,
|
||||
basePath: '/pypi',
|
||||
...(options?.registryUrl ? { registryUrl: options.registryUrl } : {}),
|
||||
},
|
||||
rubygems: {
|
||||
enabled: true,
|
||||
basePath: '/rubygems',
|
||||
...(options?.registryUrl ? { registryUrl: `${options.registryUrl}/rubygems` } : {}),
|
||||
},
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user