From 17f88bded3078bb30f305c028270c5ea6d2544df Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Mon, 29 Apr 2024 20:36:09 +0545 Subject: [PATCH 1/4] feat(self-hosted): userAgent --- docs/usage/self-hosted-configuration.md | 4 ++++ docs/usage/self-hosted-experimental.md | 4 ---- lib/config/options/index.ts | 8 ++++++++ lib/config/types.ts | 1 + lib/util/http/index.ts | 3 ++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 2c1af6afecbad4..2c2737ca1403c2 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -1105,6 +1105,10 @@ Secret names must start with an upper or lower case character and can have only If enabled emoji shortcodes are replaced with their Unicode equivalents. For example: `:warning:` will be replaced with `⚠️`. +## userAgent + +If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. + ## useCloudMetadataServices Some cloud providers offer services to receive metadata about the current instance, for example [AWS Instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html) or [GCP VM metadata](https://cloud.google.com/compute/docs/metadata/overview). diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md index fcf3c95a94e57e..1dc8fd40f5f6a0 100644 --- a/docs/usage/self-hosted-experimental.md +++ b/docs/usage/self-hosted-experimental.md @@ -32,10 +32,6 @@ Skipping the check will speed things up, but may result in versions being return If set to any value, Renovate will always paginate requests to GitHub fully, instead of stopping after 10 pages. -## `RENOVATE_USER_AGENT` - -If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. - ## `RENOVATE_X_AUTODISCOVER_REPO_ORDER` diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 995e05b93cbb90..76ae38a7e33266 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -47,6 +47,14 @@ const options: RenovateOptions[] = [ default: true, globalOnly: true, }, + { + name: 'userAgent', + description: + 'If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests.', + type: 'string', + default: null, + globalOnly: true, + }, { name: 'allowPostUpgradeCommandTemplating', description: diff --git a/lib/config/types.ts b/lib/config/types.ts index 2e55575c98927a..ff309df752a66d 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -159,6 +159,7 @@ export interface RepoGlobalConfig { privateKey?: string; privateKeyOld?: string; httpCacheTtlDays?: number; + userAgent?: string; } export interface LegacyAdminConfig { diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index b93c659497e729..7c505db6ef4bf3 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -3,6 +3,7 @@ import merge from 'deepmerge'; import got, { Options, RequestError } from 'got'; import type { SetRequired } from 'type-fest'; import { infer as Infer, type ZodError, ZodType } from 'zod'; +import { GlobalConfig } from '../../config/global'; import { HOST_DISABLED } from '../../constants/error-messages'; import { pkg } from '../../expose.cjs'; import { logger } from '../../logger'; @@ -50,7 +51,7 @@ function applyDefaultHeaders(options: Options): void { options.headers = { ...options.headers, 'user-agent': - process.env.RENOVATE_USER_AGENT ?? + GlobalConfig.get('userAgent') ?? `RenovateBot/${renovateVersion} (https://github.com/renovatebot/renovate)`, }; } From 514f7cdc324215a1d36acae5b92c07816c491b0b Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Mon, 29 Apr 2024 20:58:51 +0545 Subject: [PATCH 2/4] add missing type --- lib/config/global.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/config/global.ts b/lib/config/global.ts index 21b2b56cc25f8d..c713f8635fd0ba 100644 --- a/lib/config/global.ts +++ b/lib/config/global.ts @@ -33,6 +33,7 @@ export class GlobalConfig { 'platform', 'endpoint', 'httpCacheTtlDays', + 'userAgent', ]; private static config: RepoGlobalConfig = {}; From 2fec18dcf1160e5922db9750badd31cb95275ca5 Mon Sep 17 00:00:00 2001 From: Rahul Gautam Singh Date: Mon, 29 Apr 2024 21:08:29 +0545 Subject: [PATCH 3/4] docs: fix order --- docs/usage/self-hosted-configuration.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 2c2737ca1403c2..936294856c56a8 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -1105,15 +1105,15 @@ Secret names must start with an upper or lower case character and can have only If enabled emoji shortcodes are replaced with their Unicode equivalents. For example: `:warning:` will be replaced with `⚠️`. -## userAgent - -If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. - ## useCloudMetadataServices Some cloud providers offer services to receive metadata about the current instance, for example [AWS Instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html) or [GCP VM metadata](https://cloud.google.com/compute/docs/metadata/overview). You can control if Renovate should try to access these services with the `useCloudMetadataServices` config option. +## userAgent + +If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. + ## username You may need to set a `username` if you: From 8e3fe8c6450914e3e683f812ee458311fa15dae5 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Mon, 29 Apr 2024 21:16:59 +0545 Subject: [PATCH 4/4] Update docs/usage/self-hosted-configuration.md Co-authored-by: Rhys Arkins --- docs/usage/self-hosted-configuration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 936294856c56a8..80fed5ff440ddf 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -1113,6 +1113,7 @@ You can control if Renovate should try to access these services with the `useClo ## userAgent If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. +Otherwise, it will default to `RenovateBot/${renovateVersion} (https://github.com/renovatebot/renovate)`. ## username