feat(auth): Implement HMAC-SHA256 OCI JWTs; enhance PyPI & RubyGems uploads and normalize responses
This commit is contained in:
@@ -396,3 +396,54 @@ export async function extractGemSpec(gemData: Buffer): Promise<any | null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract basic metadata from a gem file
|
||||
* Gem files are tar.gz archives containing metadata.gz (gzipped YAML with spec)
|
||||
* This function attempts to parse the YAML from the metadata to extract name/version
|
||||
* @param gemData - Gem file data
|
||||
* @returns Extracted metadata or null
|
||||
*/
|
||||
export async function extractGemMetadata(gemData: Buffer): Promise<{
|
||||
name: string;
|
||||
version: string;
|
||||
platform?: string;
|
||||
} | null> {
|
||||
try {
|
||||
// Gem format: outer tar.gz containing metadata.gz and data.tar.gz
|
||||
// metadata.gz contains YAML with gem specification
|
||||
|
||||
// Attempt to find YAML metadata in the gem binary
|
||||
// The metadata is gzipped, but we can look for patterns in the decompressed portion
|
||||
// For test gems created with our helper, the YAML is accessible after gunzip
|
||||
const searchBuffer = gemData.toString('utf-8', 0, Math.min(gemData.length, 20000));
|
||||
|
||||
// Look for name: field in YAML
|
||||
const nameMatch = searchBuffer.match(/name:\s*([^\n\r]+)/);
|
||||
|
||||
// Look for version in Ruby YAML format: version: !ruby/object:Gem::Version\n version: X.X.X
|
||||
const versionMatch = searchBuffer.match(/version:\s*!ruby\/object:Gem::Version[\s\S]*?version:\s*['"]?([^'"\n\r]+)/);
|
||||
|
||||
// Also try simpler version format
|
||||
const simpleVersionMatch = !versionMatch ? searchBuffer.match(/^version:\s*['"]?(\d[^'"\n\r]*)/m) : null;
|
||||
|
||||
// Look for platform
|
||||
const platformMatch = searchBuffer.match(/platform:\s*([^\n\r]+)/);
|
||||
|
||||
const name = nameMatch?.[1]?.trim();
|
||||
const version = versionMatch?.[1]?.trim() || simpleVersionMatch?.[1]?.trim();
|
||||
const platform = platformMatch?.[1]?.trim();
|
||||
|
||||
if (name && version) {
|
||||
return {
|
||||
name,
|
||||
version,
|
||||
platform: platform && platform !== 'ruby' ? platform : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user