@backstage/backend-defaults 0.9.0 → 0.10.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 +48 -0
- package/config.d.ts +71 -0
- package/dist/cache.d.ts +2 -1
- package/dist/entrypoints/auth/DefaultAuthService.cjs.js.map +1 -1
- package/dist/entrypoints/cache/CacheManager.cjs.js +33 -3
- package/dist/entrypoints/cache/CacheManager.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/database/migrateBackendTasks.cjs.js +5 -4
- package/dist/entrypoints/scheduler/database/migrateBackendTasks.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/database/tables.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/DefaultSchedulerService.cjs.js +5 -2
- package/dist/entrypoints/scheduler/lib/DefaultSchedulerService.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/LocalTaskWorker.cjs.js +58 -10
- package/dist/entrypoints/scheduler/lib/LocalTaskWorker.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/PluginTaskSchedulerImpl.cjs.js +42 -5
- package/dist/entrypoints/scheduler/lib/PluginTaskSchedulerImpl.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/PluginTaskSchedulerJanitor.cjs.js +6 -2
- package/dist/entrypoints/scheduler/lib/PluginTaskSchedulerJanitor.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/TaskWorker.cjs.js +60 -10
- package/dist/entrypoints/scheduler/lib/TaskWorker.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/types.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/lib/util.cjs.js +16 -1
- package/dist/entrypoints/scheduler/lib/util.cjs.js.map +1 -1
- package/dist/entrypoints/scheduler/schedulerServiceFactory.cjs.js +17 -3
- package/dist/entrypoints/scheduler/schedulerServiceFactory.cjs.js.map +1 -1
- package/dist/entrypoints/urlReader/lib/GitlabUrlReader.cjs.js +11 -8
- package/dist/entrypoints/urlReader/lib/GitlabUrlReader.cjs.js.map +1 -1
- package/dist/package.json.cjs.js +2 -1
- package/dist/package.json.cjs.js.map +1 -1
- package/dist/scheduler.d.ts +4 -2
- package/migrations/scheduler/20250411000000_last_run.js +47 -0
- package/package.json +18 -17
|
@@ -37,7 +37,7 @@ class GitlabUrlReader {
|
|
|
37
37
|
async readUrl(url, options) {
|
|
38
38
|
const { etag, lastModifiedAfter, signal, token } = options ?? {};
|
|
39
39
|
const isArtifact = url.includes("/-/jobs/artifacts/");
|
|
40
|
-
const builtUrl = await this.getGitlabFetchUrl(url);
|
|
40
|
+
const builtUrl = await this.getGitlabFetchUrl(url, token);
|
|
41
41
|
let response;
|
|
42
42
|
try {
|
|
43
43
|
response = await fetch__default.default(builtUrl, {
|
|
@@ -242,20 +242,23 @@ class GitlabUrlReader {
|
|
|
242
242
|
const { host, token } = this.integration.config;
|
|
243
243
|
return `gitlab{host=${host},authed=${Boolean(token)}}`;
|
|
244
244
|
}
|
|
245
|
-
async getGitlabFetchUrl(target) {
|
|
245
|
+
async getGitlabFetchUrl(target, token) {
|
|
246
246
|
const targetUrl = new URL(target);
|
|
247
247
|
if (targetUrl.pathname.includes("/-/jobs/artifacts/")) {
|
|
248
|
-
return this.getGitlabArtifactFetchUrl(targetUrl).then(
|
|
248
|
+
return this.getGitlabArtifactFetchUrl(targetUrl, token).then(
|
|
249
249
|
(value) => value.toString()
|
|
250
250
|
);
|
|
251
251
|
}
|
|
252
|
-
return integration.getGitLabFileFetchUrl(target,
|
|
252
|
+
return integration.getGitLabFileFetchUrl(target, {
|
|
253
|
+
...this.integration.config,
|
|
254
|
+
...token && { token }
|
|
255
|
+
});
|
|
253
256
|
}
|
|
254
257
|
// convert urls of the form:
|
|
255
258
|
// https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>
|
|
256
259
|
// to urls of the form:
|
|
257
260
|
// https://example.com/api/v4/projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=<job_name>
|
|
258
|
-
async getGitlabArtifactFetchUrl(target) {
|
|
261
|
+
async getGitlabArtifactFetchUrl(target, token) {
|
|
259
262
|
if (!target.pathname.includes("/-/jobs/artifacts/")) {
|
|
260
263
|
throw new Error("Unable to process url as an GitLab artifact");
|
|
261
264
|
}
|
|
@@ -263,7 +266,7 @@ class GitlabUrlReader {
|
|
|
263
266
|
const [namespaceAndProject, ref] = target.pathname.split("/-/jobs/artifacts/");
|
|
264
267
|
const projectPath = new URL(target);
|
|
265
268
|
projectPath.pathname = namespaceAndProject;
|
|
266
|
-
const projectId = await this.resolveProjectToId(projectPath);
|
|
269
|
+
const projectId = await this.resolveProjectToId(projectPath, token);
|
|
267
270
|
const relativePath = integration.getGitLabIntegrationRelativePath(
|
|
268
271
|
this.integration.config
|
|
269
272
|
);
|
|
@@ -276,7 +279,7 @@ class GitlabUrlReader {
|
|
|
276
279
|
);
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
|
-
async resolveProjectToId(pathToProject) {
|
|
282
|
+
async resolveProjectToId(pathToProject, token) {
|
|
280
283
|
let project = pathToProject.pathname;
|
|
281
284
|
const relativePath = integration.getGitLabIntegrationRelativePath(
|
|
282
285
|
this.integration.config
|
|
@@ -287,7 +290,7 @@ class GitlabUrlReader {
|
|
|
287
290
|
project = project.replace(/^\//, "");
|
|
288
291
|
const result = await fetch__default.default(
|
|
289
292
|
`${pathToProject.origin}${relativePath}/api/v4/projects/${encodeURIComponent(project)}`,
|
|
290
|
-
integration.getGitLabRequestOptions(this.integration.config)
|
|
293
|
+
integration.getGitLabRequestOptions(this.integration.config, token)
|
|
291
294
|
);
|
|
292
295
|
const data = await result.json();
|
|
293
296
|
if (!result.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitlabUrlReader.cjs.js","sources":["../../../../src/entrypoints/urlReader/lib/GitlabUrlReader.ts"],"sourcesContent":["/*\n * Copyright 2020 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\n// NOTE(freben): Intentionally uses node-fetch because of https://github.com/backstage/backstage/issues/28190\nimport fetch, { Response } from 'node-fetch';\n\nimport {\n UrlReaderService,\n UrlReaderServiceReadTreeOptions,\n UrlReaderServiceReadTreeResponse,\n UrlReaderServiceReadUrlOptions,\n UrlReaderServiceReadUrlResponse,\n UrlReaderServiceSearchOptions,\n UrlReaderServiceSearchResponse,\n} from '@backstage/backend-plugin-api';\nimport {\n assertError,\n NotFoundError,\n NotModifiedError,\n} from '@backstage/errors';\nimport {\n GitLabIntegration,\n ScmIntegrations,\n getGitLabFileFetchUrl,\n getGitLabIntegrationRelativePath,\n getGitLabRequestOptions,\n} from '@backstage/integration';\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd, trimStart } from 'lodash';\nimport { Minimatch } from 'minimatch';\nimport { Readable } from 'stream';\nimport { ReadUrlResponseFactory } from './ReadUrlResponseFactory';\nimport { ReadTreeResponseFactory, ReaderFactory } from './types';\nimport { parseLastModified } from './util';\n\n/**\n * Implements a {@link @backstage/backend-plugin-api#UrlReaderService} for files on GitLab.\n *\n * @public\n */\nexport class GitlabUrlReader implements UrlReaderService {\n static factory: ReaderFactory = ({ config, treeResponseFactory }) => {\n const integrations = ScmIntegrations.fromConfig(config);\n return integrations.gitlab.list().map(integration => {\n const reader = new GitlabUrlReader(integration, {\n treeResponseFactory,\n });\n const predicate = (url: URL) => url.host === integration.config.host;\n return { reader, predicate };\n });\n };\n\n constructor(\n private readonly integration: GitLabIntegration,\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 { etag, lastModifiedAfter, signal, token } = options ?? {};\n const isArtifact = url.includes('/-/jobs/artifacts/');\n const builtUrl = await this.getGitlabFetchUrl(url);\n\n let response: Response;\n try {\n response = await fetch(builtUrl, {\n headers: {\n ...getGitLabRequestOptions(this.integration.config, token).headers,\n ...(etag && !isArtifact && { 'If-None-Match': etag }),\n ...(lastModifiedAfter &&\n !isArtifact && {\n 'If-Modified-Since': lastModifiedAfter.toUTCString(),\n }),\n },\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 be\n // 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 && { signal: signal as any }),\n });\n } catch (e) {\n throw new Error(`Unable to read ${url}, ${e}`);\n }\n\n if (response.status === 304) {\n throw new NotModifiedError();\n }\n\n if (response.ok) {\n return ReadUrlResponseFactory.fromNodeJSReadable(response.body, {\n etag: response.headers.get('ETag') ?? undefined,\n lastModifiedAt: parseLastModified(\n response.headers.get('Last-Modified'),\n ),\n });\n }\n\n const message = `${url} could not be read as ${builtUrl}, ${response.status} ${response.statusText}`;\n if (response.status === 404) {\n throw new NotFoundError(message);\n }\n throw new Error(message);\n }\n\n async readTree(\n url: string,\n options?: UrlReaderServiceReadTreeOptions,\n ): Promise<UrlReaderServiceReadTreeResponse> {\n const { etag, signal, token } = options ?? {};\n const { ref, full_name, filepath } = parseGitUrl(url);\n\n let repoFullName = full_name;\n\n const relativePath = getGitLabIntegrationRelativePath(\n this.integration.config,\n );\n\n // Considering self hosted gitlab with relative\n // assuming '/gitlab' is the relative path\n // from: /gitlab/repo/project\n // to: repo/project\n if (relativePath) {\n const rectifiedRelativePath = `${trimStart(relativePath, '/')}/`;\n repoFullName = full_name.replace(rectifiedRelativePath, '');\n }\n\n // Use GitLab API to get the default branch\n // encodeURIComponent is required for GitLab API\n // https://docs.gitlab.com/ee/api/README.html#namespaced-path-encoding\n const projectGitlabResponse = await fetch(\n new URL(\n `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent(\n repoFullName,\n )}`,\n ).toString(),\n getGitLabRequestOptions(this.integration.config, token),\n );\n if (!projectGitlabResponse.ok) {\n const msg = `Failed to read tree from ${url}, ${projectGitlabResponse.status} ${projectGitlabResponse.statusText}`;\n if (projectGitlabResponse.status === 404) {\n throw new NotFoundError(msg);\n }\n throw new Error(msg);\n }\n const projectGitlabResponseJson = await projectGitlabResponse.json();\n\n // ref is an empty string if no branch is set in provided url to readTree.\n const branch = ref || projectGitlabResponseJson.default_branch;\n\n // Fetch the latest commit that modifies the filepath in the provided or default branch\n // to compare against the provided sha.\n const commitsReqParams = new URLSearchParams();\n commitsReqParams.set('ref_name', branch);\n if (!!filepath) {\n commitsReqParams.set('path', filepath);\n }\n const commitsGitlabResponse = await fetch(\n new URL(\n `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent(\n repoFullName,\n )}/repository/commits?${commitsReqParams.toString()}`,\n ).toString(),\n {\n ...getGitLabRequestOptions(this.integration.config, token),\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 && { signal: signal as any }),\n },\n );\n if (!commitsGitlabResponse.ok) {\n const message = `Failed to read tree (branch) from ${url}, ${commitsGitlabResponse.status} ${commitsGitlabResponse.statusText}`;\n if (commitsGitlabResponse.status === 404) {\n throw new NotFoundError(message);\n }\n throw new Error(message);\n }\n\n const commitSha = (await commitsGitlabResponse.json())[0]?.id ?? '';\n if (etag && etag === commitSha) {\n throw new NotModifiedError();\n }\n\n const archiveReqParams = new URLSearchParams();\n archiveReqParams.set('sha', branch);\n if (!!filepath) {\n archiveReqParams.set('path', filepath);\n }\n // https://docs.gitlab.com/ee/api/repositories.html#get-file-archive\n const archiveGitLabResponse = await fetch(\n `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent(\n repoFullName,\n )}/repository/archive?${archiveReqParams.toString()}`,\n {\n ...getGitLabRequestOptions(this.integration.config, token),\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 && { signal: signal as any }),\n },\n );\n if (!archiveGitLabResponse.ok) {\n const message = `Failed to read tree (archive) from ${url}, ${archiveGitLabResponse.status} ${archiveGitLabResponse.statusText}`;\n if (archiveGitLabResponse.status === 404) {\n throw new NotFoundError(message);\n }\n throw new Error(message);\n }\n\n return await this.deps.treeResponseFactory.fromTarArchive({\n stream: Readable.from(archiveGitLabResponse.body),\n subpath: filepath,\n etag: commitSha,\n filter: options?.filter,\n });\n }\n\n async search(\n url: string,\n options?: UrlReaderServiceSearchOptions,\n ): Promise<UrlReaderServiceSearchResponse> {\n const { filepath } = parseGitUrl(url);\n\n // If it's a direct URL we use readUrl instead\n if (!filepath?.match(/[*?]/)) {\n try {\n const data = await this.readUrl(url, options);\n\n return {\n files: [\n {\n url: url,\n content: data.buffer,\n lastModifiedAt: data.lastModifiedAt,\n },\n ],\n etag: data.etag ?? '',\n };\n } catch (error) {\n assertError(error);\n if (error.name === 'NotFoundError') {\n return {\n files: [],\n etag: '',\n };\n }\n throw error;\n }\n }\n\n const staticPart = this.getStaticPart(filepath);\n const matcher = new Minimatch(filepath);\n const treeUrl = trimEnd(url.replace(filepath, staticPart), `/`);\n const pathPrefix = staticPart ? `${staticPart}/` : '';\n const tree = await this.readTree(treeUrl, {\n etag: options?.etag,\n signal: options?.signal,\n filter: path => matcher.match(`${pathPrefix}${path}`),\n });\n\n const files = await tree.files();\n return {\n etag: tree.etag,\n files: files.map(file => ({\n url: this.integration.resolveUrl({\n url: `/${pathPrefix}${file.path}`,\n base: url,\n }),\n content: file.content,\n lastModifiedAt: file.lastModifiedAt,\n })),\n };\n }\n\n /**\n * This function splits the input globPattern string into segments using the path separator /. It then iterates over\n * the segments from the end of the array towards the beginning, checking if the concatenated string up to that\n * segment matches the original globPattern using the minimatch function. If a match is found, it continues iterating.\n * If no match is found, it returns the concatenated string up to the current segment, which is the static part of the\n * glob pattern.\n *\n * E.g. `catalog/foo/*.yaml` will return `catalog/foo`.\n *\n * @param globPattern - the glob pattern\n */\n private getStaticPart(globPattern: string) {\n const segments = globPattern.split('/');\n let i = segments.length;\n while (\n i > 0 &&\n new Minimatch(segments.slice(0, i).join('/')).match(globPattern)\n ) {\n i--;\n }\n return segments.slice(0, i).join('/');\n }\n\n toString() {\n const { host, token } = this.integration.config;\n return `gitlab{host=${host},authed=${Boolean(token)}}`;\n }\n\n private async getGitlabFetchUrl(target: string): Promise<string> {\n // If the target is for a job artifact then go down that path\n const targetUrl = new URL(target);\n if (targetUrl.pathname.includes('/-/jobs/artifacts/')) {\n return this.getGitlabArtifactFetchUrl(targetUrl).then(value =>\n value.toString(),\n );\n }\n // Default to the old behavior of assuming the url is for a file\n return getGitLabFileFetchUrl(target, this.integration.config);\n }\n\n // convert urls of the form:\n // https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>\n // to urls of the form:\n // https://example.com/api/v4/projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=<job_name>\n private async getGitlabArtifactFetchUrl(target: URL): Promise<URL> {\n if (!target.pathname.includes('/-/jobs/artifacts/')) {\n throw new Error('Unable to process url as an GitLab artifact');\n }\n try {\n const [namespaceAndProject, ref] =\n target.pathname.split('/-/jobs/artifacts/');\n const projectPath = new URL(target);\n projectPath.pathname = namespaceAndProject;\n const projectId = await this.resolveProjectToId(projectPath);\n const relativePath = getGitLabIntegrationRelativePath(\n this.integration.config,\n );\n const newUrl = new URL(target);\n newUrl.pathname = `${relativePath}/api/v4/projects/${projectId}/jobs/artifacts/${ref}`;\n return newUrl;\n } catch (e) {\n throw new Error(\n `Unable to translate GitLab artifact URL: ${target}, ${e}`,\n );\n }\n }\n\n private async resolveProjectToId(pathToProject: URL): Promise<number> {\n let project = pathToProject.pathname;\n // Check relative path exist and remove it if so\n const relativePath = getGitLabIntegrationRelativePath(\n this.integration.config,\n );\n if (relativePath) {\n project = project.replace(relativePath, '');\n }\n // Trim an initial / if it exists\n project = project.replace(/^\\//, '');\n const result = await fetch(\n `${\n pathToProject.origin\n }${relativePath}/api/v4/projects/${encodeURIComponent(project)}`,\n getGitLabRequestOptions(this.integration.config),\n );\n const data = await result.json();\n if (!result.ok) {\n throw new Error(`Gitlab error: ${data.error}, ${data.error_description}`);\n }\n return Number(data.id);\n }\n}\n"],"names":["ScmIntegrations","fetch","getGitLabRequestOptions","NotModifiedError","ReadUrlResponseFactory","parseLastModified","NotFoundError","parseGitUrl","getGitLabIntegrationRelativePath","trimStart","Readable","assertError","Minimatch","trimEnd","getGitLabFileFetchUrl"],"mappings":";;;;;;;;;;;;;;;;;AAqDO,MAAM,eAA4C,CAAA;AAAA,EAYvD,WAAA,CACmB,aACA,IACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA;AAChB,EAdH,OAAO,OAAyB,GAAA,CAAC,EAAE,MAAA,EAAQ,qBAA0B,KAAA;AACnE,IAAM,MAAA,YAAA,GAAeA,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AACtD,IAAA,OAAO,YAAa,CAAA,MAAA,CAAO,IAAK,EAAA,CAAE,IAAI,CAAe,WAAA,KAAA;AACnD,MAAM,MAAA,MAAA,GAAS,IAAI,eAAA,CAAgB,WAAa,EAAA;AAAA,QAC9C;AAAA,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,CAAA;AAAA,MAC9DC,mCAAA,CAAwB,IAAK,CAAA,WAAA,CAAY,MAAM;AAAA,KACjD;AACA,IAAM,MAAA,IAAA,GAAO,MAAM,MAAA,CAAO,IAAK,EAAA;AAC/B,IAAI,IAAA,CAAC,OAAO,EAAI,EAAA;AACd,MAAM,MAAA,IAAI,MAAM,CAAiB,cAAA,EAAA,IAAA,CAAK,KAAK,CAAK,EAAA,EAAA,IAAA,CAAK,iBAAiB,CAAE,CAAA,CAAA;AAAA;AAE1E,IAAO,OAAA,MAAA,CAAO,KAAK,EAAE,CAAA;AAAA;AAEzB;;;;"}
|
|
1
|
+
{"version":3,"file":"GitlabUrlReader.cjs.js","sources":["../../../../src/entrypoints/urlReader/lib/GitlabUrlReader.ts"],"sourcesContent":["/*\n * Copyright 2020 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\n// NOTE(freben): Intentionally uses node-fetch because of https://github.com/backstage/backstage/issues/28190\nimport fetch, { Response } from 'node-fetch';\n\nimport {\n UrlReaderService,\n UrlReaderServiceReadTreeOptions,\n UrlReaderServiceReadTreeResponse,\n UrlReaderServiceReadUrlOptions,\n UrlReaderServiceReadUrlResponse,\n UrlReaderServiceSearchOptions,\n UrlReaderServiceSearchResponse,\n} from '@backstage/backend-plugin-api';\nimport {\n assertError,\n NotFoundError,\n NotModifiedError,\n} from '@backstage/errors';\nimport {\n getGitLabFileFetchUrl,\n getGitLabIntegrationRelativePath,\n getGitLabRequestOptions,\n GitLabIntegration,\n ScmIntegrations,\n} from '@backstage/integration';\nimport parseGitUrl from 'git-url-parse';\nimport { trimEnd, trimStart } from 'lodash';\nimport { Minimatch } from 'minimatch';\nimport { Readable } from 'stream';\nimport { ReadUrlResponseFactory } from './ReadUrlResponseFactory';\nimport { ReaderFactory, ReadTreeResponseFactory } from './types';\nimport { parseLastModified } from './util';\n\n/**\n * Implements a {@link @backstage/backend-plugin-api#UrlReaderService} for files on GitLab.\n *\n * @public\n */\nexport class GitlabUrlReader implements UrlReaderService {\n static factory: ReaderFactory = ({ config, treeResponseFactory }) => {\n const integrations = ScmIntegrations.fromConfig(config);\n return integrations.gitlab.list().map(integration => {\n const reader = new GitlabUrlReader(integration, {\n treeResponseFactory,\n });\n const predicate = (url: URL) => url.host === integration.config.host;\n return { reader, predicate };\n });\n };\n\n constructor(\n private readonly integration: GitLabIntegration,\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 { etag, lastModifiedAfter, signal, token } = options ?? {};\n const isArtifact = url.includes('/-/jobs/artifacts/');\n const builtUrl = await this.getGitlabFetchUrl(url, token);\n\n let response: Response;\n try {\n response = await fetch(builtUrl, {\n headers: {\n ...getGitLabRequestOptions(this.integration.config, token).headers,\n ...(etag && !isArtifact && { 'If-None-Match': etag }),\n ...(lastModifiedAfter &&\n !isArtifact && {\n 'If-Modified-Since': lastModifiedAfter.toUTCString(),\n }),\n },\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 be\n // 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 && { signal: signal as any }),\n });\n } catch (e) {\n throw new Error(`Unable to read ${url}, ${e}`);\n }\n\n if (response.status === 304) {\n throw new NotModifiedError();\n }\n\n if (response.ok) {\n return ReadUrlResponseFactory.fromNodeJSReadable(response.body, {\n etag: response.headers.get('ETag') ?? undefined,\n lastModifiedAt: parseLastModified(\n response.headers.get('Last-Modified'),\n ),\n });\n }\n\n const message = `${url} could not be read as ${builtUrl}, ${response.status} ${response.statusText}`;\n if (response.status === 404) {\n throw new NotFoundError(message);\n }\n throw new Error(message);\n }\n\n async readTree(\n url: string,\n options?: UrlReaderServiceReadTreeOptions,\n ): Promise<UrlReaderServiceReadTreeResponse> {\n const { etag, signal, token } = options ?? {};\n const { ref, full_name, filepath } = parseGitUrl(url);\n\n let repoFullName = full_name;\n\n const relativePath = getGitLabIntegrationRelativePath(\n this.integration.config,\n );\n\n // Considering self hosted gitlab with relative\n // assuming '/gitlab' is the relative path\n // from: /gitlab/repo/project\n // to: repo/project\n if (relativePath) {\n const rectifiedRelativePath = `${trimStart(relativePath, '/')}/`;\n repoFullName = full_name.replace(rectifiedRelativePath, '');\n }\n\n // Use GitLab API to get the default branch\n // encodeURIComponent is required for GitLab API\n // https://docs.gitlab.com/ee/api/README.html#namespaced-path-encoding\n const projectGitlabResponse = await fetch(\n new URL(\n `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent(\n repoFullName,\n )}`,\n ).toString(),\n getGitLabRequestOptions(this.integration.config, token),\n );\n if (!projectGitlabResponse.ok) {\n const msg = `Failed to read tree from ${url}, ${projectGitlabResponse.status} ${projectGitlabResponse.statusText}`;\n if (projectGitlabResponse.status === 404) {\n throw new NotFoundError(msg);\n }\n throw new Error(msg);\n }\n const projectGitlabResponseJson = await projectGitlabResponse.json();\n\n // ref is an empty string if no branch is set in provided url to readTree.\n const branch = ref || projectGitlabResponseJson.default_branch;\n\n // Fetch the latest commit that modifies the filepath in the provided or default branch\n // to compare against the provided sha.\n const commitsReqParams = new URLSearchParams();\n commitsReqParams.set('ref_name', branch);\n if (!!filepath) {\n commitsReqParams.set('path', filepath);\n }\n const commitsGitlabResponse = await fetch(\n new URL(\n `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent(\n repoFullName,\n )}/repository/commits?${commitsReqParams.toString()}`,\n ).toString(),\n {\n ...getGitLabRequestOptions(this.integration.config, token),\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 && { signal: signal as any }),\n },\n );\n if (!commitsGitlabResponse.ok) {\n const message = `Failed to read tree (branch) from ${url}, ${commitsGitlabResponse.status} ${commitsGitlabResponse.statusText}`;\n if (commitsGitlabResponse.status === 404) {\n throw new NotFoundError(message);\n }\n throw new Error(message);\n }\n\n const commitSha = (await commitsGitlabResponse.json())[0]?.id ?? '';\n if (etag && etag === commitSha) {\n throw new NotModifiedError();\n }\n\n const archiveReqParams = new URLSearchParams();\n archiveReqParams.set('sha', branch);\n if (!!filepath) {\n archiveReqParams.set('path', filepath);\n }\n // https://docs.gitlab.com/ee/api/repositories.html#get-file-archive\n const archiveGitLabResponse = await fetch(\n `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent(\n repoFullName,\n )}/repository/archive?${archiveReqParams.toString()}`,\n {\n ...getGitLabRequestOptions(this.integration.config, token),\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 && { signal: signal as any }),\n },\n );\n if (!archiveGitLabResponse.ok) {\n const message = `Failed to read tree (archive) from ${url}, ${archiveGitLabResponse.status} ${archiveGitLabResponse.statusText}`;\n if (archiveGitLabResponse.status === 404) {\n throw new NotFoundError(message);\n }\n throw new Error(message);\n }\n\n return await this.deps.treeResponseFactory.fromTarArchive({\n stream: Readable.from(archiveGitLabResponse.body),\n subpath: filepath,\n etag: commitSha,\n filter: options?.filter,\n });\n }\n\n async search(\n url: string,\n options?: UrlReaderServiceSearchOptions,\n ): Promise<UrlReaderServiceSearchResponse> {\n const { filepath } = parseGitUrl(url);\n\n // If it's a direct URL we use readUrl instead\n if (!filepath?.match(/[*?]/)) {\n try {\n const data = await this.readUrl(url, options);\n\n return {\n files: [\n {\n url: url,\n content: data.buffer,\n lastModifiedAt: data.lastModifiedAt,\n },\n ],\n etag: data.etag ?? '',\n };\n } catch (error) {\n assertError(error);\n if (error.name === 'NotFoundError') {\n return {\n files: [],\n etag: '',\n };\n }\n throw error;\n }\n }\n\n const staticPart = this.getStaticPart(filepath);\n const matcher = new Minimatch(filepath);\n const treeUrl = trimEnd(url.replace(filepath, staticPart), `/`);\n const pathPrefix = staticPart ? `${staticPart}/` : '';\n const tree = await this.readTree(treeUrl, {\n etag: options?.etag,\n signal: options?.signal,\n filter: path => matcher.match(`${pathPrefix}${path}`),\n });\n\n const files = await tree.files();\n return {\n etag: tree.etag,\n files: files.map(file => ({\n url: this.integration.resolveUrl({\n url: `/${pathPrefix}${file.path}`,\n base: url,\n }),\n content: file.content,\n lastModifiedAt: file.lastModifiedAt,\n })),\n };\n }\n\n /**\n * This function splits the input globPattern string into segments using the path separator /. It then iterates over\n * the segments from the end of the array towards the beginning, checking if the concatenated string up to that\n * segment matches the original globPattern using the minimatch function. If a match is found, it continues iterating.\n * If no match is found, it returns the concatenated string up to the current segment, which is the static part of the\n * glob pattern.\n *\n * E.g. `catalog/foo/*.yaml` will return `catalog/foo`.\n *\n * @param globPattern - the glob pattern\n */\n private getStaticPart(globPattern: string) {\n const segments = globPattern.split('/');\n let i = segments.length;\n while (\n i > 0 &&\n new Minimatch(segments.slice(0, i).join('/')).match(globPattern)\n ) {\n i--;\n }\n return segments.slice(0, i).join('/');\n }\n\n toString() {\n const { host, token } = this.integration.config;\n return `gitlab{host=${host},authed=${Boolean(token)}}`;\n }\n\n private async getGitlabFetchUrl(\n target: string,\n token?: string,\n ): Promise<string> {\n // If the target is for a job artifact then go down that path\n const targetUrl = new URL(target);\n if (targetUrl.pathname.includes('/-/jobs/artifacts/')) {\n return this.getGitlabArtifactFetchUrl(targetUrl, token).then(value =>\n value.toString(),\n );\n }\n // Default to the old behavior of assuming the url is for a file\n return getGitLabFileFetchUrl(target, {\n ...this.integration.config,\n ...(token && { token }),\n });\n }\n\n // convert urls of the form:\n // https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>\n // to urls of the form:\n // https://example.com/api/v4/projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=<job_name>\n private async getGitlabArtifactFetchUrl(\n target: URL,\n token?: string,\n ): Promise<URL> {\n if (!target.pathname.includes('/-/jobs/artifacts/')) {\n throw new Error('Unable to process url as an GitLab artifact');\n }\n try {\n const [namespaceAndProject, ref] =\n target.pathname.split('/-/jobs/artifacts/');\n const projectPath = new URL(target);\n projectPath.pathname = namespaceAndProject;\n const projectId = await this.resolveProjectToId(projectPath, token);\n const relativePath = getGitLabIntegrationRelativePath(\n this.integration.config,\n );\n const newUrl = new URL(target);\n newUrl.pathname = `${relativePath}/api/v4/projects/${projectId}/jobs/artifacts/${ref}`;\n return newUrl;\n } catch (e) {\n throw new Error(\n `Unable to translate GitLab artifact URL: ${target}, ${e}`,\n );\n }\n }\n\n private async resolveProjectToId(\n pathToProject: URL,\n token?: string,\n ): Promise<number> {\n let project = pathToProject.pathname;\n // Check relative path exist and remove it if so\n const relativePath = getGitLabIntegrationRelativePath(\n this.integration.config,\n );\n if (relativePath) {\n project = project.replace(relativePath, '');\n }\n // Trim an initial / if it exists\n project = project.replace(/^\\//, '');\n const result = await fetch(\n `${\n pathToProject.origin\n }${relativePath}/api/v4/projects/${encodeURIComponent(project)}`,\n getGitLabRequestOptions(this.integration.config, token),\n );\n const data = await result.json();\n if (!result.ok) {\n throw new Error(`Gitlab error: ${data.error}, ${data.error_description}`);\n }\n return Number(data.id);\n }\n}\n"],"names":["ScmIntegrations","fetch","getGitLabRequestOptions","NotModifiedError","ReadUrlResponseFactory","parseLastModified","NotFoundError","parseGitUrl","getGitLabIntegrationRelativePath","trimStart","Readable","assertError","Minimatch","trimEnd","getGitLabFileFetchUrl"],"mappings":";;;;;;;;;;;;;;;;;AAqDO,MAAM,eAA4C,CAAA;AAAA,EAYvD,WAAA,CACmB,aACA,IACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA;AAChB,EAdH,OAAO,OAAyB,GAAA,CAAC,EAAE,MAAA,EAAQ,qBAA0B,KAAA;AACnE,IAAM,MAAA,YAAA,GAAeA,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AACtD,IAAA,OAAO,YAAa,CAAA,MAAA,CAAO,IAAK,EAAA,CAAE,IAAI,CAAe,WAAA,KAAA;AACnD,MAAM,MAAA,MAAA,GAAS,IAAI,eAAA,CAAgB,WAAa,EAAA;AAAA,QAC9C;AAAA,OACD,CAAA;AACD,MAAA,MAAM,YAAY,CAAC,GAAA,KAAa,GAAI,CAAA,IAAA,KAAS,YAAY,MAAO,CAAA,IAAA;AAChE,MAAO,OAAA,EAAE,QAAQ,SAAU,EAAA;AAAA,KAC5B,CAAA;AAAA,GACH;AAAA,EAOA,MAAM,KAAK,GAA8B,EAAA;AACvC,IAAA,MAAM,QAAW,GAAA,MAAM,IAAK,CAAA,OAAA,CAAQ,GAAG,CAAA;AACvC,IAAA,OAAO,SAAS,MAAO,EAAA;AAAA;AACzB,EAEA,MAAM,OACJ,CAAA,GAAA,EACA,OAC0C,EAAA;AAC1C,IAAA,MAAM,EAAE,IAAM,EAAA,iBAAA,EAAmB,QAAQ,KAAM,EAAA,GAAI,WAAW,EAAC;AAC/D,IAAM,MAAA,UAAA,GAAa,GAAI,CAAA,QAAA,CAAS,oBAAoB,CAAA;AACpD,IAAA,MAAM,QAAW,GAAA,MAAM,IAAK,CAAA,iBAAA,CAAkB,KAAK,KAAK,CAAA;AAExD,IAAI,IAAA,QAAA;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-defaults";
|
|
6
|
-
var version = "0.
|
|
6
|
+
var version = "0.10.0-next.1";
|
|
7
7
|
var description = "Backend defaults used by Backstage backend apps";
|
|
8
8
|
var backstage = {
|
|
9
9
|
role: "node-library"
|
|
@@ -147,6 +147,7 @@ var dependencies = {
|
|
|
147
147
|
"@google-cloud/storage": "^7.0.0",
|
|
148
148
|
"@keyv/memcache": "^2.0.1",
|
|
149
149
|
"@keyv/redis": "^4.0.1",
|
|
150
|
+
"@keyv/valkey": "^1.0.1",
|
|
150
151
|
"@manypkg/get-packages": "^1.1.3",
|
|
151
152
|
"@octokit/rest": "^19.0.3",
|
|
152
153
|
"@opentelemetry/api": "^1.9.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.json.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package.json.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/scheduler.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
-
import { DatabaseService, LoggerService, RootLifecycleService, SchedulerService } from '@backstage/backend-plugin-api';
|
|
2
|
+
import { DatabaseService, LoggerService, RootLifecycleService, HttpRouterService, PluginMetadataService, SchedulerService } from '@backstage/backend-plugin-api';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Default implementation of the task scheduler service.
|
|
@@ -10,7 +10,9 @@ declare class DefaultSchedulerService {
|
|
|
10
10
|
static create(options: {
|
|
11
11
|
database: DatabaseService;
|
|
12
12
|
logger: LoggerService;
|
|
13
|
-
rootLifecycle
|
|
13
|
+
rootLifecycle: RootLifecycleService;
|
|
14
|
+
httpRouter: HttpRouterService;
|
|
15
|
+
pluginMetadata: PluginMetadataService;
|
|
14
16
|
}): SchedulerService;
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 The Backstage Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// @ts-check
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param { import("knex").Knex } knex
|
|
21
|
+
* @returns { Promise<void> }
|
|
22
|
+
*/
|
|
23
|
+
exports.up = async function up(knex) {
|
|
24
|
+
await knex.schema.alterTable('backstage_backend_tasks__tasks', table => {
|
|
25
|
+
table
|
|
26
|
+
.text('last_run_error_json', 'longtext')
|
|
27
|
+
.nullable()
|
|
28
|
+
.comment(
|
|
29
|
+
'JSON serialized error object from the last task run, if it failed',
|
|
30
|
+
);
|
|
31
|
+
table
|
|
32
|
+
.dateTime('last_run_ended_at')
|
|
33
|
+
.nullable()
|
|
34
|
+
.comment('The last time that the task ended');
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param { import("knex").Knex } knex
|
|
40
|
+
* @returns { Promise<void> }
|
|
41
|
+
*/
|
|
42
|
+
exports.down = async function down(knex) {
|
|
43
|
+
await knex.schema.alterTable('backstage_backend_tasks__tasks', table => {
|
|
44
|
+
table.dropColumn('last_run_error_json');
|
|
45
|
+
table.dropColumn('last_run_ended_at');
|
|
46
|
+
});
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-defaults",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-next.1",
|
|
4
4
|
"description": "Backend defaults used by Backstage backend apps",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -208,22 +208,23 @@
|
|
|
208
208
|
"@aws-sdk/credential-providers": "^3.350.0",
|
|
209
209
|
"@aws-sdk/types": "^3.347.0",
|
|
210
210
|
"@azure/storage-blob": "^12.5.0",
|
|
211
|
-
"@backstage/backend-app-api": "
|
|
212
|
-
"@backstage/backend-dev-utils": "
|
|
213
|
-
"@backstage/backend-plugin-api": "
|
|
214
|
-
"@backstage/cli-node": "
|
|
215
|
-
"@backstage/config": "
|
|
216
|
-
"@backstage/config-loader": "
|
|
217
|
-
"@backstage/errors": "
|
|
218
|
-
"@backstage/integration": "
|
|
219
|
-
"@backstage/integration-aws-node": "
|
|
220
|
-
"@backstage/plugin-auth-node": "
|
|
221
|
-
"@backstage/plugin-events-node": "
|
|
222
|
-
"@backstage/plugin-permission-node": "
|
|
223
|
-
"@backstage/types": "
|
|
211
|
+
"@backstage/backend-app-api": "1.2.3-next.1",
|
|
212
|
+
"@backstage/backend-dev-utils": "0.1.5",
|
|
213
|
+
"@backstage/backend-plugin-api": "1.3.1-next.1",
|
|
214
|
+
"@backstage/cli-node": "0.2.13",
|
|
215
|
+
"@backstage/config": "1.3.2",
|
|
216
|
+
"@backstage/config-loader": "1.10.1-next.0",
|
|
217
|
+
"@backstage/errors": "1.2.7",
|
|
218
|
+
"@backstage/integration": "1.16.4-next.1",
|
|
219
|
+
"@backstage/integration-aws-node": "0.1.15",
|
|
220
|
+
"@backstage/plugin-auth-node": "0.6.3-next.1",
|
|
221
|
+
"@backstage/plugin-events-node": "0.4.11-next.1",
|
|
222
|
+
"@backstage/plugin-permission-node": "0.10.0-next.1",
|
|
223
|
+
"@backstage/types": "1.2.1",
|
|
224
224
|
"@google-cloud/storage": "^7.0.0",
|
|
225
225
|
"@keyv/memcache": "^2.0.1",
|
|
226
226
|
"@keyv/redis": "^4.0.1",
|
|
227
|
+
"@keyv/valkey": "^1.0.1",
|
|
227
228
|
"@manypkg/get-packages": "^1.1.3",
|
|
228
229
|
"@octokit/rest": "^19.0.3",
|
|
229
230
|
"@opentelemetry/api": "^1.9.0",
|
|
@@ -270,9 +271,9 @@
|
|
|
270
271
|
},
|
|
271
272
|
"devDependencies": {
|
|
272
273
|
"@aws-sdk/util-stream-node": "^3.350.0",
|
|
273
|
-
"@backstage/backend-plugin-api": "
|
|
274
|
-
"@backstage/backend-test-utils": "
|
|
275
|
-
"@backstage/cli": "
|
|
274
|
+
"@backstage/backend-plugin-api": "1.3.1-next.1",
|
|
275
|
+
"@backstage/backend-test-utils": "1.5.0-next.1",
|
|
276
|
+
"@backstage/cli": "0.32.1-next.1",
|
|
276
277
|
"@google-cloud/cloud-sql-connector": "^1.4.0",
|
|
277
278
|
"@types/archiver": "^6.0.0",
|
|
278
279
|
"@types/base64-stream": "^1.0.2",
|