Skip to content
Snippets Groups Projects
Unverified Commit 9f9cf258 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

refactor: move user-agent insertion from got to http (#6492)

parent 2e18987d
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1 ...@@ -20,6 +20,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1
Array [ Array [
"https://index.docker.io/v2/", "https://index.docker.io/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -35,6 +38,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1 ...@@ -35,6 +38,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1
Object { Object {
"headers": Object { "headers": Object {
"authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk", "authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -51,6 +55,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1 ...@@ -51,6 +55,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1
Object { Object {
"headers": Object { "headers": Object {
"authorization": "Bearer some-token ", "authorization": "Bearer some-token ",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -65,6 +70,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1 ...@@ -65,6 +70,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1
Array [ Array [
"https://index.docker.io/v2/", "https://index.docker.io/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -80,6 +88,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1 ...@@ -80,6 +88,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1
Object { Object {
"headers": Object { "headers": Object {
"accept": "application/vnd.docker.distribution.manifest.v2+json", "accept": "application/vnd.docker.distribution.manifest.v2+json",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -143,6 +152,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1 ...@@ -143,6 +152,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1
Array [ Array [
"https://index.docker.io/v2/", "https://index.docker.io/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -158,6 +170,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1 ...@@ -158,6 +170,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1
Object { Object {
"headers": Object { "headers": Object {
"authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk", "authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -174,6 +187,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1 ...@@ -174,6 +187,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1
Object { Object {
"headers": Object { "headers": Object {
"authorization": "Bearer some-token ", "authorization": "Bearer some-token ",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -188,6 +202,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1 ...@@ -188,6 +202,9 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1
Array [ Array [
"https://index.docker.io/v2/", "https://index.docker.io/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -203,6 +220,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1 ...@@ -203,6 +220,7 @@ exports[`api/docker getReleases adds library/ prefix for Docker Hub (implicit) 1
Object { Object {
"headers": Object { "headers": Object {
"accept": "application/vnd.docker.distribution.manifest.v2+json", "accept": "application/vnd.docker.distribution.manifest.v2+json",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -266,6 +284,9 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`] ...@@ -266,6 +284,9 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`]
Array [ Array [
"https://k8s.gcr.io/v2/", "https://k8s.gcr.io/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -281,6 +302,7 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`] ...@@ -281,6 +302,7 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`]
Object { Object {
"headers": Object { "headers": Object {
"authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk", "authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -297,6 +319,7 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`] ...@@ -297,6 +319,7 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`]
Object { Object {
"headers": Object { "headers": Object {
"authorization": "Bearer some-token ", "authorization": "Bearer some-token ",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -311,6 +334,9 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`] ...@@ -311,6 +334,9 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`]
Array [ Array [
"https://k8s.gcr.io/v2/", "https://k8s.gcr.io/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -326,6 +352,7 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`] ...@@ -326,6 +352,7 @@ exports[`api/docker getReleases adds no library/ prefix for other registries 1`]
Object { Object {
"headers": Object { "headers": Object {
"accept": "application/vnd.docker.distribution.manifest.v2+json", "accept": "application/vnd.docker.distribution.manifest.v2+json",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -389,6 +416,9 @@ exports[`api/docker getReleases uses custom registry in depName 1`] = ` ...@@ -389,6 +416,9 @@ exports[`api/docker getReleases uses custom registry in depName 1`] = `
Array [ Array [
"https://registry.company.com/v2/", "https://registry.company.com/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -402,7 +432,9 @@ exports[`api/docker getReleases uses custom registry in depName 1`] = ` ...@@ -402,7 +432,9 @@ exports[`api/docker getReleases uses custom registry in depName 1`] = `
Array [ Array [
"https://registry.company.com/v2/node/tags/list?n=10000", "https://registry.company.com/v2/node/tags/list?n=10000",
Object { Object {
"headers": Object {}, "headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -416,6 +448,9 @@ exports[`api/docker getReleases uses custom registry in depName 1`] = ` ...@@ -416,6 +448,9 @@ exports[`api/docker getReleases uses custom registry in depName 1`] = `
Array [ Array [
"https://registry.company.com/v2/", "https://registry.company.com/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -458,6 +493,9 @@ Array [ ...@@ -458,6 +493,9 @@ Array [
Array [ Array [
"https://registry.company.com/v2/", "https://registry.company.com/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -471,7 +509,9 @@ Array [ ...@@ -471,7 +509,9 @@ Array [
Array [ Array [
"https://registry.company.com/v2/node/tags/list?n=10000", "https://registry.company.com/v2/node/tags/list?n=10000",
Object { Object {
"headers": Object {}, "headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -485,7 +525,9 @@ Array [ ...@@ -485,7 +525,9 @@ Array [
Array [ Array [
"https://api.github.com/user/9287/repos?page=3&per_page=100", "https://api.github.com/user/9287/repos?page=3&per_page=100",
Object { Object {
"headers": Object {}, "headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -499,6 +541,9 @@ Array [ ...@@ -499,6 +541,9 @@ Array [
Array [ Array [
"https://registry.company.com/v2/", "https://registry.company.com/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -514,6 +559,7 @@ Array [ ...@@ -514,6 +559,7 @@ Array [
Object { Object {
"headers": Object { "headers": Object {
"accept": "application/vnd.docker.distribution.manifest.v2+json", "accept": "application/vnd.docker.distribution.manifest.v2+json",
"user-agent": "https://github.com/renovatebot/renovate",
}, },
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
...@@ -533,6 +579,9 @@ exports[`api/docker getReleases uses lower tag limit for ECR deps 1`] = ` ...@@ -533,6 +579,9 @@ exports[`api/docker getReleases uses lower tag limit for ECR deps 1`] = `
Array [ Array [
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/", "https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -546,7 +595,9 @@ exports[`api/docker getReleases uses lower tag limit for ECR deps 1`] = ` ...@@ -546,7 +595,9 @@ exports[`api/docker getReleases uses lower tag limit for ECR deps 1`] = `
Array [ Array [
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/node/tags/list?n=1000", "https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/node/tags/list?n=1000",
Object { Object {
"headers": Object {}, "headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -560,6 +611,9 @@ exports[`api/docker getReleases uses lower tag limit for ECR deps 1`] = ` ...@@ -560,6 +611,9 @@ exports[`api/docker getReleases uses lower tag limit for ECR deps 1`] = `
Array [ Array [
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/", "https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
......
...@@ -227,6 +227,9 @@ Array [ ...@@ -227,6 +227,9 @@ Array [
Array [ Array [
"https://custom.pypi.net/foo/azure-cli-monitor/json", "https://custom.pypi.net/foo/azure-cli-monitor/json",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -245,6 +248,9 @@ Array [ ...@@ -245,6 +248,9 @@ Array [
Array [ Array [
"https://my.pypi.python/pypi/azure-cli-monitor/json", "https://my.pypi.python/pypi/azure-cli-monitor/json",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -263,6 +269,9 @@ Array [ ...@@ -263,6 +269,9 @@ Array [
Array [ Array [
"https://custom.pypi.net/foo/azure-cli-monitor/json", "https://custom.pypi.net/foo/azure-cli-monitor/json",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
...@@ -276,6 +285,9 @@ Array [ ...@@ -276,6 +285,9 @@ Array [
Array [ Array [
"https://second-index/foo/azure-cli-monitor/json", "https://second-index/foo/azure-cli-monitor/json",
Object { Object {
"headers": Object {
"user-agent": "https://github.com/renovatebot/renovate",
},
"hooks": Object { "hooks": Object {
"beforeRedirect": Array [ "beforeRedirect": Array [
[Function], [Function],
......
...@@ -17,7 +17,7 @@ Object { ...@@ -17,7 +17,7 @@ Object {
"headers": Object { "headers": Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -65,7 +65,7 @@ Object { ...@@ -65,7 +65,7 @@ Object {
"headers": Object { "headers": Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -110,7 +110,7 @@ Object { ...@@ -110,7 +110,7 @@ Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"authorization": "Bearer XXX", "authorization": "Bearer XXX",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -155,7 +155,7 @@ Object { ...@@ -155,7 +155,7 @@ Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"authorization": "Bearer XXX", "authorization": "Bearer XXX",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -199,7 +199,7 @@ Object { ...@@ -199,7 +199,7 @@ Object {
"headers": Object { "headers": Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -245,7 +245,7 @@ Object { ...@@ -245,7 +245,7 @@ Object {
"headers": Object { "headers": Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -291,7 +291,7 @@ Object { ...@@ -291,7 +291,7 @@ Object {
"Private-token": "XXX", "Private-token": "XXX",
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
...@@ -337,7 +337,7 @@ Object { ...@@ -337,7 +337,7 @@ Object {
"accept": "application/json", "accept": "application/json",
"accept-encoding": "gzip, deflate", "accept-encoding": "gzip, deflate",
"authorization": "token XXX", "authorization": "token XXX",
"user-agent": "https://github.com/renovatebot/renovate", "user-agent": "got/9.6.0 (https://github.com/sindresorhus/got)",
}, },
"hooks": Object { "hooks": Object {
"afterResponse": Array [], "afterResponse": Array [],
......
import got from 'got';
import auth from './auth'; import auth from './auth';
import cacheGet from './cache-get'; import cacheGet from './cache-get';
import hostRules from './host-rules'; import hostRules from './host-rules';
import renovateAgent from './renovate-agent';
import { mergeInstances } from './util'; import { mergeInstances } from './util';
export * from './common'; export * from './common';
/* /*
* This is the default got instance for Renovate. * This is the default got instance for Renovate.
* - Set the user agent to be Renovate
* - Cache all GET requests for the lifetime of the repo * - Cache all GET requests for the lifetime of the repo
* *
*/ */
export const api = mergeInstances(cacheGet, renovateAgent, hostRules, auth); export const api = mergeInstances(got, cacheGet, hostRules, auth);
export default api; export default api;
import got from 'got';
// Sets the user agent to be Renovate
export default got.extend({
headers: {
'user-agent':
process.env.RENOVATE_USER_AGENT ||
'https://github.com/renovatebot/renovate',
},
});
...@@ -67,6 +67,12 @@ export class Http<GetOptions = HttpOptions, PostOptions = HttpPostOptions> { ...@@ -67,6 +67,12 @@ export class Http<GetOptions = HttpOptions, PostOptions = HttpPostOptions> {
}, },
], ],
}; };
combinedOptions.headers = {
...combinedOptions.headers,
'user-agent':
process.env.RENOVATE_USER_AGENT ||
'https://github.com/renovatebot/renovate',
};
const res = await got(resolvedUrl, combinedOptions); const res = await got(resolvedUrl, combinedOptions);
return { body: res.body, headers: res.headers }; return { body: res.body, headers: res.headers };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment