Skip to content

Commit

Permalink
fix(rubygems): Restrict metadata cache to rubygems.org host (#23307)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jul 11, 2023
1 parent da08608 commit 0bc7e61
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/modules/datasource/rubygems/metadata-cache.ts
Expand Up @@ -2,7 +2,7 @@ import hasha from 'hasha';
import { logger } from '../../../logger';
import * as packageCache from '../../../util/cache/package';
import type { Http } from '../../../util/http';
import { joinUrlParts } from '../../../util/url';
import { joinUrlParts, parseUrl } from '../../../util/url';
import type { ReleaseResult } from '../types';
import { GemMetadata, GemVersions } from './schema';

Expand Down Expand Up @@ -52,15 +52,19 @@ export class MetadataCache {
data.homepage = metadata.homepage;
}

const newCache: CacheRecord = { hash, data };
const ttlMinutes = 100 * 24 * 60;
const ttlRandomDelta = Math.floor(Math.random() * 10 * 24 * 60);
await packageCache.set(
cacheNs,
cacheKey,
newCache,
ttlMinutes + ttlRandomDelta
);
const registryHostname = parseUrl(registryUrl)?.hostname;
if (registryHostname === 'rubygems.org') {
const newCache: CacheRecord = { hash, data };
const ttlMinutes = 100 * 24 * 60;
const ttlRandomDelta = Math.floor(Math.random() * 10 * 24 * 60);
await packageCache.set(
cacheNs,
cacheKey,
newCache,
ttlMinutes + ttlRandomDelta
);
}

return data;
} catch (err) {
logger.debug({ err }, 'Rubygems: failed to fetch metadata');
Expand Down

0 comments on commit 0bc7e61

Please sign in to comment.