Skip to content

Commit

Permalink
fix: improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
hersentino committed Jan 15, 2024
1 parent 63f2ced commit 75d0010
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1777,11 +1777,11 @@ It uses `QuickLRU` with a `maxSize` of `1000`.

Enable got [http2](https://github.com/sindresorhus/got/blob/v11.5.2/readme.md#http2) support.

### headers
### header

You can provide `headers` object that includes fields to be forwarded to the HTTP request headers. By default, all headers starting with "X-" are allowed, a bot administrator may configure an override for [allowedHeaders](self-hosted-configuration.md#allowedHeaders) to configure more permitted headers.
You can provide `header` object that includes fields to be forwarded to the HTTP request header. By default, all header starting with "X-" are allowed, a bot administrator may configure an override for [allowedHeader](self-hosted-configuration.md#allowedHeader) to configure more permitted header.

Any `headers` value configured in bot admin `hostRules` (e.g. `config.js`) won't be validated so can contain any desired header regardless of `allowedHeaders`.
Any `header` value configured in bot admin `hostRules` (e.g. `config.js`) won't be validated so can contain any desired header regardless of `allowedHeader`.

Example:

Expand All @@ -1790,7 +1790,7 @@ Example:
"hostRules": [
{
"matchHost": "https://domain.com/all-versions",
"headers": {
"header": {
"X-custom-header": "secret"
}
}
Expand Down
14 changes: 7 additions & 7 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ But before you disable templating completely, try the `allowedPostUpgradeCommand

## allowScripts

## allowedHeaders
## allowedHeader

This is option particularly useful when a registry employs a specific authentication system not already covered by Renovate's standard credential handling in `hostRules`.
By default, all headers starting with "X-" are allowed, but you can permit additional headers using this option.
If declared, it will override the default "X-" allowed headers, so you should include them in your config if you wish for them to remain allowed.
`allowedHeaders` is an array of minimatch-compatible globs or re2-compatible regex strings.
By default, all header starting with "X-" are allowed, but you can permit additional header using this option.
If declared, it will override the default "X-" allowed header, so you should include them in your config if you wish for them to remain allowed.
`allowedHeader` is an array of minimatch-compatible globs or re2-compatible regex strings.

Examples:

Expand All @@ -78,19 +78,19 @@ Examples:
"hostRules": [
{
"matchHost": "https://domain.com/all-versions",
"headers": {
"header": {
"X-Auth-Token": "secret"
}
}
]
}
```

or with custom `allowedHeaders`:
or with custom `allowedHeader`:

```js title="config.js"
module.exports = {
allowedHeaders: ['custom-header'],
allowedHeader: ['custom-header'],
};
```

Expand Down
2 changes: 1 addition & 1 deletion lib/config/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class GlobalConfig {
// TODO: once global config work is complete, add a test to make sure this list includes all options with globalOnly=true (#9603)
private static readonly OPTIONS: (keyof RepoGlobalConfig)[] = [
'allowCustomCrateRegistries',
'allowedHeaders',
'allowedHeader',
'allowedPostUpgradeCommands',
'allowPlugins',
'allowPostUpgradeCommandTemplating',
Expand Down
6 changes: 3 additions & 3 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RenovateOptions } from '../types';

const options: RenovateOptions[] = [
{
name: 'allowedHeaders',
name: 'allowedHeader',
description:
'List of allowed patterns for header names in repo hostRules config.',
type: 'array',
Expand Down Expand Up @@ -2376,9 +2376,9 @@ const options: RenovateOptions[] = [
advancedUse: true,
},
{
name: 'headers',
name: 'header',
description:
'An object that includes fields to be forwarded to the HTTP request headers.',
'An object that includes fields to be forwarded to the HTTP request header.',
type: 'object',
parent: 'hostRules',
cli: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface RepoGlobalConfig {
allowPlugins?: boolean;
allowPostUpgradeCommandTemplating?: boolean;
allowScripts?: boolean;
allowedHeaders?: string[];
allowedHeader?: string[];
allowedPostUpgradeCommands?: string[];
binarySource?: 'docker' | 'global' | 'install' | 'hermit';
cacheHardTtlMinutes?: number;
Expand Down
14 changes: 7 additions & 7 deletions lib/config/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,14 +898,14 @@ describe('config/validation', () => {
]);
});

it('errors if unallowed headers in hostRules', async () => {
GlobalConfig.set({ allowedHeaders: ['X-*'] });
it('errors if unallowed header in hostRules', async () => {
GlobalConfig.set({ allowedHeader: ['X-*'] });

const config = {
hostRules: [
{
matchHost: 'https://domain.com/all-versions',
headers: {
header: {
'X-Auth-Token': 'token',
unallowedHeader: 'token',
},
Expand All @@ -918,20 +918,20 @@ describe('config/validation', () => {
expect(errors).toMatchObject([
{
message:
"hostRules header `unallowedHeader` is not permitted by this bot's `allowedHeaders`.",
"hostRules header `unallowedHeader` is not permitted by this bot's `allowedHeader`.",
topic: 'Configuration Error',
},
]);
});

it('errors if headers values are not string', async () => {
GlobalConfig.set({ allowedHeaders: ['X-*'] });
it('errors if header values are not string', async () => {
GlobalConfig.set({ allowedHeader: ['X-*'] });

const config = {
hostRules: [
{
matchHost: 'https://domain.com/all-versions',
headers: {
header: {
'X-Auth-Token': 10,
} as unknown as Record<string, string>,
},
Expand Down
12 changes: 6 additions & 6 deletions lib/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const topLevelObjects = managerList;

const ignoredNodes = [
'$schema',
'headers',
'header',
'depType',
'npmToken',
'packageFile',
Expand Down Expand Up @@ -648,22 +648,22 @@ export async function validateConfig(
}

if (key === 'hostRules' && is.array(val)) {
const allowedHeaders = GlobalConfig.get('allowedHeaders');
const allowedHeader = GlobalConfig.get('allowedHeader');
for (const rule of val as HostRule[]) {
if (!rule.headers) {
if (!rule.header) {
continue;
}
for (const [header, value] of Object.entries(rule.headers)) {
for (const [header, value] of Object.entries(rule.header)) {
if (!is.string(value)) {
errors.push({
topic: 'Configuration Error',
message: `Invalid hostRules header value configuration: should be a string.`,
});
}
if (!anyMatchRegexOrMinimatch(allowedHeaders, header)) {
if (!anyMatchRegexOrMinimatch(allowedHeader, header)) {
errors.push({
topic: 'Configuration Error',
message: `hostRules header \`${header}\` is not permitted by this bot's \`allowedHeaders\`.`,
message: `hostRules header \`${header}\` is not permitted by this bot's \`allowedHeader\`.`,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/types/host-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface HostRuleSearchResult {
enableHttp2?: boolean;
concurrentRequestLimit?: number;
maxRequestsPerSecond?: number;
headers?: Record<string, string>;
header?: Record<string, string>;

dnsCache?: boolean;
keepAlive?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions lib/util/http/host-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,10 @@ describe('util/http/host-rules', () => {
});

it('should remove unallowed header from request', () => {
GlobalConfig.set({ allowedHeaders: ['X-*'] });
GlobalConfig.set({ allowedHeader: ['X-*'] });
const hostRule = {
matchHost: 'https://domain.com/all-versions',
headers: {
header: {
'X-Auth-Token': 'token',
unallowedHeader: 'token',
},
Expand Down
16 changes: 8 additions & 8 deletions lib/util/http/host-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,23 @@ export function applyHostRule<GotOptions extends HostRulesGotOptions>(
options.lookup = dnsLookup;
}

if (hostRule.headers) {
const allowedHeaders = GlobalConfig.get('allowedHeaders');
const filteredHeaders: Record<string, string> = {};
if (hostRule.header) {
const allowedHeader = GlobalConfig.get('allowedHeader');
const filteredHeader: Record<string, string> = {};

for (const [header, value] of Object.entries(hostRule.headers)) {
if (anyMatchRegexOrMinimatch(allowedHeaders, header)) {
filteredHeaders[header] = value;
for (const [header, value] of Object.entries(hostRule.header)) {
if (anyMatchRegexOrMinimatch(allowedHeader, header)) {
filteredHeader[header] = value;
} else {
logger.once.error(
{ allowedHeaders, header },
{ allowedHeader, header },
'Disallowed hostRules header',
);
}
}

options.headers = {
...filteredHeaders,
...filteredHeader,
...options.headers,
};
}
Expand Down

0 comments on commit 75d0010

Please sign in to comment.