mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
refactor: terraform registryUrls
This commit is contained in:
parent
0f12451c5c
commit
ba59a21505
4 changed files with 28 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const parse = require('github-url-from-git');
|
const parse = require('github-url-from-git');
|
||||||
|
const is = require('@sindresorhus/is');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getPkgReleases,
|
getPkgReleases,
|
||||||
|
@ -13,12 +14,14 @@ module.exports = {
|
||||||
* - `homepage` is set to the Terraform registry's page if it's on the official main registry
|
* - `homepage` is set to the Terraform registry's page if it's on the official main registry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function getPkgReleases(purl) {
|
async function getPkgReleases(purl, config) {
|
||||||
const { lookupName: dependency, qualifiers } = purl;
|
const { lookupName: dependency } = purl;
|
||||||
const registry = qualifiers.registry || 'registry.terraform.io';
|
const registry = is.nonEmptyArray(config.repositoryUrls)
|
||||||
|
? config.repositoryUrls[0]
|
||||||
|
: 'https://registry.terraform.io';
|
||||||
logger.debug({ dependency, registry }, 'terraform.getDependencies()');
|
logger.debug({ dependency, registry }, 'terraform.getDependencies()');
|
||||||
const cacheNamespace = 'terraform';
|
const cacheNamespace = 'terraform';
|
||||||
const pkgUrl = `https://${registry}/v1/modules/${dependency}`;
|
const pkgUrl = `${registry}/v1/modules/${dependency}`;
|
||||||
const cachedResult = await renovateCache.get(cacheNamespace, pkgUrl);
|
const cachedResult = await renovateCache.get(cacheNamespace, pkgUrl);
|
||||||
// istanbul ignore if
|
// istanbul ignore if
|
||||||
if (cachedResult) {
|
if (cachedResult) {
|
||||||
|
|
|
@ -71,11 +71,11 @@ function extractPackageFile(content) {
|
||||||
dep.purl = 'pkg:terraform/' + dep.depName;
|
dep.purl = 'pkg:terraform/' + dep.depName;
|
||||||
} else if (moduleParts.length === 4) {
|
} else if (moduleParts.length === 4) {
|
||||||
dep.depType = 'terraform';
|
dep.depType = 'terraform';
|
||||||
dep.registry = moduleParts.shift();
|
dep.registryUrls = ['https://' + moduleParts.shift()];
|
||||||
dep.depName = moduleParts.join('/');
|
dep.depName = moduleParts.join('/');
|
||||||
dep.depNameShort = dep.depName;
|
dep.depNameShort = dep.depName;
|
||||||
dep.lineNumber = dep.versionLine;
|
dep.lineNumber = dep.versionLine;
|
||||||
dep.purl = 'pkg:terraform/' + dep.depName + '?registry=' + dep.registry;
|
dep.purl = 'pkg:terraform/' + dep.depName;
|
||||||
}
|
}
|
||||||
if (dep.lineNumber) {
|
if (dep.lineNumber) {
|
||||||
if (!isValid(dep.currentValue)) {
|
if (!isValid(dep.currentValue)) {
|
||||||
|
|
|
@ -59,9 +59,13 @@ describe('datasource/terraform', () => {
|
||||||
got.mockReturnValueOnce({
|
got.mockReturnValueOnce({
|
||||||
body: JSON.parse(consulData),
|
body: JSON.parse(consulData),
|
||||||
});
|
});
|
||||||
const res = await datasource.getPkgReleases({
|
const config = { registryUrls: 'https://terraform.company.com' };
|
||||||
purl: 'pkg:terraform/consul/foo?registry=hashicorp',
|
const res = await datasource.getPkgReleases(
|
||||||
});
|
{
|
||||||
|
purl: 'pkg:terraform/consul/foo',
|
||||||
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
expect(res).toBeNull();
|
expect(res).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -91,8 +91,10 @@ Object {
|
||||||
"depType": "terraform",
|
"depType": "terraform",
|
||||||
"lineNumber": 71,
|
"lineNumber": 71,
|
||||||
"moduleName": "consul",
|
"moduleName": "consul",
|
||||||
"purl": "pkg:terraform/example-corp/k8s-cluster/azurerm?registry=app.terraform.io",
|
"purl": "pkg:terraform/example-corp/k8s-cluster/azurerm",
|
||||||
"registry": "app.terraform.io",
|
"registryUrls": Array [
|
||||||
|
"https://app.terraform.io",
|
||||||
|
],
|
||||||
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
|
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
@ -102,8 +104,10 @@ Object {
|
||||||
"depType": "terraform",
|
"depType": "terraform",
|
||||||
"lineNumber": 76,
|
"lineNumber": 76,
|
||||||
"moduleName": "consul2",
|
"moduleName": "consul2",
|
||||||
"purl": "pkg:terraform/example-corp/k8s-cluster/azurerm?registry=app.terraform.io",
|
"purl": "pkg:terraform/example-corp/k8s-cluster/azurerm",
|
||||||
"registry": "app.terraform.io",
|
"registryUrls": Array [
|
||||||
|
"https://app.terraform.io",
|
||||||
|
],
|
||||||
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
|
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
@ -113,8 +117,10 @@ Object {
|
||||||
"depType": "terraform",
|
"depType": "terraform",
|
||||||
"lineNumber": 81,
|
"lineNumber": 81,
|
||||||
"moduleName": "consul3",
|
"moduleName": "consul3",
|
||||||
"purl": "pkg:terraform/example-corp/k8s-cluster/azurerm?registry=app.terraform.io",
|
"purl": "pkg:terraform/example-corp/k8s-cluster/azurerm",
|
||||||
"registry": "app.terraform.io",
|
"registryUrls": Array [
|
||||||
|
"https://app.terraform.io",
|
||||||
|
],
|
||||||
"skipReason": "unsupported-version",
|
"skipReason": "unsupported-version",
|
||||||
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
|
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue