feat(registry): add declarative protocol routing and request-scoped storage hook context across registries
This commit is contained in:
@@ -41,18 +41,7 @@ export class RubyGemsRegistry extends BaseRegistry {
|
||||
this.registryUrl = registryUrl;
|
||||
this.upstreamProvider = upstreamProvider || null;
|
||||
|
||||
// Initialize logger
|
||||
this.logger = new Smartlog({
|
||||
logContext: {
|
||||
company: 'push.rocks',
|
||||
companyunit: 'smartregistry',
|
||||
containerName: 'rubygems-registry',
|
||||
environment: (process.env.NODE_ENV as any) || 'development',
|
||||
runtime: 'node',
|
||||
zone: 'rubygems'
|
||||
}
|
||||
});
|
||||
this.logger.enableConsole();
|
||||
this.logger = this.createProtocolLogger('rubygems-registry', 'rubygems');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,13 +103,7 @@ export class RubyGemsRegistry extends BaseRegistry {
|
||||
// Extract token (Authorization header)
|
||||
const token = await this.extractToken(context);
|
||||
|
||||
// Build actor from context and validated token
|
||||
const actor: IRequestActor = {
|
||||
...context.actor,
|
||||
userId: token?.userId,
|
||||
ip: context.headers['x-forwarded-for'] || context.headers['X-Forwarded-For'],
|
||||
userAgent: context.headers['user-agent'] || context.headers['User-Agent'],
|
||||
};
|
||||
const actor: IRequestActor = this.buildRequestActor(context, token);
|
||||
|
||||
this.logger.log('debug', `handleRequest: ${context.method} ${path}`, {
|
||||
method: context.method,
|
||||
@@ -128,52 +111,54 @@ export class RubyGemsRegistry extends BaseRegistry {
|
||||
hasAuth: !!token
|
||||
});
|
||||
|
||||
// Compact Index endpoints
|
||||
if (path === '/versions' && context.method === 'GET') {
|
||||
return this.handleVersionsFile(context);
|
||||
}
|
||||
return this.storage.withContext({ protocol: 'rubygems', actor }, async () => {
|
||||
// Compact Index endpoints
|
||||
if (path === '/versions' && context.method === 'GET') {
|
||||
return this.handleVersionsFile(context);
|
||||
}
|
||||
|
||||
if (path === '/names' && context.method === 'GET') {
|
||||
return this.handleNamesFile();
|
||||
}
|
||||
if (path === '/names' && context.method === 'GET') {
|
||||
return this.handleNamesFile();
|
||||
}
|
||||
|
||||
// Info file: GET /info/{gem}
|
||||
const infoMatch = path.match(/^\/info\/([^\/]+)$/);
|
||||
if (infoMatch && context.method === 'GET') {
|
||||
return this.handleInfoFile(infoMatch[1], actor);
|
||||
}
|
||||
// Info file: GET /info/{gem}
|
||||
const infoMatch = path.match(/^\/info\/([^\/]+)$/);
|
||||
if (infoMatch && context.method === 'GET') {
|
||||
return this.handleInfoFile(infoMatch[1], actor);
|
||||
}
|
||||
|
||||
// Gem download: GET /gems/{gem}-{version}[-{platform}].gem
|
||||
const downloadMatch = path.match(/^\/gems\/(.+\.gem)$/);
|
||||
if (downloadMatch && context.method === 'GET') {
|
||||
return this.handleDownload(downloadMatch[1], actor);
|
||||
}
|
||||
// Gem download: GET /gems/{gem}-{version}[-{platform}].gem
|
||||
const downloadMatch = path.match(/^\/gems\/(.+\.gem)$/);
|
||||
if (downloadMatch && context.method === 'GET') {
|
||||
return this.handleDownload(downloadMatch[1], actor);
|
||||
}
|
||||
|
||||
// Legacy specs endpoints (Marshal format)
|
||||
if (path === '/specs.4.8.gz' && context.method === 'GET') {
|
||||
return this.handleSpecs(false);
|
||||
}
|
||||
// Legacy specs endpoints (Marshal format)
|
||||
if (path === '/specs.4.8.gz' && context.method === 'GET') {
|
||||
return this.handleSpecs(false);
|
||||
}
|
||||
|
||||
if (path === '/latest_specs.4.8.gz' && context.method === 'GET') {
|
||||
return this.handleSpecs(true);
|
||||
}
|
||||
if (path === '/latest_specs.4.8.gz' && context.method === 'GET') {
|
||||
return this.handleSpecs(true);
|
||||
}
|
||||
|
||||
// Quick gemspec endpoint: GET /quick/Marshal.4.8/{gem}-{version}.gemspec.rz
|
||||
const quickMatch = path.match(/^\/quick\/Marshal\.4\.8\/(.+)\.gemspec\.rz$/);
|
||||
if (quickMatch && context.method === 'GET') {
|
||||
return this.handleQuickGemspec(quickMatch[1]);
|
||||
}
|
||||
// Quick gemspec endpoint: GET /quick/Marshal.4.8/{gem}-{version}.gemspec.rz
|
||||
const quickMatch = path.match(/^\/quick\/Marshal\.4\.8\/(.+)\.gemspec\.rz$/);
|
||||
if (quickMatch && context.method === 'GET') {
|
||||
return this.handleQuickGemspec(quickMatch[1]);
|
||||
}
|
||||
|
||||
// API v1 endpoints
|
||||
if (path.startsWith('/api/v1/')) {
|
||||
return this.handleApiRequest(path.substring(7), context, token);
|
||||
}
|
||||
// API v1 endpoints
|
||||
if (path.startsWith('/api/v1/')) {
|
||||
return this.handleApiRequest(path.substring(7), context, token);
|
||||
}
|
||||
|
||||
return {
|
||||
status: 404,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: { error: 'Not Found' },
|
||||
};
|
||||
return {
|
||||
status: 404,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: { error: 'Not Found' },
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +177,7 @@ export class RubyGemsRegistry extends BaseRegistry {
|
||||
* Extract authentication token from request
|
||||
*/
|
||||
private async extractToken(context: IRequestContext): Promise<IAuthToken | null> {
|
||||
const authHeader = context.headers['authorization'] || context.headers['Authorization'];
|
||||
const authHeader = this.getAuthorizationHeader(context);
|
||||
if (!authHeader) return null;
|
||||
|
||||
// RubyGems typically uses plain API key in Authorization header
|
||||
|
||||
Reference in New Issue
Block a user