fix(datasource/maven): Remove S3 Blob handling (#17401)

This commit is contained in:
Gabriel-Ladzaretti 2022-08-25 11:22:44 +03:00 committed by GitHub
parent 2a6b86c3d6
commit 4f9eedbe45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View file

@ -8,7 +8,7 @@ import { mockClient } from 'aws-sdk-client-mock';
import { DateTime } from 'luxon';
import { ReleaseResult, getPkgReleases } from '..';
import { Fixtures } from '../../../../test/fixtures';
import { logger } from '../../../../test/util';
import { logger } from '../../../logger';
import * as hostRules from '../../../util/host-rules';
import { id as versioning } from '../../versioning/maven';
import { MavenDatasource } from '.';
@ -113,7 +113,7 @@ describe('modules/datasource/maven/s3', () => {
const res = await get('org.example:package', baseUrlS3);
expect(res).toBeNull();
expect(logger.logger.debug).toHaveBeenCalledWith(
expect(logger.debug).toHaveBeenCalledWith(
{
failedUrl: 's3://repobucket/org/example/package/maven-metadata.xml',
},
@ -132,7 +132,7 @@ describe('modules/datasource/maven/s3', () => {
const res = await get('org.example:package', baseUrlS3);
expect(res).toBeNull();
expect(logger.logger.debug).toHaveBeenCalledWith(
expect(logger.debug).toHaveBeenCalledWith(
{
failedUrl: 's3://repobucket/org/example/package/maven-metadata.xml',
},
@ -151,7 +151,7 @@ describe('modules/datasource/maven/s3', () => {
const res = await get('org.example:package', baseUrlS3);
expect(res).toBeNull();
expect(logger.logger.trace).toHaveBeenCalledWith(
expect(logger.trace).toHaveBeenCalledWith(
{
failedUrl: 's3://repobucket/org/example/package/maven-metadata.xml',
},
@ -170,7 +170,7 @@ describe('modules/datasource/maven/s3', () => {
const res = await get('org.example:package', baseUrlS3);
expect(res).toBeNull();
expect(logger.logger.trace).toHaveBeenCalledWith(
expect(logger.trace).toHaveBeenCalledWith(
{
failedUrl: 's3://repobucket/org/example/package/maven-metadata.xml',
},
@ -189,7 +189,7 @@ describe('modules/datasource/maven/s3', () => {
const res = await get('org.example:package', baseUrlS3);
expect(res).toBeNull();
expect(logger.logger.debug).toHaveBeenCalledWith(
expect(logger.debug).toHaveBeenCalledWith(
{
failedUrl: 's3://repobucket/org/example/package/maven-metadata.xml',
message: 'Unknown error',
@ -197,6 +197,19 @@ describe('modules/datasource/maven/s3', () => {
'Unknown S3 download error'
);
});
it('returns null for unexpected response type', async () => {
s3mock
.on(GetObjectCommand, {
Bucket: 'repobucket',
Key: 'org/example/package/maven-metadata.xml',
})
.resolvesOnce({});
expect(await get('org.example:package', baseUrlS3)).toBeNull();
expect(logger.debug).toHaveBeenCalledWith(
"Expecting Readable response type got 'undefined' type instead"
);
});
});
});
});

View file

@ -1,4 +1,3 @@
import { Blob } from 'buffer';
import { Readable } from 'stream';
import { DateTime } from 'luxon';
import { XmlDocument } from 'xmldoc';
@ -114,15 +113,12 @@ export async function downloadS3Protocol(pkgUrl: URL): Promise<string | null> {
return null;
}
const { Body: res } = await getS3Client().getObject(s3Url);
// istanbul ignore if
if (res instanceof Blob) {
return res.toString();
}
if (res instanceof Readable) {
return streamToString(res);
}
logger.debug(
`Expecting Readable response type got '${typeof res}' type instead`
);
} catch (err) {
const failedUrl = pkgUrl.toString();
if (err.name === 'CredentialsProviderError') {