@backstage/integration 0.8.0 → 1.1.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/config.d.ts +31 -0
- package/dist/index.cjs.js +136 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +109 -1
- package/dist/index.esm.js +132 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.1.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b7436743cb: Gerrit integration: Added an optional configuration to set the Gitiles base url.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 1691c6c5c2: Clarify that config locations that emit User and Group kinds now need to declare so in the `catalog.locations.[].rules`
|
|
12
|
+
|
|
13
|
+
## 1.0.1-next.0
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 3ef123bbf0: Support external ID when assuming roles in S3 integration
|
|
18
|
+
|
|
19
|
+
In order to assume a role created by a 3rd party as external
|
|
20
|
+
ID is needed. This change adds an optional field to the s3
|
|
21
|
+
integration configuration and consumes that in the AwsS3UrlReader.
|
|
22
|
+
|
|
23
|
+
## 1.0.0
|
|
24
|
+
|
|
25
|
+
### Major Changes
|
|
26
|
+
|
|
27
|
+
- b58c70c223: This package has been promoted to v1.0! To understand how this change affects the package, please check out our [versioning policy](https://backstage.io/docs/overview/versioning-policy).
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 403837cbac: Added an integration for Gerrit
|
|
32
|
+
- Updated dependencies
|
|
33
|
+
- @backstage/config@1.0.0
|
|
34
|
+
|
|
3
35
|
## 0.8.0
|
|
4
36
|
|
|
5
37
|
### Minor Changes
|
|
@@ -215,6 +247,8 @@
|
|
|
215
247
|
locations:
|
|
216
248
|
- type: github-multi-org
|
|
217
249
|
target: https://github.myorg.com
|
|
250
|
+
rules:
|
|
251
|
+
- allow: [User, Group]
|
|
218
252
|
|
|
219
253
|
processors:
|
|
220
254
|
githubMultiOrg:
|
package/config.d.ts
CHANGED
|
@@ -60,6 +60,31 @@ export interface Config {
|
|
|
60
60
|
appPassword?: string;
|
|
61
61
|
}>;
|
|
62
62
|
|
|
63
|
+
/** Integration configuration for Gerrit */
|
|
64
|
+
gerrit?: Array<{
|
|
65
|
+
/**
|
|
66
|
+
* The hostname of the given Gerrit instance
|
|
67
|
+
* @visibility frontend
|
|
68
|
+
*/
|
|
69
|
+
host: string;
|
|
70
|
+
/**
|
|
71
|
+
* The base url for the Gerrit instance.
|
|
72
|
+
* @visibility frontend
|
|
73
|
+
*/
|
|
74
|
+
baseUrl?: string;
|
|
75
|
+
/**
|
|
76
|
+
* The username to use for authenticated requests.
|
|
77
|
+
* @visibility secret
|
|
78
|
+
*/
|
|
79
|
+
username?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Gerrit password used to authenticate requests. This can be either a password
|
|
82
|
+
* or a generated access token.
|
|
83
|
+
* @visibility secret
|
|
84
|
+
*/
|
|
85
|
+
password?: string;
|
|
86
|
+
}>;
|
|
87
|
+
|
|
63
88
|
/** Integration configuration for GitHub */
|
|
64
89
|
github?: Array<{
|
|
65
90
|
/**
|
|
@@ -200,6 +225,12 @@ export interface Config {
|
|
|
200
225
|
* @visibility backend
|
|
201
226
|
*/
|
|
202
227
|
roleArn?: string;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* External ID to use when assuming role
|
|
231
|
+
* @visibility backend
|
|
232
|
+
*/
|
|
233
|
+
externalId?: string;
|
|
203
234
|
}>;
|
|
204
235
|
};
|
|
205
236
|
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -451,6 +451,129 @@ function getBitbucketRequestOptions(config) {
|
|
|
451
451
|
};
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
+
function readGerritIntegrationConfig(config) {
|
|
455
|
+
const host = config.getString("host");
|
|
456
|
+
let baseUrl = config.getOptionalString("baseUrl");
|
|
457
|
+
let gitilesBaseUrl = config.getOptionalString("gitilesBaseUrl");
|
|
458
|
+
const username = config.getOptionalString("username");
|
|
459
|
+
const password = config.getOptionalString("password");
|
|
460
|
+
if (!isValidHost(host)) {
|
|
461
|
+
throw new Error(`Invalid Gerrit integration config, '${host}' is not a valid host`);
|
|
462
|
+
} else if (baseUrl && !isValidUrl(baseUrl)) {
|
|
463
|
+
throw new Error(`Invalid Gerrit integration config, '${baseUrl}' is not a valid baseUrl`);
|
|
464
|
+
} else if (gitilesBaseUrl && !isValidUrl(gitilesBaseUrl)) {
|
|
465
|
+
throw new Error(`Invalid Gerrit integration config, '${gitilesBaseUrl}' is not a valid gitilesBaseUrl`);
|
|
466
|
+
}
|
|
467
|
+
if (baseUrl) {
|
|
468
|
+
baseUrl = lodash.trimEnd(baseUrl, "/");
|
|
469
|
+
} else {
|
|
470
|
+
baseUrl = `https://${host}`;
|
|
471
|
+
}
|
|
472
|
+
if (gitilesBaseUrl) {
|
|
473
|
+
gitilesBaseUrl = lodash.trimEnd(gitilesBaseUrl, "/");
|
|
474
|
+
} else {
|
|
475
|
+
gitilesBaseUrl = `https://${host}`;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
host,
|
|
479
|
+
baseUrl,
|
|
480
|
+
gitilesBaseUrl,
|
|
481
|
+
username,
|
|
482
|
+
password
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function readGerritIntegrationConfigs(configs) {
|
|
486
|
+
return configs.map(readGerritIntegrationConfig);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const _GerritIntegration = class {
|
|
490
|
+
constructor(integrationConfig) {
|
|
491
|
+
this.integrationConfig = integrationConfig;
|
|
492
|
+
}
|
|
493
|
+
get type() {
|
|
494
|
+
return "gerrit";
|
|
495
|
+
}
|
|
496
|
+
get title() {
|
|
497
|
+
return this.integrationConfig.host;
|
|
498
|
+
}
|
|
499
|
+
get config() {
|
|
500
|
+
return this.integrationConfig;
|
|
501
|
+
}
|
|
502
|
+
resolveUrl(options) {
|
|
503
|
+
const { url, base, lineNumber } = options;
|
|
504
|
+
let updated;
|
|
505
|
+
if (url) {
|
|
506
|
+
updated = new URL(url, base);
|
|
507
|
+
} else {
|
|
508
|
+
updated = new URL(base);
|
|
509
|
+
}
|
|
510
|
+
if (lineNumber) {
|
|
511
|
+
updated.hash = lineNumber.toString();
|
|
512
|
+
}
|
|
513
|
+
return updated.toString();
|
|
514
|
+
}
|
|
515
|
+
resolveEditUrl(url) {
|
|
516
|
+
return url;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
let GerritIntegration = _GerritIntegration;
|
|
520
|
+
GerritIntegration.factory = ({ config }) => {
|
|
521
|
+
var _a;
|
|
522
|
+
const configs = readGerritIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gerrit")) != null ? _a : []);
|
|
523
|
+
return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
const GERRIT_BODY_PREFIX = ")]}'";
|
|
527
|
+
function parseGitilesUrl(config, url) {
|
|
528
|
+
const urlPath = url.replace(config.gitilesBaseUrl, "");
|
|
529
|
+
const parts = urlPath.split("/").filter((p) => !!p);
|
|
530
|
+
const projectEndIndex = parts.indexOf("+");
|
|
531
|
+
if (projectEndIndex <= 0) {
|
|
532
|
+
throw new Error(`Unable to parse project from url: ${url}`);
|
|
533
|
+
}
|
|
534
|
+
const project = lodash.trimStart(parts.slice(0, projectEndIndex).join("/"), "/");
|
|
535
|
+
const branchIndex = parts.indexOf("heads");
|
|
536
|
+
if (branchIndex <= 0) {
|
|
537
|
+
throw new Error(`Unable to parse branch from url: ${url}`);
|
|
538
|
+
}
|
|
539
|
+
const branch = parts[branchIndex + 1];
|
|
540
|
+
const filePath = parts.slice(branchIndex + 2).join("/");
|
|
541
|
+
return {
|
|
542
|
+
branch,
|
|
543
|
+
filePath: filePath === "" ? "/" : filePath,
|
|
544
|
+
project
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
function getAuthenticationPrefix(config) {
|
|
548
|
+
return config.password ? "/a/" : "/";
|
|
549
|
+
}
|
|
550
|
+
function getGerritFileContentsApiUrl(config, url) {
|
|
551
|
+
const { branch, filePath, project } = parseGitilesUrl(config, url);
|
|
552
|
+
return `${config.baseUrl}${getAuthenticationPrefix(config)}projects/${encodeURIComponent(project)}/branches/${branch}/files/${encodeURIComponent(filePath)}/content`;
|
|
553
|
+
}
|
|
554
|
+
function getGerritRequestOptions(config) {
|
|
555
|
+
const headers = {};
|
|
556
|
+
if (!config.password) {
|
|
557
|
+
return headers;
|
|
558
|
+
}
|
|
559
|
+
const buffer = Buffer.from(`${config.username}:${config.password}`, "utf8");
|
|
560
|
+
headers.Authorization = `Basic ${buffer.toString("base64")}`;
|
|
561
|
+
return {
|
|
562
|
+
headers
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
async function parseGerritJsonResponse(response) {
|
|
566
|
+
const responseBody = await response.text();
|
|
567
|
+
if (responseBody.startsWith(GERRIT_BODY_PREFIX)) {
|
|
568
|
+
try {
|
|
569
|
+
return JSON.parse(responseBody.slice(GERRIT_BODY_PREFIX.length));
|
|
570
|
+
} catch (ex) {
|
|
571
|
+
throw new Error(`Invalid response from Gerrit: ${responseBody.slice(0, 10)} - ${ex}`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
throw new Error(`Gerrit JSON body prefix missing. Found: ${responseBody.slice(0, 10)}`);
|
|
575
|
+
}
|
|
576
|
+
|
|
454
577
|
const GITHUB_HOST = "github.com";
|
|
455
578
|
const GITHUB_API_BASE_URL = "https://api.github.com";
|
|
456
579
|
const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
|
|
@@ -896,13 +1019,15 @@ function readAwsS3IntegrationConfig(config) {
|
|
|
896
1019
|
const accessKeyId = config.getOptionalString("accessKeyId");
|
|
897
1020
|
const secretAccessKey = config.getOptionalString("secretAccessKey");
|
|
898
1021
|
const roleArn = config.getOptionalString("roleArn");
|
|
1022
|
+
const externalId = config.getOptionalString("externalId");
|
|
899
1023
|
return {
|
|
900
1024
|
host,
|
|
901
1025
|
endpoint,
|
|
902
1026
|
s3ForcePathStyle,
|
|
903
1027
|
accessKeyId,
|
|
904
1028
|
secretAccessKey,
|
|
905
|
-
roleArn
|
|
1029
|
+
roleArn,
|
|
1030
|
+
externalId
|
|
906
1031
|
};
|
|
907
1032
|
}
|
|
908
1033
|
function readAwsS3IntegrationConfigs(configs) {
|
|
@@ -949,6 +1074,7 @@ class ScmIntegrations {
|
|
|
949
1074
|
awsS3: AwsS3Integration.factory({ config }),
|
|
950
1075
|
azure: AzureIntegration.factory({ config }),
|
|
951
1076
|
bitbucket: BitbucketIntegration.factory({ config }),
|
|
1077
|
+
gerrit: GerritIntegration.factory({ config }),
|
|
952
1078
|
github: GitHubIntegration.factory({ config }),
|
|
953
1079
|
gitlab: GitLabIntegration.factory({ config })
|
|
954
1080
|
});
|
|
@@ -965,6 +1091,9 @@ class ScmIntegrations {
|
|
|
965
1091
|
get bitbucket() {
|
|
966
1092
|
return this.byType.bitbucket;
|
|
967
1093
|
}
|
|
1094
|
+
get gerrit() {
|
|
1095
|
+
return this.byType.gerrit;
|
|
1096
|
+
}
|
|
968
1097
|
get github() {
|
|
969
1098
|
return this.byType.github;
|
|
970
1099
|
}
|
|
@@ -1000,6 +1129,7 @@ exports.AwsS3Integration = AwsS3Integration;
|
|
|
1000
1129
|
exports.AzureIntegration = AzureIntegration;
|
|
1001
1130
|
exports.BitbucketIntegration = BitbucketIntegration;
|
|
1002
1131
|
exports.DefaultGithubCredentialsProvider = DefaultGithubCredentialsProvider;
|
|
1132
|
+
exports.GerritIntegration = GerritIntegration;
|
|
1003
1133
|
exports.GitHubIntegration = GitHubIntegration;
|
|
1004
1134
|
exports.GitLabIntegration = GitLabIntegration;
|
|
1005
1135
|
exports.GithubAppCredentialsMux = GithubAppCredentialsMux;
|
|
@@ -1014,16 +1144,21 @@ exports.getBitbucketDefaultBranch = getBitbucketDefaultBranch;
|
|
|
1014
1144
|
exports.getBitbucketDownloadUrl = getBitbucketDownloadUrl;
|
|
1015
1145
|
exports.getBitbucketFileFetchUrl = getBitbucketFileFetchUrl;
|
|
1016
1146
|
exports.getBitbucketRequestOptions = getBitbucketRequestOptions;
|
|
1147
|
+
exports.getGerritFileContentsApiUrl = getGerritFileContentsApiUrl;
|
|
1148
|
+
exports.getGerritRequestOptions = getGerritRequestOptions;
|
|
1017
1149
|
exports.getGitHubFileFetchUrl = getGitHubFileFetchUrl;
|
|
1018
1150
|
exports.getGitHubRequestOptions = getGitHubRequestOptions;
|
|
1019
1151
|
exports.getGitLabFileFetchUrl = getGitLabFileFetchUrl;
|
|
1020
1152
|
exports.getGitLabRequestOptions = getGitLabRequestOptions;
|
|
1153
|
+
exports.parseGerritJsonResponse = parseGerritJsonResponse;
|
|
1021
1154
|
exports.readAwsS3IntegrationConfig = readAwsS3IntegrationConfig;
|
|
1022
1155
|
exports.readAwsS3IntegrationConfigs = readAwsS3IntegrationConfigs;
|
|
1023
1156
|
exports.readAzureIntegrationConfig = readAzureIntegrationConfig;
|
|
1024
1157
|
exports.readAzureIntegrationConfigs = readAzureIntegrationConfigs;
|
|
1025
1158
|
exports.readBitbucketIntegrationConfig = readBitbucketIntegrationConfig;
|
|
1026
1159
|
exports.readBitbucketIntegrationConfigs = readBitbucketIntegrationConfigs;
|
|
1160
|
+
exports.readGerritIntegrationConfig = readGerritIntegrationConfig;
|
|
1161
|
+
exports.readGerritIntegrationConfigs = readGerritIntegrationConfigs;
|
|
1027
1162
|
exports.readGitHubIntegrationConfig = readGitHubIntegrationConfig;
|
|
1028
1163
|
exports.readGitHubIntegrationConfigs = readGitHubIntegrationConfigs;
|
|
1029
1164
|
exports.readGitLabIntegrationConfig = readGitLabIntegrationConfig;
|