Skip to content
Snippets Groups Projects
Unverified Commit ecc60897 authored by RahulGautamSingh's avatar RahulGautamSingh Committed by GitHub
Browse files

feat(datasource/nuget): support password only registry auth (#20749)

parent 9ec48045
No related branches found
Tags 34.157.0
No related merge requests found
......@@ -6,6 +6,7 @@ import type { RepoGlobalConfig } from '../../../config/types';
import * as docker from '../../../util/exec/docker';
import * as _hostRules from '../../../util/host-rules';
import type { UpdateArtifactsConfig } from '../types';
import type { Registry } from './types';
import * as util from './util';
import * as nuget from '.';
......@@ -420,16 +421,23 @@ describe('modules/manager/nuget/artifacts', () => {
name: 'myRegistry',
url: 'https://my-registry.example.org',
},
] as never);
hostRules.find.mockImplementationOnce((search) => {
if (
search.hostType === 'nuget' &&
search.url === 'https://my-registry.example.org'
) {
return {
username: 'some-username',
password: 'some-password',
};
{
name: 'myRegistry2',
url: 'https://my-registry2.example.org',
},
] satisfies Registry[]);
hostRules.find.mockImplementation((search) => {
if (search.hostType === 'nuget') {
if (search.url === 'https://my-registry.example.org') {
return {
username: 'some-username',
password: 'some-password',
};
} else {
return {
password: 'some-password',
};
}
}
return {};
});
......@@ -455,6 +463,11 @@ describe('modules/manager/nuget/artifacts', () => {
'dotnet nuget add source https://my-registry.example.org/ --configfile /tmp/renovate/cache/__renovate-private-cache/nuget/nuget.config ' +
'--name myRegistry --username some-username --password some-password --store-password-in-clear-text',
},
{
cmd:
'dotnet nuget add source https://my-registry2.example.org/ --configfile /tmp/renovate/cache/__renovate-private-cache/nuget/nuget.config ' +
'--name myRegistry2 --password some-password --store-password-in-clear-text',
},
{
cmd: 'dotnet restore project.csproj --force-evaluate --configfile /tmp/renovate/cache/__renovate-private-cache/nuget/nuget.config',
},
......
......@@ -38,7 +38,7 @@ async function addSourceCmds(
(await getConfiguredRegistries(packageFileName)) ?? getDefaultRegistries();
const result: string[] = [];
for (const registry of registries) {
const { username, password } = hostRules.find({
const { password, username } = hostRules.find({
hostType: NugetDatasource.id,
url: registry.url,
});
......@@ -50,9 +50,14 @@ async function addSourceCmds(
// Add name for registry, if known.
addSourceCmd += ` --name ${quote(registry.name)}`;
}
if (username && password) {
// Add registry credentials from host rules, if configured.
addSourceCmd += ` --username ${quote(username)} --password ${quote(
// Add registry credentials from host rules, if configured.
if (username) {
// Add username from host rules, if configured.
addSourceCmd += ` --username ${quote(username)}`;
}
if (password) {
// Add password from host rules, if configured.
addSourceCmd += ` --password ${quote(
password
)} --store-password-in-clear-text`;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment