Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(maven): Change signatures for S3 resource checks #31269

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/modules/datasource/maven/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { Http } from '../../../util/http';
import { parseUrl } from '../../../util/url';
import {
checkResource,
checkS3Resource,
downloadHttpProtocol,
downloadMavenXml,
downloadS3Protocol,
Expand Down Expand Up @@ -105,12 +104,4 @@ describe('modules/datasource/maven/util', () => {
expect(res).toBe('error');
});
});

describe('checkS3Resource', () => {
it('returns error for non-S3 URLs', async () => {
// #22198
const res = await checkS3Resource(parseUrl('http://not-s3.com/')!);
expect(res).toBe('error');
});
});
});
40 changes: 22 additions & 18 deletions lib/modules/datasource/maven/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ExternalHostError } from '../../../types/errors/external-host-error';
import type { Http } from '../../../util/http';
import type { HttpOptions, HttpResponse } from '../../../util/http/types';
import { regEx } from '../../../util/regex';
import type { S3UrlParts } from '../../../util/s3';
import { getS3Client, parseS3Url } from '../../../util/s3';
import { streamToString } from '../../../util/streams';
import { parseUrl } from '../../../util/url';
Expand Down Expand Up @@ -197,13 +198,9 @@ async function checkHttpResource(
}

export async function checkS3Resource(
pkgUrl: URL,
s3Url: S3UrlParts,
): Promise<HttpResourceCheckResult> {
try {
const s3Url = parseS3Url(pkgUrl);
if (s3Url === null) {
return 'error';
}
const response = await getS3Client().send(new HeadObjectCommand(s3Url));
if (response.DeleteMarker) {
return 'not-found';
Expand All @@ -217,7 +214,12 @@ export async function checkS3Resource(
return 'not-found';
} else {
logger.debug(
{ pkgUrl, name: err.name, message: err.message },
{
bucket: s3Url.Bucket,
key: s3Url.Key,
name: err.name,
message: err.message,
},
`Can't check S3 resource existence`,
);
}
Expand All @@ -233,19 +235,21 @@ export async function checkResource(
if (parsedUrl === null) {
return 'error';
}
switch (parsedUrl.protocol) {
case 'http:':
case 'https:':
return await checkHttpResource(http, parsedUrl);
case 's3:':
return await checkS3Resource(parsedUrl);
default:
logger.debug(
{ url: pkgUrl.toString() },
`Unsupported Maven protocol in check resource`,
);
return 'not-found';

const s3Url = parseS3Url(parsedUrl);
if (s3Url) {
return await checkS3Resource(s3Url);
}

if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
return await checkHttpResource(http, parsedUrl);
}

logger.debug(
{ url: pkgUrl.toString() },
`Unsupported Maven protocol in check resource`,
);
return 'not-found';
}

function containsPlaceholder(str: string): boolean {
Expand Down