Skip to content

Commit

Permalink
feat(config): relax registy alias validation (#22815)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Jun 16, 2023
1 parent b9dc2f3 commit 2948a64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
13 changes: 7 additions & 6 deletions docs/usage/configuration-options.md
Expand Up @@ -3193,16 +3193,17 @@ You can use the `registryAliases` object to set registry aliases.

This feature works with the following managers:

- [`ansible`](/modules/manager/ansible)
- [`docker-compose`](/modules/manager/docker-compose)
- [`dockerfile`](/modules/manager/dockerfile)
- [`droneci`](/modules/manager/droneci)
- [`gitlabci`](/modules/manager/gitlabci/)
- [`helm-requirements`](/modules/manager/helm-requirements/)
- [`helmv3`](/modules/manager/helmv3/)
- [`helmfile`](/modules/manager/helmfile/)
- [`gitlabci`](/modules/manager/gitlabci/)
- [`dockerfile`](/modules/manager/dockerfile)
- [`docker-compose`](/modules/manager/docker-compose)
- [`helmv3`](/modules/manager/helmv3/)
- [`kubernetes`](/modules/manager/kubernetes)
- [`ansible`](/modules/manager/ansible)
- [`droneci`](/modules/manager/droneci)
- [`terraform`](/modules/manager/terraform)
- [`woodpecker`](/modules/manager/woodpecker)

## registryUrls

Expand Down
8 changes: 4 additions & 4 deletions lib/config/validation.spec.ts
Expand Up @@ -578,16 +578,16 @@ describe('config/validation', () => {
expect(errors).toMatchObject([
{
message:
'Invalid `registryAliases.registryAliases.sample` configuration: value is not a url',
'Invalid `registryAliases.registryAliases.sample` configuration: value is not a string',
topic: 'Configuration Error',
},
]);
});

it('errors if registryAliases have invalid url', async () => {
it('errors if registryAliases have invalid value', async () => {
const config = {
registryAliases: {
example1: 'noturl',
example1: 123 as never,
example2: 'http://www.example.com',
},
};
Expand All @@ -598,7 +598,7 @@ describe('config/validation', () => {
expect(errors).toMatchObject([
{
message:
'Invalid `registryAliases.registryAliases.example1` configuration: value is not a url',
'Invalid `registryAliases.registryAliases.example1` configuration: value is not a string',
topic: 'Configuration Error',
},
]);
Expand Down
13 changes: 2 additions & 11 deletions lib/config/validation.ts
Expand Up @@ -54,15 +54,6 @@ function isIgnored(key: string): boolean {
return ignoredNodes.includes(key);
}

function validateAliasObject(val: Record<string, unknown>): true | string {
for (const [key, value] of Object.entries(val)) {
if (!is.urlString(value)) {
return key;
}
}
return true;
}

function validatePlainObject(val: Record<string, unknown>): true | string {
for (const [key, value] of Object.entries(val)) {
if (!is.string(value)) {
Expand Down Expand Up @@ -570,11 +561,11 @@ export async function validateConfig(
) {
if (is.plainObject(val)) {
if (key === 'registryAliases') {
const res = validateAliasObject(val);
const res = validatePlainObject(val);
if (res !== true) {
errors.push({
topic: 'Configuration Error',
message: `Invalid \`${currentPath}.${key}.${res}\` configuration: value is not a url`,
message: `Invalid \`${currentPath}.${key}.${res}\` configuration: value is not a string`,
});
}
} else if (
Expand Down

0 comments on commit 2948a64

Please sign in to comment.