feat(registry): add declarative protocol routing and request-scoped storage hook context across registries
This commit is contained in:
@@ -43,18 +43,7 @@ export class CargoRegistry extends BaseRegistry {
|
||||
this.registryUrl = registryUrl;
|
||||
this.upstreamProvider = upstreamProvider || null;
|
||||
|
||||
// Initialize logger
|
||||
this.logger = new Smartlog({
|
||||
logContext: {
|
||||
company: 'push.rocks',
|
||||
companyunit: 'smartregistry',
|
||||
containerName: 'cargo-registry',
|
||||
environment: (process.env.NODE_ENV as any) || 'development',
|
||||
runtime: 'node',
|
||||
zone: 'cargo'
|
||||
}
|
||||
});
|
||||
this.logger.enableConsole();
|
||||
this.logger = this.createProtocolLogger('cargo-registry', 'cargo');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,16 +99,10 @@ export class CargoRegistry extends BaseRegistry {
|
||||
const path = context.path.replace(this.basePath, '');
|
||||
|
||||
// Extract token (Cargo uses Authorization header WITHOUT "Bearer" prefix)
|
||||
const authHeader = context.headers['authorization'] || context.headers['Authorization'];
|
||||
const authHeader = this.getAuthorizationHeader(context);
|
||||
const token = authHeader ? await this.authManager.validateToken(authHeader, 'cargo') : null;
|
||||
|
||||
// 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,
|
||||
@@ -127,18 +110,20 @@ export class CargoRegistry extends BaseRegistry {
|
||||
hasAuth: !!token
|
||||
});
|
||||
|
||||
// Config endpoint (required for sparse protocol)
|
||||
if (path === '/config.json') {
|
||||
return this.handleConfigJson();
|
||||
}
|
||||
return this.storage.withContext({ protocol: 'cargo', actor }, async () => {
|
||||
// Config endpoint (required for sparse protocol)
|
||||
if (path === '/config.json') {
|
||||
return this.handleConfigJson();
|
||||
}
|
||||
|
||||
// API endpoints
|
||||
if (path.startsWith('/api/v1/')) {
|
||||
return this.handleApiRequest(path, context, token, actor);
|
||||
}
|
||||
// API endpoints
|
||||
if (path.startsWith('/api/v1/')) {
|
||||
return this.handleApiRequest(path, context, token, actor);
|
||||
}
|
||||
|
||||
// Index files (sparse protocol)
|
||||
return this.handleIndexRequest(path, actor);
|
||||
// Index files (sparse protocol)
|
||||
return this.handleIndexRequest(path, actor);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user