@backstage/backend-defaults 0.7.0-next.0 → 0.7.0
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,56 @@
|
|
|
1
1
|
# @backstage/backend-defaults
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ec547b8: Ensure that an error handler middleware exists at the end of each plugin `httpRouter` handler chain. This makes it so that exceptions thrown by plugin routes are caught and encoded in the standard error format.
|
|
8
|
+
|
|
9
|
+
If you were using the standard `MiddlewareFactory` just to put an `error` middleware in you router, you can now remove that at your earliest convenience since it's redundant. If you have custom error handlers in your plugin router, those will continue to function as previously. If you were relying on thrown errors propagating all the way down to the root HTTP router, you will find that they no longer do that, and may want to hoist your error handling up to the plugin level instead.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 575613f: Go back to using `node-fetch` for gitlab
|
|
14
|
+
- d2b16db: The `GerritUrlReader` can now read content from a commit and not only from the top of a branch. The
|
|
15
|
+
Gitiles URL must contain the full commit `SHA` hash like: `https://gerrit.com/gitiles/repo/+/2846e8dc327ae2f60249983b1c3b96f42f205bae/catalog-info.yaml`.
|
|
16
|
+
- 8ecf8cb: Exclude `@backstage/backend-common` from schema collection if `@backstage/backend-defaults` is present
|
|
17
|
+
- 8379bf4: Remove usages of `PluginDatabaseManager` and `PluginEndpointDiscovery` and replace with their equivalent service types
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/backend-app-api@1.1.1
|
|
20
|
+
- @backstage/types@1.2.1
|
|
21
|
+
- @backstage/config-loader@1.9.5
|
|
22
|
+
- @backstage/plugin-permission-node@0.8.7
|
|
23
|
+
- @backstage/plugin-auth-node@0.5.6
|
|
24
|
+
- @backstage/integration@1.16.1
|
|
25
|
+
- @backstage/backend-dev-utils@0.1.5
|
|
26
|
+
- @backstage/backend-plugin-api@1.1.1
|
|
27
|
+
- @backstage/cli-common@0.1.15
|
|
28
|
+
- @backstage/cli-node@0.2.12
|
|
29
|
+
- @backstage/config@1.3.2
|
|
30
|
+
- @backstage/errors@1.2.7
|
|
31
|
+
- @backstage/integration-aws-node@0.1.15
|
|
32
|
+
- @backstage/plugin-events-node@0.4.7
|
|
33
|
+
|
|
34
|
+
## 0.7.0-next.1
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies
|
|
39
|
+
- @backstage/types@1.2.1-next.0
|
|
40
|
+
- @backstage/backend-app-api@1.1.1-next.1
|
|
41
|
+
- @backstage/backend-plugin-api@1.1.1-next.1
|
|
42
|
+
- @backstage/cli-node@0.2.12-next.0
|
|
43
|
+
- @backstage/config@1.3.2-next.0
|
|
44
|
+
- @backstage/config-loader@1.9.5-next.1
|
|
45
|
+
- @backstage/errors@1.2.7-next.0
|
|
46
|
+
- @backstage/plugin-auth-node@0.5.6-next.1
|
|
47
|
+
- @backstage/plugin-events-node@0.4.7-next.1
|
|
48
|
+
- @backstage/integration-aws-node@0.1.15-next.0
|
|
49
|
+
- @backstage/plugin-permission-node@0.8.7-next.1
|
|
50
|
+
- @backstage/backend-dev-utils@0.1.5
|
|
51
|
+
- @backstage/cli-common@0.1.15
|
|
52
|
+
- @backstage/integration@1.16.1-next.0
|
|
53
|
+
|
|
3
54
|
## 0.7.0-next.0
|
|
4
55
|
|
|
5
56
|
### Minor Changes
|
|
@@ -74,29 +74,8 @@ class GerritUrlReader {
|
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
async readTree(url, options) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
response = await fetch__default.default(apiUrl, {
|
|
81
|
-
method: "GET",
|
|
82
|
-
...integration.getGerritRequestOptions(this.integration.config)
|
|
83
|
-
});
|
|
84
|
-
} catch (e) {
|
|
85
|
-
throw new Error(`Unable to read branch state ${url}, ${e}`);
|
|
86
|
-
}
|
|
87
|
-
if (response.status === 404) {
|
|
88
|
-
throw new errors.NotFoundError(`Not found: ${url}`);
|
|
89
|
-
}
|
|
90
|
-
if (!response.ok) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`${url} could not be read as ${apiUrl}, ${response.status} ${response.statusText}`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
const branchInfo = await integration.parseGerritJsonResponse(response);
|
|
96
|
-
if (options?.etag === branchInfo.revision) {
|
|
97
|
-
throw new errors.NotModifiedError();
|
|
98
|
-
}
|
|
99
|
-
return this.readTreeFromGitiles(url, branchInfo.revision, options);
|
|
77
|
+
const urlRevision = await this.getRevisionForUrl(url, options);
|
|
78
|
+
return this.readTreeFromGitiles(url, urlRevision, options);
|
|
100
79
|
}
|
|
101
80
|
async search() {
|
|
102
81
|
throw new Error("GerritReader does not implement search");
|
|
@@ -106,16 +85,10 @@ class GerritUrlReader {
|
|
|
106
85
|
return `gerrit{host=${host},authed=${Boolean(password)}}`;
|
|
107
86
|
}
|
|
108
87
|
async readTreeFromGitiles(url, revision, options) {
|
|
109
|
-
const
|
|
88
|
+
const archiveUrl = integration.buildGerritGitilesArchiveUrlFromLocation(
|
|
110
89
|
this.integration.config,
|
|
111
90
|
url
|
|
112
91
|
);
|
|
113
|
-
const archiveUrl = integration.buildGerritGitilesArchiveUrl(
|
|
114
|
-
this.integration.config,
|
|
115
|
-
project,
|
|
116
|
-
branch,
|
|
117
|
-
filePath
|
|
118
|
-
);
|
|
119
92
|
const archiveResponse = await fetch__default.default(archiveUrl, {
|
|
120
93
|
...integration.getGerritRequestOptions(this.integration.config),
|
|
121
94
|
// TODO(freben): The signal cast is there because pre-3.x versions of
|
|
@@ -141,6 +114,33 @@ class GerritUrlReader {
|
|
|
141
114
|
stripFirstDirectory: false
|
|
142
115
|
});
|
|
143
116
|
}
|
|
117
|
+
async getRevisionForUrl(url, options) {
|
|
118
|
+
const { ref, refType } = integration.parseGitilesUrlRef(this.integration.config, url);
|
|
119
|
+
if (refType === "sha") {
|
|
120
|
+
if (options?.etag === ref) {
|
|
121
|
+
throw new errors.NotModifiedError();
|
|
122
|
+
}
|
|
123
|
+
return ref;
|
|
124
|
+
}
|
|
125
|
+
const apiUrl = integration.getGerritBranchApiUrl(this.integration.config, url);
|
|
126
|
+
let response;
|
|
127
|
+
try {
|
|
128
|
+
response = await fetch__default.default(apiUrl, {
|
|
129
|
+
method: "GET",
|
|
130
|
+
...integration.getGerritRequestOptions(this.integration.config)
|
|
131
|
+
});
|
|
132
|
+
} catch (e) {
|
|
133
|
+
throw new Error(`Unable to read branch state ${url}, ${e}`);
|
|
134
|
+
}
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw await errors.ResponseError.fromResponse(response);
|
|
137
|
+
}
|
|
138
|
+
const branchInfo = await integration.parseGerritJsonResponse(response);
|
|
139
|
+
if (options?.etag === branchInfo.revision) {
|
|
140
|
+
throw new errors.NotModifiedError();
|
|
141
|
+
}
|
|
142
|
+
return branchInfo.revision;
|
|
143
|
+
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
exports.GerritUrlReader = GerritUrlReader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GerritUrlReader.cjs.js","sources":["../../../../src/entrypoints/urlReader/lib/GerritUrlReader.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n UrlReaderService,\n UrlReaderServiceReadTreeOptions,\n UrlReaderServiceReadTreeResponse,\n UrlReaderServiceReadUrlOptions,\n UrlReaderServiceReadUrlResponse,\n UrlReaderServiceSearchResponse,\n} from '@backstage/backend-plugin-api';\nimport { Base64Decode } from 'base64-stream';\nimport fetch, { Response } from 'node-fetch';\nimport { Readable } from 'stream';\nimport {\n GerritIntegration,\n ScmIntegrations,\n buildGerritGitilesArchiveUrl,\n getGerritBranchApiUrl,\n getGerritFileContentsApiUrl,\n getGerritRequestOptions,\n parseGerritGitilesUrl,\n parseGerritJsonResponse,\n} from '@backstage/integration';\nimport { NotFoundError, NotModifiedError } from '@backstage/errors';\nimport { ReadTreeResponseFactory, ReaderFactory } from './types';\n\n/**\n * Implements a {@link @backstage/backend-plugin-api#UrlReaderService} for files in Gerrit.\n *\n * @remarks\n * To be able to link to Git contents for Gerrit providers in a user friendly\n * way we are depending on that there is a Gitiles installation somewhere\n * that we can link to. It is perfectly possible to integrate Gerrit with\n * Backstage without Gitiles since all API calls goes directly to Gerrit.\n * However if Gitiles is configured, readTree will use it to fetch\n * an archive instead of cloning the repository.\n *\n * The \"host\" variable in the config is the Gerrit host. The address where\n * Gitiles is installed may be on the same host but it could be on a\n * separate host. For example a Gerrit instance could be hosted on\n * \"gerrit-review.company.com\" but the repos could be browsable on a separate\n * host, e.g. \"gerrit.company.com\" and the human readable URL would then\n * not point to the API host.\n *\n * @public\n */\nexport class GerritUrlReader implements UrlReaderService {\n static factory: ReaderFactory = ({ config, treeResponseFactory }) => {\n const integrations = ScmIntegrations.fromConfig(config);\n if (!integrations.gerrit) {\n return [];\n }\n return integrations.gerrit.list().map(integration => {\n const reader = new GerritUrlReader(integration, { treeResponseFactory });\n const predicate = (url: URL) => {\n const gitilesUrl = new URL(integration.config.gitilesBaseUrl!);\n // If gitilesUrl is not specified it will default to\n // \"integration.config.host\".\n return url.host === gitilesUrl.host;\n };\n return { reader, predicate };\n });\n };\n\n constructor(\n private readonly integration: GerritIntegration,\n private readonly deps: { treeResponseFactory: ReadTreeResponseFactory },\n ) {}\n\n async read(url: string): Promise<Buffer> {\n const response = await this.readUrl(url);\n return response.buffer();\n }\n\n async readUrl(\n url: string,\n options?: UrlReaderServiceReadUrlOptions,\n ): Promise<UrlReaderServiceReadUrlResponse> {\n const apiUrl = getGerritFileContentsApiUrl(this.integration.config, url);\n let response: Response;\n try {\n response = await fetch(apiUrl, {\n method: 'GET',\n ...getGerritRequestOptions(this.integration.config),\n // TODO(freben): The signal cast is there because pre-3.x versions of\n // node-fetch have a very slightly deviating AbortSignal type signature.\n // The difference does not affect us in practice however. The cast can\n // be removed after we support ESM for CLI dependencies and migrate to\n // version 3 of node-fetch.\n // https://github.com/backstage/backstage/issues/8242\n signal: options?.signal as any,\n });\n } catch (e) {\n throw new Error(`Unable to read gerrit file ${url}, ${e}`);\n }\n\n if (response.ok) {\n let responseBody: string;\n return {\n buffer: async () => {\n if (responseBody === undefined) {\n responseBody = await response.text();\n }\n return Buffer.from(responseBody, 'base64');\n },\n stream: () => {\n const readable = Readable.from(response.body);\n return readable.pipe(new Base64Decode());\n },\n };\n }\n if (response.status === 404) {\n throw new NotFoundError(`File ${url} not found.`);\n }\n throw new Error(\n `${url} could not be read as ${apiUrl}, ${response.status} ${response.statusText}`,\n );\n }\n\n async readTree(\n url: string,\n options?: UrlReaderServiceReadTreeOptions,\n ): Promise<UrlReaderServiceReadTreeResponse> {\n const apiUrl = getGerritBranchApiUrl(this.integration.config, url);\n let response: Response;\n try {\n response = await fetch(apiUrl, {\n method: 'GET',\n ...getGerritRequestOptions(this.integration.config),\n });\n } catch (e) {\n throw new Error(`Unable to read branch state ${url}, ${e}`);\n }\n\n if (response.status === 404) {\n throw new NotFoundError(`Not found: ${url}`);\n }\n\n if (!response.ok) {\n throw new Error(\n `${url} could not be read as ${apiUrl}, ${response.status} ${response.statusText}`,\n );\n }\n const branchInfo = (await parseGerritJsonResponse(response as any)) as {\n revision: string;\n };\n if (options?.etag === branchInfo.revision) {\n throw new NotModifiedError();\n }\n\n return this.readTreeFromGitiles(url, branchInfo.revision, options);\n }\n\n async search(): Promise<UrlReaderServiceSearchResponse> {\n throw new Error('GerritReader does not implement search');\n }\n\n toString() {\n const { host, password } = this.integration.config;\n return `gerrit{host=${host},authed=${Boolean(password)}}`;\n }\n\n private async readTreeFromGitiles(\n url: string,\n revision: string,\n options?: UrlReaderServiceReadTreeOptions,\n ) {\n const { branch, filePath, project } = parseGerritGitilesUrl(\n this.integration.config,\n url,\n );\n const archiveUrl = buildGerritGitilesArchiveUrl(\n this.integration.config,\n project,\n branch,\n filePath,\n );\n const archiveResponse = await fetch(archiveUrl, {\n ...getGerritRequestOptions(this.integration.config),\n // TODO(freben): The signal cast is there because pre-3.x versions of\n // node-fetch have a very slightly deviating AbortSignal type signature.\n // The difference does not affect us in practice however. The cast can\n // be removed after we support ESM for CLI dependencies and migrate to\n // version 3 of node-fetch.\n // https://github.com/backstage/backstage/issues/8242\n signal: options?.signal as any,\n });\n\n if (archiveResponse.status === 404) {\n throw new NotFoundError(`Not found: ${archiveUrl}`);\n }\n\n if (!archiveResponse.ok) {\n throw new Error(\n `${url} could not be read as ${archiveUrl}, ${archiveResponse.status} ${archiveResponse.statusText}`,\n );\n }\n\n return await this.deps.treeResponseFactory.fromTarArchive({\n stream: archiveResponse.body as unknown as Readable,\n etag: revision,\n filter: options?.filter,\n stripFirstDirectory: false,\n });\n }\n}\n"],"names":["ScmIntegrations","getGerritFileContentsApiUrl","fetch","getGerritRequestOptions","Readable","Base64Decode","NotFoundError","getGerritBranchApiUrl","parseGerritJsonResponse","NotModifiedError","parseGerritGitilesUrl","buildGerritGitilesArchiveUrl"],"mappings":";;;;;;;;;;;;AA4DO,MAAM,eAA4C,CAAA;AAAA,EAkBvD,WAAA,CACmB,aACA,IACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA;AAChB,EApBH,OAAO,OAAyB,GAAA,CAAC,EAAE,MAAA,EAAQ,qBAA0B,KAAA;AACnE,IAAM,MAAA,YAAA,GAAeA,2BAA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MAAA;AAAA,MACjB,OAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AACA,IAAM,MAAA,eAAA,GAAkB,MAAMT,sBAAA,CAAM,UAAY,EAAA;AAAA,MAC9C,GAAGC,mCAAA,CAAwB,IAAK,CAAA,WAAA,CAAY,MAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOlD,QAAQ,OAAS,EAAA;AAAA,KAClB,CAAA;AAED,IAAI,IAAA,eAAA,CAAgB,WAAW,GAAK,EAAA;AAClC,MAAA,MAAM,IAAIG,oBAAA,CAAc,CAAc,WAAA,EAAA,UAAU,CAAE,CAAA,CAAA;AAAA;AAGpD,IAAI,IAAA,CAAC,gBAAgB,EAAI,EAAA;AACvB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,EAAG,GAAG,CAAyB,sBAAA,EAAA,UAAU,KAAK,eAAgB,CAAA,MAAM,CAAI,CAAA,EAAA,eAAA,CAAgB,UAAU,CAAA;AAAA,OACpG;AAAA;AAGF,IAAA,OAAO,MAAM,IAAA,CAAK,IAAK,CAAA,mBAAA,CAAoB,cAAe,CAAA;AAAA,MACxD,QAAQ,eAAgB,CAAA,IAAA;AAAA,MACxB,IAAM,EAAA,QAAA;AAAA,MACN,QAAQ,OAAS,EAAA,MAAA;AAAA,MACjB,mBAAqB,EAAA;AAAA,KACtB,CAAA;AAAA;AAEL;;;;"}
|
|
1
|
+
{"version":3,"file":"GerritUrlReader.cjs.js","sources":["../../../../src/entrypoints/urlReader/lib/GerritUrlReader.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n UrlReaderService,\n UrlReaderServiceReadTreeOptions,\n UrlReaderServiceReadTreeResponse,\n UrlReaderServiceReadUrlOptions,\n UrlReaderServiceReadUrlResponse,\n UrlReaderServiceSearchResponse,\n} from '@backstage/backend-plugin-api';\nimport { Base64Decode } from 'base64-stream';\nimport fetch, { Response } from 'node-fetch';\nimport { Readable } from 'stream';\nimport {\n GerritIntegration,\n ScmIntegrations,\n buildGerritGitilesArchiveUrlFromLocation,\n getGerritBranchApiUrl,\n getGerritFileContentsApiUrl,\n getGerritRequestOptions,\n parseGerritJsonResponse,\n parseGitilesUrlRef,\n} from '@backstage/integration';\nimport {\n NotFoundError,\n NotModifiedError,\n ResponseError,\n} from '@backstage/errors';\nimport { ReadTreeResponseFactory, ReaderFactory } from './types';\n\n/**\n * Implements a {@link @backstage/backend-plugin-api#UrlReaderService} for files in Gerrit.\n *\n * @remarks\n * To be able to link to Git contents for Gerrit providers in a user friendly\n * way we are depending on that there is a Gitiles installation somewhere\n * that we can link to. It is perfectly possible to integrate Gerrit with\n * Backstage without Gitiles since all API calls goes directly to Gerrit.\n * However if Gitiles is configured, readTree will use it to fetch\n * an archive instead of cloning the repository.\n *\n * The \"host\" variable in the config is the Gerrit host. The address where\n * Gitiles is installed may be on the same host but it could be on a\n * separate host. For example a Gerrit instance could be hosted on\n * \"gerrit-review.company.com\" but the repos could be browsable on a separate\n * host, e.g. \"gerrit.company.com\" and the human readable URL would then\n * not point to the API host.\n *\n * @public\n */\nexport class GerritUrlReader implements UrlReaderService {\n static factory: ReaderFactory = ({ config, treeResponseFactory }) => {\n const integrations = ScmIntegrations.fromConfig(config);\n if (!integrations.gerrit) {\n return [];\n }\n return integrations.gerrit.list().map(integration => {\n const reader = new GerritUrlReader(integration, { treeResponseFactory });\n const predicate = (url: URL) => {\n const gitilesUrl = new URL(integration.config.gitilesBaseUrl!);\n // If gitilesUrl is not specified it will default to\n // \"integration.config.host\".\n return url.host === gitilesUrl.host;\n };\n return { reader, predicate };\n });\n };\n\n constructor(\n private readonly integration: GerritIntegration,\n private readonly deps: { treeResponseFactory: ReadTreeResponseFactory },\n ) {}\n\n async read(url: string): Promise<Buffer> {\n const response = await this.readUrl(url);\n return response.buffer();\n }\n\n async readUrl(\n url: string,\n options?: UrlReaderServiceReadUrlOptions,\n ): Promise<UrlReaderServiceReadUrlResponse> {\n const apiUrl = getGerritFileContentsApiUrl(this.integration.config, url);\n let response: Response;\n try {\n response = await fetch(apiUrl, {\n method: 'GET',\n ...getGerritRequestOptions(this.integration.config),\n // TODO(freben): The signal cast is there because pre-3.x versions of\n // node-fetch have a very slightly deviating AbortSignal type signature.\n // The difference does not affect us in practice however. The cast can\n // be removed after we support ESM for CLI dependencies and migrate to\n // version 3 of node-fetch.\n // https://github.com/backstage/backstage/issues/8242\n signal: options?.signal as any,\n });\n } catch (e) {\n throw new Error(`Unable to read gerrit file ${url}, ${e}`);\n }\n\n if (response.ok) {\n let responseBody: string;\n return {\n buffer: async () => {\n if (responseBody === undefined) {\n responseBody = await response.text();\n }\n return Buffer.from(responseBody, 'base64');\n },\n stream: () => {\n const readable = Readable.from(response.body);\n return readable.pipe(new Base64Decode());\n },\n };\n }\n if (response.status === 404) {\n throw new NotFoundError(`File ${url} not found.`);\n }\n throw new Error(\n `${url} could not be read as ${apiUrl}, ${response.status} ${response.statusText}`,\n );\n }\n\n async readTree(\n url: string,\n options?: UrlReaderServiceReadTreeOptions,\n ): Promise<UrlReaderServiceReadTreeResponse> {\n const urlRevision = await this.getRevisionForUrl(url, options);\n\n return this.readTreeFromGitiles(url, urlRevision, options);\n }\n\n async search(): Promise<UrlReaderServiceSearchResponse> {\n throw new Error('GerritReader does not implement search');\n }\n\n toString() {\n const { host, password } = this.integration.config;\n return `gerrit{host=${host},authed=${Boolean(password)}}`;\n }\n\n private async readTreeFromGitiles(\n url: string,\n revision: string,\n options?: UrlReaderServiceReadTreeOptions,\n ) {\n const archiveUrl = buildGerritGitilesArchiveUrlFromLocation(\n this.integration.config,\n url,\n );\n const archiveResponse = await fetch(archiveUrl, {\n ...getGerritRequestOptions(this.integration.config),\n // TODO(freben): The signal cast is there because pre-3.x versions of\n // node-fetch have a very slightly deviating AbortSignal type signature.\n // The difference does not affect us in practice however. The cast can\n // be removed after we support ESM for CLI dependencies and migrate to\n // version 3 of node-fetch.\n // https://github.com/backstage/backstage/issues/8242\n signal: options?.signal as any,\n });\n\n if (archiveResponse.status === 404) {\n throw new NotFoundError(`Not found: ${archiveUrl}`);\n }\n\n if (!archiveResponse.ok) {\n throw new Error(\n `${url} could not be read as ${archiveUrl}, ${archiveResponse.status} ${archiveResponse.statusText}`,\n );\n }\n\n return await this.deps.treeResponseFactory.fromTarArchive({\n stream: archiveResponse.body as unknown as Readable,\n etag: revision,\n filter: options?.filter,\n stripFirstDirectory: false,\n });\n }\n\n private async getRevisionForUrl(\n url: string,\n options?: UrlReaderServiceReadTreeOptions,\n ): Promise<string> {\n const { ref, refType } = parseGitilesUrlRef(this.integration.config, url);\n // The url points to a static revision.\n if (refType === 'sha') {\n if (options?.etag === ref) {\n throw new NotModifiedError();\n }\n return ref;\n }\n\n const apiUrl = getGerritBranchApiUrl(this.integration.config, url);\n let response: Response;\n try {\n response = await fetch(apiUrl, {\n method: 'GET',\n ...getGerritRequestOptions(this.integration.config),\n });\n } catch (e) {\n throw new Error(`Unable to read branch state ${url}, ${e}`);\n }\n\n if (!response.ok) {\n throw await ResponseError.fromResponse(response);\n }\n\n const branchInfo = (await parseGerritJsonResponse(response as any)) as {\n revision: string;\n };\n if (options?.etag === branchInfo.revision) {\n throw new NotModifiedError();\n }\n return branchInfo.revision;\n }\n}\n"],"names":["ScmIntegrations","getGerritFileContentsApiUrl","fetch","getGerritRequestOptions","Readable","Base64Decode","NotFoundError","buildGerritGitilesArchiveUrlFromLocation","parseGitilesUrlRef","NotModifiedError","getGerritBranchApiUrl","ResponseError","parseGerritJsonResponse"],"mappings":";;;;;;;;;;;;AAgEO,MAA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|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var name = "@backstage/backend-defaults";
|
|
6
|
-
var version = "0.7.0
|
|
6
|
+
var version = "0.7.0";
|
|
7
7
|
var description = "Backend defaults used by Backstage backend apps";
|
|
8
8
|
var backstage = {
|
|
9
9
|
role: "node-library"
|
package/dist/urlReader.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-defaults",
|
|
3
|
-
"version": "0.7.0
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Backend defaults used by Backstage backend apps",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -193,20 +193,20 @@
|
|
|
193
193
|
"@aws-sdk/types": "^3.347.0",
|
|
194
194
|
"@azure/identity": "^4.0.0",
|
|
195
195
|
"@azure/storage-blob": "^12.5.0",
|
|
196
|
-
"@backstage/backend-app-api": "1.1.1
|
|
197
|
-
"@backstage/backend-dev-utils": "0.1.5",
|
|
198
|
-
"@backstage/backend-plugin-api": "1.1.1
|
|
199
|
-
"@backstage/cli-common": "0.1.15",
|
|
200
|
-
"@backstage/cli-node": "0.2.
|
|
201
|
-
"@backstage/config": "1.3.
|
|
202
|
-
"@backstage/config-loader": "1.9.5
|
|
203
|
-
"@backstage/errors": "1.2.
|
|
204
|
-
"@backstage/integration": "1.16.
|
|
205
|
-
"@backstage/integration-aws-node": "0.1.
|
|
206
|
-
"@backstage/plugin-auth-node": "0.5.6
|
|
207
|
-
"@backstage/plugin-events-node": "0.4.7
|
|
208
|
-
"@backstage/plugin-permission-node": "0.8.7
|
|
209
|
-
"@backstage/types": "1.2.
|
|
196
|
+
"@backstage/backend-app-api": "^1.1.1",
|
|
197
|
+
"@backstage/backend-dev-utils": "^0.1.5",
|
|
198
|
+
"@backstage/backend-plugin-api": "^1.1.1",
|
|
199
|
+
"@backstage/cli-common": "^0.1.15",
|
|
200
|
+
"@backstage/cli-node": "^0.2.12",
|
|
201
|
+
"@backstage/config": "^1.3.2",
|
|
202
|
+
"@backstage/config-loader": "^1.9.5",
|
|
203
|
+
"@backstage/errors": "^1.2.7",
|
|
204
|
+
"@backstage/integration": "^1.16.1",
|
|
205
|
+
"@backstage/integration-aws-node": "^0.1.15",
|
|
206
|
+
"@backstage/plugin-auth-node": "^0.5.6",
|
|
207
|
+
"@backstage/plugin-events-node": "^0.4.7",
|
|
208
|
+
"@backstage/plugin-permission-node": "^0.8.7",
|
|
209
|
+
"@backstage/types": "^1.2.1",
|
|
210
210
|
"@google-cloud/storage": "^7.0.0",
|
|
211
211
|
"@keyv/memcache": "^2.0.1",
|
|
212
212
|
"@keyv/redis": "^4.0.1",
|
|
@@ -267,9 +267,9 @@
|
|
|
267
267
|
},
|
|
268
268
|
"devDependencies": {
|
|
269
269
|
"@aws-sdk/util-stream-node": "^3.350.0",
|
|
270
|
-
"@backstage/backend-plugin-api": "1.1.1
|
|
271
|
-
"@backstage/backend-test-utils": "1.2.1
|
|
272
|
-
"@backstage/cli": "0.29.5
|
|
270
|
+
"@backstage/backend-plugin-api": "^1.1.1",
|
|
271
|
+
"@backstage/backend-test-utils": "^1.2.1",
|
|
272
|
+
"@backstage/cli": "^0.29.5",
|
|
273
273
|
"@google-cloud/cloud-sql-connector": "^1.4.0",
|
|
274
274
|
"@types/archiver": "^6.0.0",
|
|
275
275
|
"@types/base64-stream": "^1.0.2",
|