@backstage/integration 1.0.0 → 1.1.0-next.2

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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # @backstage/integration
2
2
 
3
+ ## 1.1.0-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - d26e1b0146: Exported `replaceGitLabUrlType` from package
8
+
9
+ ## 1.1.0-next.1
10
+
11
+ ### Minor Changes
12
+
13
+ - b7436743cb: Gerrit integration: Added an optional configuration to set the Gitiles base url.
14
+
15
+ ### Patch Changes
16
+
17
+ - 1691c6c5c2: Clarify that config locations that emit User and Group kinds now need to declare so in the `catalog.locations.[].rules`
18
+
19
+ ## 1.0.1-next.0
20
+
21
+ ### Patch Changes
22
+
23
+ - 3ef123bbf0: Support external ID when assuming roles in S3 integration
24
+
25
+ In order to assume a role created by a 3rd party as external
26
+ ID is needed. This change adds an optional field to the s3
27
+ integration configuration and consumes that in the AwsS3UrlReader.
28
+
3
29
  ## 1.0.0
4
30
 
5
31
  ### Major Changes
@@ -227,6 +253,8 @@
227
253
  locations:
228
254
  - type: github-multi-org
229
255
  target: https://github.myorg.com
256
+ rules:
257
+ - allow: [User, Group]
230
258
 
231
259
  processors:
232
260
  githubMultiOrg:
package/config.d.ts CHANGED
@@ -225,6 +225,12 @@ export interface Config {
225
225
  * @visibility backend
226
226
  */
227
227
  roleArn?: string;
228
+
229
+ /**
230
+ * External ID to use when assuming role
231
+ * @visibility backend
232
+ */
233
+ externalId?: string;
228
234
  }>;
229
235
  };
230
236
  }
package/dist/index.cjs.js CHANGED
@@ -454,21 +454,30 @@ function getBitbucketRequestOptions(config) {
454
454
  function readGerritIntegrationConfig(config) {
455
455
  const host = config.getString("host");
456
456
  let baseUrl = config.getOptionalString("baseUrl");
457
+ let gitilesBaseUrl = config.getOptionalString("gitilesBaseUrl");
457
458
  const username = config.getOptionalString("username");
458
459
  const password = config.getOptionalString("password");
459
460
  if (!isValidHost(host)) {
460
461
  throw new Error(`Invalid Gerrit integration config, '${host}' is not a valid host`);
461
462
  } else if (baseUrl && !isValidUrl(baseUrl)) {
462
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`);
463
466
  }
464
467
  if (baseUrl) {
465
468
  baseUrl = lodash.trimEnd(baseUrl, "/");
466
469
  } else {
467
470
  baseUrl = `https://${host}`;
468
471
  }
472
+ if (gitilesBaseUrl) {
473
+ gitilesBaseUrl = lodash.trimEnd(gitilesBaseUrl, "/");
474
+ } else {
475
+ gitilesBaseUrl = `https://${host}`;
476
+ }
469
477
  return {
470
478
  host,
471
479
  baseUrl,
480
+ gitilesBaseUrl,
472
481
  username,
473
482
  password
474
483
  };
@@ -514,6 +523,57 @@ GerritIntegration.factory = ({ config }) => {
514
523
  return basicIntegrations(configs.map((c) => new _GerritIntegration(c)), (i) => i.config.host);
515
524
  };
516
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
+
517
577
  const GITHUB_HOST = "github.com";
518
578
  const GITHUB_API_BASE_URL = "https://api.github.com";
519
579
  const GITHUB_RAW_BASE_URL = "https://raw.githubusercontent.com";
@@ -910,7 +970,7 @@ const _GitLabIntegration = class {
910
970
  return defaultScmResolveUrl(options);
911
971
  }
912
972
  resolveEditUrl(url) {
913
- return replaceUrlType(url, "edit");
973
+ return replaceGitLabUrlType(url, "edit");
914
974
  }
915
975
  };
916
976
  let GitLabIntegration = _GitLabIntegration;
@@ -919,7 +979,7 @@ GitLabIntegration.factory = ({ config }) => {
919
979
  const configs = readGitLabIntegrationConfigs((_a = config.getOptionalConfigArray("integrations.gitlab")) != null ? _a : []);
920
980
  return basicIntegrations(configs.map((c) => new _GitLabIntegration(c)), (i) => i.config.host);
921
981
  };
922
- function replaceUrlType(url, type) {
982
+ function replaceGitLabUrlType(url, type) {
923
983
  return url.replace(/\/\-\/(blob|tree|edit)\//, `/-/${type}/`);
924
984
  }
925
985
 
@@ -959,13 +1019,15 @@ function readAwsS3IntegrationConfig(config) {
959
1019
  const accessKeyId = config.getOptionalString("accessKeyId");
960
1020
  const secretAccessKey = config.getOptionalString("secretAccessKey");
961
1021
  const roleArn = config.getOptionalString("roleArn");
1022
+ const externalId = config.getOptionalString("externalId");
962
1023
  return {
963
1024
  host,
964
1025
  endpoint,
965
1026
  s3ForcePathStyle,
966
1027
  accessKeyId,
967
1028
  secretAccessKey,
968
- roleArn
1029
+ roleArn,
1030
+ externalId
969
1031
  };
970
1032
  }
971
1033
  function readAwsS3IntegrationConfigs(configs) {
@@ -1082,10 +1144,13 @@ exports.getBitbucketDefaultBranch = getBitbucketDefaultBranch;
1082
1144
  exports.getBitbucketDownloadUrl = getBitbucketDownloadUrl;
1083
1145
  exports.getBitbucketFileFetchUrl = getBitbucketFileFetchUrl;
1084
1146
  exports.getBitbucketRequestOptions = getBitbucketRequestOptions;
1147
+ exports.getGerritFileContentsApiUrl = getGerritFileContentsApiUrl;
1148
+ exports.getGerritRequestOptions = getGerritRequestOptions;
1085
1149
  exports.getGitHubFileFetchUrl = getGitHubFileFetchUrl;
1086
1150
  exports.getGitHubRequestOptions = getGitHubRequestOptions;
1087
1151
  exports.getGitLabFileFetchUrl = getGitLabFileFetchUrl;
1088
1152
  exports.getGitLabRequestOptions = getGitLabRequestOptions;
1153
+ exports.parseGerritJsonResponse = parseGerritJsonResponse;
1089
1154
  exports.readAwsS3IntegrationConfig = readAwsS3IntegrationConfig;
1090
1155
  exports.readAwsS3IntegrationConfigs = readAwsS3IntegrationConfigs;
1091
1156
  exports.readAzureIntegrationConfig = readAzureIntegrationConfig;
@@ -1100,4 +1165,5 @@ exports.readGitLabIntegrationConfig = readGitLabIntegrationConfig;
1100
1165
  exports.readGitLabIntegrationConfigs = readGitLabIntegrationConfigs;
1101
1166
  exports.readGoogleGcsIntegrationConfig = readGoogleGcsIntegrationConfig;
1102
1167
  exports.replaceGitHubUrlType = replaceGitHubUrlType;
1168
+ exports.replaceGitLabUrlType = replaceGitLabUrlType;
1103
1169
  //# sourceMappingURL=index.cjs.js.map