Use host rules

This commit is contained in:
Borja Domínguez Vázquez 2024-12-14 13:32:31 +01:00
parent c3360f82d3
commit 620fa90803
2 changed files with 21 additions and 4 deletions

View file

@ -2,6 +2,7 @@ import { getPkgReleases } from '..';
import { Fixtures } from '../../../../test/fixtures'; import { Fixtures } from '../../../../test/fixtures';
import * as httpMock from '../../../../test/http-mock'; import * as httpMock from '../../../../test/http-mock';
import { GlobalConfig } from '../../../config/global'; import { GlobalConfig } from '../../../config/global';
import * as hostRules from '../../../util/host-rules';
import type { AzurePipelinesTask } from './types'; import type { AzurePipelinesTask } from './types';
import { AzurePipelinesTasksDatasource } from '.'; import { AzurePipelinesTasksDatasource } from '.';
@ -14,6 +15,7 @@ const marketplaceTasksPath =
describe('modules/datasource/azure-pipelines-tasks/index', () => { describe('modules/datasource/azure-pipelines-tasks/index', () => {
beforeEach(() => { beforeEach(() => {
GlobalConfig.reset(); GlobalConfig.reset();
hostRules.clear();
}); });
it('returns null for unknown task', async () => { it('returns null for unknown task', async () => {
@ -78,6 +80,12 @@ describe('modules/datasource/azure-pipelines-tasks/index', () => {
endpoint: 'https://my.custom.domain', endpoint: 'https://my.custom.domain',
}); });
hostRules.add({
hostType: AzurePipelinesTasksDatasource.id,
matchHost: 'my.custom.domain',
token: '123test',
});
httpMock httpMock
.scope('https://my.custom.domain') .scope('https://my.custom.domain')
.get('/_apis/distributedtask/tasks/') .get('/_apis/distributedtask/tasks/')
@ -97,6 +105,12 @@ describe('modules/datasource/azure-pipelines-tasks/index', () => {
endpoint: 'https://my.custom.domain', endpoint: 'https://my.custom.domain',
}); });
hostRules.add({
hostType: AzurePipelinesTasksDatasource.id,
matchHost: 'my.custom.domain',
token: '123test',
});
httpMock httpMock
.scope('https://my.custom.domain') .scope('https://my.custom.domain')
.get('/_apis/distributedtask/tasks/') .get('/_apis/distributedtask/tasks/')

View file

@ -1,5 +1,6 @@
import { GlobalConfig } from '../../../config/global'; import { GlobalConfig } from '../../../config/global';
import { cache } from '../../../util/cache/package/decorator'; import { cache } from '../../../util/cache/package/decorator';
import * as hostRules from '../../../util/host-rules';
import type { HttpOptions } from '../../../util/http/types'; import type { HttpOptions } from '../../../util/http/types';
import { id as versioning } from '../../versioning/loose'; import { id as versioning } from '../../versioning/loose';
import { Datasource } from '../datasource'; import { Datasource } from '../datasource';
@ -27,11 +28,13 @@ export class AzurePipelinesTasksDatasource extends Datasource {
}: GetReleasesConfig): Promise<ReleaseResult | null> { }: GetReleasesConfig): Promise<ReleaseResult | null> {
const platform = GlobalConfig.get('platform'); const platform = GlobalConfig.get('platform');
const endpoint = GlobalConfig.get('endpoint'); const endpoint = GlobalConfig.get('endpoint');
const { token } = hostRules.find({
hostType: AzurePipelinesTasksDatasource.id,
url: endpoint,
});
if (platform === 'azure' && endpoint) { if (platform === 'azure' && endpoint && token) {
const auth = Buffer.from( const auth = Buffer.from(`renovate:${token}`).toString('base64');
`renovate:${process.env.RENOVATE_TOKEN}`,
).toString('base64');
const opts: HttpOptions = { const opts: HttpOptions = {
headers: { authorization: `Basic ${auth}` }, headers: { authorization: `Basic ${auth}` },
}; };