@axis-backstage/plugin-readme-backend 0.12.0 → 0.13.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,20 @@
1
1
  # @axis-backstage/plugin-readme-backend
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 84e60e6: A configuration has been added to the readme backend that makes it possible to
8
+ configure which files to look for and the exact order. Example:
9
+
10
+ ```yaml
11
+ readme:
12
+ -fileNames:
13
+ - README.txt
14
+ - README.text
15
+ - README.markdown
16
+ ```
17
+
3
18
  ## 0.12.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -32,6 +32,20 @@ const backend = createBackend();
32
32
  backend.start();
33
33
  ```
34
34
 
35
+ ### Configuration
36
+
37
+ This plugin does not require any configuration. It has a default configuration
38
+ with a set of README file names that it will look for in the entity source location. This actual file to use and the order to look for them can be
39
+ configured in the `app-config.yaml` file using the "readme.fileNames" configuration key. This is a simple list of file names to look for in the entity source location.
40
+
41
+ ```yaml
42
+ readme:
43
+ -fileNames:
44
+ - README.txt
45
+ - README.text
46
+ - README.markdown
47
+ ```
48
+
35
49
  ### Troubleshooting
36
50
 
37
51
  If the backend fails to provide README content for an entity, it could be due to several reasons.
package/config.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export interface Config {
2
+ /**
3
+ * Configuration options for the Readme backend plugin
4
+ */
5
+ readme?: {
6
+ /**
7
+ * Optional list of file names to try. Specifies the file names to try
8
+ * when looking for a README file and which order to use.
9
+ */
10
+ fileNames?: string[];
11
+ };
12
+ }
@@ -1,14 +1,25 @@
1
1
  'use strict';
2
2
 
3
+ const CONFIG_PATH = "readme.fileNames";
3
4
  const NOT_FOUND_PLACEHOLDER = "NOT_FOUND";
4
- const README_TYPES = [
5
- { name: "README", type: "text/plain" },
5
+ const DEFAULT_README_TYPES = [
6
6
  { name: "README.md", type: "text/markdown" },
7
+ { name: "README.MD", type: "text/markdown" },
8
+ { name: "README", type: "text/plain" },
7
9
  { name: "README.rst", type: "text/plain" },
8
- { name: "README.txt", type: "text/plain" },
9
- { name: "README.MD", type: "text/markdown" }
10
+ { name: "README.txt", type: "text/plain" }
10
11
  ];
12
+ function getReadmeTypes(config) {
13
+ const readmeTypes = config.getOptionalStringArray(CONFIG_PATH);
14
+ if (!readmeTypes) {
15
+ return DEFAULT_README_TYPES;
16
+ }
17
+ return readmeTypes.map((name) => {
18
+ const type = name.endsWith(".md") || name.endsWith(".MD") ? "text/markdown" : "text/plain";
19
+ return { name, type };
20
+ });
21
+ }
11
22
 
12
23
  exports.NOT_FOUND_PLACEHOLDER = NOT_FOUND_PLACEHOLDER;
13
- exports.README_TYPES = README_TYPES;
24
+ exports.getReadmeTypes = getReadmeTypes;
14
25
  //# sourceMappingURL=constants.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs.js","sources":["../../src/service/constants.ts"],"sourcesContent":["import { FileType } from './types';\n\n// Cache placeholder for entities where no readme\nexport const NOT_FOUND_PLACEHOLDER = 'NOT_FOUND';\n\nexport const README_TYPES: FileType[] = [\n { name: 'README', type: 'text/plain' },\n { name: 'README.md', type: 'text/markdown' },\n { name: 'README.rst', type: 'text/plain' },\n { name: 'README.txt', type: 'text/plain' },\n { name: 'README.MD', type: 'text/markdown' },\n];\n"],"names":[],"mappings":";;AAGO,MAAM,qBAAwB,GAAA;AAE9B,MAAM,YAA2B,GAAA;AAAA,EACtC,EAAE,IAAA,EAAM,QAAU,EAAA,IAAA,EAAM,YAAa,EAAA;AAAA,EACrC,EAAE,IAAA,EAAM,WAAa,EAAA,IAAA,EAAM,eAAgB,EAAA;AAAA,EAC3C,EAAE,IAAA,EAAM,YAAc,EAAA,IAAA,EAAM,YAAa,EAAA;AAAA,EACzC,EAAE,IAAA,EAAM,YAAc,EAAA,IAAA,EAAM,YAAa,EAAA;AAAA,EACzC,EAAE,IAAA,EAAM,WAAa,EAAA,IAAA,EAAM,eAAgB;AAC7C;;;;;"}
1
+ {"version":3,"file":"constants.cjs.js","sources":["../../src/service/constants.ts"],"sourcesContent":["import { RootConfigService } from '@backstage/backend-plugin-api';\nimport { FileType } from './types';\n\nconst CONFIG_PATH = 'readme.fileNames';\n\n// Cache placeholder for entities where no readme\nexport const NOT_FOUND_PLACEHOLDER = 'NOT_FOUND';\n\nconst DEFAULT_README_TYPES: FileType[] = [\n { name: 'README.md', type: 'text/markdown' },\n { name: 'README.MD', type: 'text/markdown' },\n { name: 'README', type: 'text/plain' },\n { name: 'README.rst', type: 'text/plain' },\n { name: 'README.txt', type: 'text/plain' },\n];\n\nexport function getReadmeTypes(config: RootConfigService): FileType[] {\n const readmeTypes = config.getOptionalStringArray(CONFIG_PATH);\n if (!readmeTypes) {\n return DEFAULT_README_TYPES;\n }\n return readmeTypes.map(name => {\n const type =\n name.endsWith('.md') || name.endsWith('.MD')\n ? 'text/markdown'\n : 'text/plain';\n return { name, type };\n });\n}\n"],"names":[],"mappings":";;AAGA,MAAM,WAAc,GAAA,kBAAA;AAGb,MAAM,qBAAwB,GAAA;AAErC,MAAM,oBAAmC,GAAA;AAAA,EACvC,EAAE,IAAA,EAAM,WAAa,EAAA,IAAA,EAAM,eAAgB,EAAA;AAAA,EAC3C,EAAE,IAAA,EAAM,WAAa,EAAA,IAAA,EAAM,eAAgB,EAAA;AAAA,EAC3C,EAAE,IAAA,EAAM,QAAU,EAAA,IAAA,EAAM,YAAa,EAAA;AAAA,EACrC,EAAE,IAAA,EAAM,YAAc,EAAA,IAAA,EAAM,YAAa,EAAA;AAAA,EACzC,EAAE,IAAA,EAAM,YAAc,EAAA,IAAA,EAAM,YAAa;AAC3C,CAAA;AAEO,SAAS,eAAe,MAAuC,EAAA;AACpE,EAAM,MAAA,WAAA,GAAc,MAAO,CAAA,sBAAA,CAAuB,WAAW,CAAA;AAC7D,EAAA,IAAI,CAAC,WAAa,EAAA;AAChB,IAAO,OAAA,oBAAA;AAAA;AAET,EAAO,OAAA,WAAA,CAAY,IAAI,CAAQ,IAAA,KAAA;AAC7B,IAAM,MAAA,IAAA,GACJ,KAAK,QAAS,CAAA,KAAK,KAAK,IAAK,CAAA,QAAA,CAAS,KAAK,CAAA,GACvC,eACA,GAAA,YAAA;AACN,IAAO,OAAA,EAAE,MAAM,IAAK,EAAA;AAAA,GACrB,CAAA;AACH;;;;;"}
@@ -60,7 +60,8 @@ async function createRouter(options) {
60
60
  response.status(500).json({ error: `No integration found for ${source.target}` });
61
61
  return;
62
62
  }
63
- for (const fileType of constants.README_TYPES) {
63
+ const readmeTypes = constants.getReadmeTypes(config);
64
+ for (const fileType of readmeTypes) {
64
65
  const url = integration.resolveUrl({
65
66
  url: fileType.name,
66
67
  base: source.target
@@ -1 +1 @@
1
- {"version":3,"file":"router.cjs.js","sources":["../../src/service/router.ts"],"sourcesContent":["import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport {\n AuthService,\n CacheService,\n DiscoveryService,\n LoggerService,\n RootConfigService,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n getEntitySourceLocation,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { CatalogClient } from '@backstage/catalog-client';\nimport { isError, NotFoundError } from '@backstage/errors';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { isSymLink } from '../lib';\nimport { NOT_FOUND_PLACEHOLDER, README_TYPES } from './constants';\nimport { ReadmeFile } from './types';\n\n/**\n * Constructs a readme router.\n *\n */\ninterface RouterOptions {\n auth: AuthService;\n config: RootConfigService;\n discovery: DiscoveryService;\n logger: LoggerService;\n reader: UrlReaderService;\n cache: CacheService;\n}\n\n/**\n * Constructs a readme router.\n *\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { auth, logger, config, reader, discovery, cache } = options;\n const catalogClient = new CatalogClient({ discoveryApi: discovery });\n\n logger.info('Initializing readme backend');\n const integrations = ScmIntegrations.fromConfig(config);\n const router = Router();\n router.use(express.json());\n\n router.get('/health', (_, response) => {\n response.json({ status: 'ok' });\n });\n\n router.get('/:kind/:namespace/:name', async (request, response) => {\n const { kind, namespace, name } = request.params;\n const entityRef = stringifyEntityRef({ kind, namespace, name });\n const cacheDoc = (await cache.get(entityRef)) as ReadmeFile | undefined;\n\n if (cacheDoc && cacheDoc.name === NOT_FOUND_PLACEHOLDER) {\n throw new NotFoundError('Readme could not be found');\n }\n if (cacheDoc) {\n logger.info(`Loading README for ${entityRef} from cache.`);\n response.type(cacheDoc.type);\n response.send(cacheDoc.content);\n return;\n }\n const { token } = await auth.getPluginRequestToken({\n onBehalfOf: await auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const entity = await catalogClient.getEntityByRef(entityRef, { token });\n if (!entity) {\n logger.info(`No integration found for ${entityRef}`);\n response\n .status(500)\n .json({ error: `No integration found for ${entityRef}` });\n return;\n }\n const source = getEntitySourceLocation(entity);\n\n if (!source || source.type !== 'url') {\n const errorMessage = `Not valid location for ${source.target}`;\n logger.info(errorMessage);\n throw new NotFoundError(errorMessage);\n }\n const integration = integrations.byUrl(source.target);\n\n if (!integration) {\n logger.info(`No integration found for ${source.target}`);\n response\n .status(500)\n .json({ error: `No integration found for ${source.target}` });\n return;\n }\n\n for (const fileType of README_TYPES) {\n const url = integration.resolveUrl({\n url: fileType.name,\n base: source.target,\n });\n\n let content;\n\n try {\n logger.debug(`Trying README location: ${url} for ${entityRef} `);\n response.type(fileType.type);\n\n const urlResponse = await reader.readUrl(url);\n content = (await urlResponse.buffer()).toString('utf-8');\n\n if (isSymLink(content)) {\n const symLinkUrl = integration.resolveUrl({\n url: content,\n base: source.target,\n });\n const symLinkUrlResponse = await reader.readUrl(symLinkUrl);\n content = (await symLinkUrlResponse.buffer()).toString('utf-8');\n }\n\n cache.set(entityRef, {\n name: fileType.name,\n type: fileType.type,\n content: content,\n });\n logger.info(\n `Found README for ${entityRef}: ${url} type ${fileType.type}`,\n );\n response.send(content);\n return;\n } catch (error: unknown) {\n if (isError(error) && error.name === 'NotFoundError') {\n continue;\n } else {\n response.status(500).json({\n error: `Readme failure: ${error}`,\n });\n return;\n }\n }\n }\n logger.info(`Readme not found for ${entityRef}`);\n cache.set(entityRef, {\n name: NOT_FOUND_PLACEHOLDER,\n type: '',\n content: '',\n });\n throw new NotFoundError('Readme could not be found');\n });\n\n const middleware = MiddlewareFactory.create({ logger, config });\n router.use(middleware.error());\n return router;\n}\n"],"names":["catalogClient","CatalogClient","ScmIntegrations","Router","express","stringifyEntityRef","NOT_FOUND_PLACEHOLDER","NotFoundError","getEntitySourceLocation","README_TYPES","isSymLink","isError","MiddlewareFactory"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAA,MAAM,EAAE,IAAM,EAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,SAAA,EAAW,OAAU,GAAA,OAAA;AAC3D,EAAA,MAAMA,kBAAgB,IAAIC,2BAAA,CAAc,EAAE,YAAA,EAAc,WAAW,CAAA;AAEnE,EAAA,MAAA,CAAO,KAAK,6BAA6B,CAAA;AACzC,EAAM,MAAA,YAAA,GAAeC,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA;AACtD,EAAA,MAAM,SAASC,uBAAO,EAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,wBAAQ,CAAA,IAAA,EAAM,CAAA;AAEzB,EAAA,MAAA,CAAO,GAAI,CAAA,SAAA,EAAW,CAAC,CAAA,EAAG,QAAa,KAAA;AACrC,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,IAAA,EAAM,CAAA;AAAA,GAC/B,CAAA;AAED,EAAA,MAAA,CAAO,GAAI,CAAA,yBAAA,EAA2B,OAAO,OAAA,EAAS,QAAa,KAAA;AACjE,IAAA,MAAM,EAAE,IAAA,EAAM,SAAW,EAAA,IAAA,KAAS,OAAQ,CAAA,MAAA;AAC1C,IAAA,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../../src/service/router.ts"],"sourcesContent":["import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';\nimport {\n AuthService,\n CacheService,\n DiscoveryService,\n LoggerService,\n RootConfigService,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n getEntitySourceLocation,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { CatalogClient } from '@backstage/catalog-client';\nimport { isError, NotFoundError } from '@backstage/errors';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { isSymLink } from '../lib';\nimport { NOT_FOUND_PLACEHOLDER, getReadmeTypes } from './constants';\nimport { ReadmeFile } from './types';\n\n/**\n * Constructs a readme router.\n *\n */\ninterface RouterOptions {\n auth: AuthService;\n config: RootConfigService;\n discovery: DiscoveryService;\n logger: LoggerService;\n reader: UrlReaderService;\n cache: CacheService;\n}\n\n/**\n * Constructs a readme router.\n *\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { auth, logger, config, reader, discovery, cache } = options;\n const catalogClient = new CatalogClient({ discoveryApi: discovery });\n\n logger.info('Initializing readme backend');\n const integrations = ScmIntegrations.fromConfig(config);\n const router = Router();\n router.use(express.json());\n\n router.get('/health', (_, response) => {\n response.json({ status: 'ok' });\n });\n\n router.get('/:kind/:namespace/:name', async (request, response) => {\n const { kind, namespace, name } = request.params;\n const entityRef = stringifyEntityRef({ kind, namespace, name });\n const cacheDoc = (await cache.get(entityRef)) as ReadmeFile | undefined;\n\n if (cacheDoc && cacheDoc.name === NOT_FOUND_PLACEHOLDER) {\n throw new NotFoundError('Readme could not be found');\n }\n if (cacheDoc) {\n logger.info(`Loading README for ${entityRef} from cache.`);\n response.type(cacheDoc.type);\n response.send(cacheDoc.content);\n return;\n }\n const { token } = await auth.getPluginRequestToken({\n onBehalfOf: await auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const entity = await catalogClient.getEntityByRef(entityRef, { token });\n if (!entity) {\n logger.info(`No integration found for ${entityRef}`);\n response\n .status(500)\n .json({ error: `No integration found for ${entityRef}` });\n return;\n }\n const source = getEntitySourceLocation(entity);\n\n if (!source || source.type !== 'url') {\n const errorMessage = `Not valid location for ${source.target}`;\n logger.info(errorMessage);\n throw new NotFoundError(errorMessage);\n }\n const integration = integrations.byUrl(source.target);\n\n if (!integration) {\n logger.info(`No integration found for ${source.target}`);\n response\n .status(500)\n .json({ error: `No integration found for ${source.target}` });\n return;\n }\n\n const readmeTypes = getReadmeTypes(config);\n\n for (const fileType of readmeTypes) {\n const url = integration.resolveUrl({\n url: fileType.name,\n base: source.target,\n });\n\n let content;\n\n try {\n logger.debug(`Trying README location: ${url} for ${entityRef} `);\n response.type(fileType.type);\n\n const urlResponse = await reader.readUrl(url);\n content = (await urlResponse.buffer()).toString('utf-8');\n\n if (isSymLink(content)) {\n const symLinkUrl = integration.resolveUrl({\n url: content,\n base: source.target,\n });\n const symLinkUrlResponse = await reader.readUrl(symLinkUrl);\n content = (await symLinkUrlResponse.buffer()).toString('utf-8');\n }\n\n cache.set(entityRef, {\n name: fileType.name,\n type: fileType.type,\n content: content,\n });\n logger.info(\n `Found README for ${entityRef}: ${url} type ${fileType.type}`,\n );\n response.send(content);\n return;\n } catch (error: unknown) {\n if (isError(error) && error.name === 'NotFoundError') {\n continue;\n } else {\n response.status(500).json({\n error: `Readme failure: ${error}`,\n });\n return;\n }\n }\n }\n logger.info(`Readme not found for ${entityRef}`);\n cache.set(entityRef, {\n name: NOT_FOUND_PLACEHOLDER,\n type: '',\n content: '',\n });\n throw new NotFoundError('Readme could not be found');\n });\n\n const middleware = MiddlewareFactory.create({ logger, config });\n router.use(middleware.error());\n return router;\n}\n"],"names":["catalogClient","CatalogClient","ScmIntegrations","Router","express","stringifyEntityRef","NOT_FOUND_PLACEHOLDER","NotFoundError","getEntitySourceLocation","getReadmeTypes","isSymLink","isError","MiddlewareFactory"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,eAAsB,aACpB,OAC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B,QAAA;AAAA,eACO,KAAgB,EAAA;AACvB,QAAA,IAAIC,cAAQ,CAAA,KAAK,CAAK,IAAA,KAAA,CAAM,SAAS,eAAiB,EAAA;AACpD,UAAA;AAAA,SACK,MAAA;AACL,UAAS,QAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,IAAK,CAAA;AAAA,YACxB,KAAA,EAAO,mBAAmB,KAAK,CAAA;AAAA,WAChC,CAAA;AACD,UAAA;AAAA;AACF;AACF;AAEF,IAAO,MAAA,CAAA,IAAA,CAAK,CAAwB,qBAAA,EAAA,SAAS,CAAE,CAAA,CAAA;AAC/C,IAAA,KAAA,CAAM,IAAI,SAAW,EAAA;AAAA,MACnB,IAAM,EAAAL,+BAAA;AAAA,MACN,IAAM,EAAA,EAAA;AAAA,MACN,OAAS,EAAA;AAAA,KACV,CAAA;AACD,IAAM,MAAA,IAAIC,qBAAc,2BAA2B,CAAA;AAAA,GACpD,CAAA;AAED,EAAA,MAAM,aAAaK,gCAAkB,CAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAC9D,EAAO,MAAA,CAAA,GAAA,CAAI,UAAW,CAAA,KAAA,EAAO,CAAA;AAC7B,EAAO,OAAA,MAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axis-backstage/plugin-readme-backend",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "main": "dist/index.cjs.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -44,13 +44,16 @@
44
44
  "devDependencies": {
45
45
  "@backstage/backend-test-utils": "^1.3.0",
46
46
  "@backstage/cli": "^0.30.0",
47
+ "@backstage/config": "^1.3.2",
47
48
  "@types/supertest": "^2.0.12",
48
- "msw": "^1.0.0",
49
+ "msw": "^2.7.3",
49
50
  "supertest": "^6.2.4"
50
51
  },
51
52
  "files": [
52
- "dist"
53
+ "dist",
54
+ "config.d.ts"
53
55
  ],
56
+ "configSchema": "config.d.ts",
54
57
  "typesVersions": {
55
58
  "*": {
56
59
  "index": [