@backstage/integration 1.3.1-next.1 → 1.3.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 +31 -0
- package/dist/index.cjs.js +34 -24
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +34 -24
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @backstage/integration
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eadf56bbbf: Bump `git-url-parse` version to `^13.0.0`
|
|
8
|
+
- 7d47def9c4: Removed dependency on `@types/jest`.
|
|
9
|
+
- 667d917488: Updated dependency `msw` to `^0.47.0`.
|
|
10
|
+
- 87ec2ba4d6: Updated dependency `msw` to `^0.46.0`.
|
|
11
|
+
- bf5e9030eb: Updated dependency `msw` to `^0.45.0`.
|
|
12
|
+
- 42918e085c: Fixed bug in the `bitbucketServer` integration where token did not take precedence over supplied username and password which is described in the documentation.
|
|
13
|
+
- f76f22c649: Improved caching around github app tokens.
|
|
14
|
+
Tokens are now cached for 50 minutes, not 10.
|
|
15
|
+
Calls to get app installations are also included in this cache.
|
|
16
|
+
If you have more than one github app configured, consider adding `allowedInstallationOwners` to your apps configuration to gain the most benefit from these performance changes.
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @backstage/config@1.0.2
|
|
19
|
+
- @backstage/errors@1.1.1
|
|
20
|
+
|
|
21
|
+
## 1.3.1-next.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 7d47def9c4: Removed dependency on `@types/jest`.
|
|
26
|
+
- f76f22c649: Improved caching around github app tokens.
|
|
27
|
+
Tokens are now cached for 50 minutes, not 10.
|
|
28
|
+
Calls to get app installations are also included in this cache.
|
|
29
|
+
If you have more than one github app configured, consider adding `allowedInstallationOwners` to your apps configuration to gain the most benefit from these performance changes.
|
|
30
|
+
- Updated dependencies
|
|
31
|
+
- @backstage/config@1.0.2-next.0
|
|
32
|
+
- @backstage/errors@1.1.1-next.0
|
|
33
|
+
|
|
3
34
|
## 1.3.1-next.1
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -1081,16 +1081,30 @@ function chooseEndpoint(config, credentials) {
|
|
|
1081
1081
|
class Cache {
|
|
1082
1082
|
constructor() {
|
|
1083
1083
|
this.tokenCache = /* @__PURE__ */ new Map();
|
|
1084
|
-
this.
|
|
1084
|
+
this.isExpired = (date) => luxon.DateTime.local() > date;
|
|
1085
|
+
}
|
|
1086
|
+
async getOrCreateToken(owner, repo, supplier) {
|
|
1087
|
+
let existingInstallationData = this.tokenCache.get(owner);
|
|
1088
|
+
if (!existingInstallationData || this.isExpired(existingInstallationData.expiresAt)) {
|
|
1089
|
+
existingInstallationData = await supplier();
|
|
1090
|
+
existingInstallationData.expiresAt = existingInstallationData.expiresAt.minus({ minutes: 10 });
|
|
1091
|
+
this.tokenCache.set(owner, existingInstallationData);
|
|
1092
|
+
}
|
|
1093
|
+
if (!this.appliesToRepo(existingInstallationData, repo)) {
|
|
1094
|
+
throw new Error(
|
|
1095
|
+
`The Backstage GitHub application used in the ${owner} organization does not have access to a repository with the name ${repo}`
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
return { accessToken: existingInstallationData.token };
|
|
1085
1099
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1100
|
+
appliesToRepo(tokenData, repo) {
|
|
1101
|
+
if (repo === void 0) {
|
|
1102
|
+
return true;
|
|
1103
|
+
}
|
|
1104
|
+
if (tokenData.repositories !== void 0) {
|
|
1105
|
+
return tokenData.repositories.includes(repo);
|
|
1090
1106
|
}
|
|
1091
|
-
|
|
1092
|
-
this.tokenCache.set(key, result);
|
|
1093
|
-
return { accessToken: result.token };
|
|
1107
|
+
return true;
|
|
1094
1108
|
}
|
|
1095
1109
|
}
|
|
1096
1110
|
const HEADERS = {
|
|
@@ -1114,23 +1128,25 @@ class GithubAppManager {
|
|
|
1114
1128
|
}
|
|
1115
1129
|
async getInstallationCredentials(owner, repo) {
|
|
1116
1130
|
var _a;
|
|
1117
|
-
const { installationId, suspended } = await this.getInstallationData(owner);
|
|
1118
1131
|
if (this.allowedInstallationOwners) {
|
|
1119
1132
|
if (!((_a = this.allowedInstallationOwners) == null ? void 0 : _a.includes(owner))) {
|
|
1120
1133
|
return { accessToken: void 0 };
|
|
1121
1134
|
}
|
|
1122
1135
|
}
|
|
1123
|
-
|
|
1124
|
-
throw new Error(`The GitHub application for ${owner} is suspended`);
|
|
1125
|
-
}
|
|
1126
|
-
const cacheKey = repo ? `${owner}/${repo}` : owner;
|
|
1127
|
-
return this.cache.getOrCreateToken(cacheKey, async () => {
|
|
1136
|
+
return this.cache.getOrCreateToken(owner, repo, async () => {
|
|
1128
1137
|
var _a2;
|
|
1138
|
+
const { installationId, suspended } = await this.getInstallationData(
|
|
1139
|
+
owner
|
|
1140
|
+
);
|
|
1141
|
+
if (suspended) {
|
|
1142
|
+
throw new Error(`The GitHub application for ${owner} is suspended`);
|
|
1143
|
+
}
|
|
1129
1144
|
const result = await this.appClient.apps.createInstallationAccessToken({
|
|
1130
1145
|
installation_id: installationId,
|
|
1131
1146
|
headers: HEADERS
|
|
1132
1147
|
});
|
|
1133
|
-
|
|
1148
|
+
let repositoryNames;
|
|
1149
|
+
if (result.data.repository_selection === "selected") {
|
|
1134
1150
|
const installationClient = new rest.Octokit({
|
|
1135
1151
|
baseUrl: this.baseUrl,
|
|
1136
1152
|
auth: result.data.token
|
|
@@ -1139,18 +1155,12 @@ class GithubAppManager {
|
|
|
1139
1155
|
installationClient.apps.listReposAccessibleToInstallation
|
|
1140
1156
|
);
|
|
1141
1157
|
const repositories = (_a2 = repos.repositories) != null ? _a2 : repos;
|
|
1142
|
-
|
|
1143
|
-
return repository.name === repo;
|
|
1144
|
-
});
|
|
1145
|
-
if (!hasRepo) {
|
|
1146
|
-
throw new Error(
|
|
1147
|
-
`The Backstage GitHub application used in the ${owner} organization does not have access to a repository with the name ${repo}`
|
|
1148
|
-
);
|
|
1149
|
-
}
|
|
1158
|
+
repositoryNames = repositories.map((repository) => repository.name);
|
|
1150
1159
|
}
|
|
1151
1160
|
return {
|
|
1152
1161
|
token: result.data.token,
|
|
1153
|
-
expiresAt: luxon.DateTime.fromISO(result.data.expires_at)
|
|
1162
|
+
expiresAt: luxon.DateTime.fromISO(result.data.expires_at),
|
|
1163
|
+
repositories: repositoryNames
|
|
1154
1164
|
};
|
|
1155
1165
|
});
|
|
1156
1166
|
}
|