@backstage/plugin-search-backend 1.0.2 → 1.1.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 +44 -0
- package/dist/index.cjs.js +14 -2
- package/dist/index.cjs.js.map +1 -1
- package/package.json +12 -13
- package/LICENSE +0 -201
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @backstage/plugin-search-backend
|
|
2
2
|
|
|
3
|
+
## 1.1.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 16c853a6ed: Be less restrictive with unknown keys on query endpoint
|
|
8
|
+
- a799972bb1: The query received by search engines now contains a property called `pageLimit`, it specifies how many results to return per page when sending a query request to the search backend.
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
_Returns up to 30 results per page_
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
GET /query?pageLimit=30
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The search backend validates the page limit and this value must not exceed 100, but it doesn't set a default value for the page limit parameter, it leaves it up to each search engine to set this, so Lunr, Postgres and Elastic Search set 25 results per page as a default value.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @backstage/backend-common@0.15.2-next.1
|
|
23
|
+
- @backstage/plugin-search-common@1.1.0-next.1
|
|
24
|
+
- @backstage/plugin-search-backend-node@1.0.3-next.1
|
|
25
|
+
- @backstage/config@1.0.3-next.1
|
|
26
|
+
- @backstage/errors@1.1.2-next.1
|
|
27
|
+
- @backstage/types@1.0.0
|
|
28
|
+
- @backstage/plugin-auth-node@0.2.6-next.1
|
|
29
|
+
- @backstage/plugin-permission-common@0.6.5-next.1
|
|
30
|
+
- @backstage/plugin-permission-node@0.6.6-next.1
|
|
31
|
+
|
|
32
|
+
## 1.0.3-next.0
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- Updated dependencies
|
|
37
|
+
- @backstage/backend-common@0.15.2-next.0
|
|
38
|
+
- @backstage/plugin-auth-node@0.2.6-next.0
|
|
39
|
+
- @backstage/plugin-permission-node@0.6.6-next.0
|
|
40
|
+
- @backstage/config@1.0.3-next.0
|
|
41
|
+
- @backstage/errors@1.1.2-next.0
|
|
42
|
+
- @backstage/types@1.0.0
|
|
43
|
+
- @backstage/plugin-permission-common@0.6.5-next.0
|
|
44
|
+
- @backstage/plugin-search-backend-node@1.0.3-next.0
|
|
45
|
+
- @backstage/plugin-search-common@1.0.2-next.0
|
|
46
|
+
|
|
3
47
|
## 1.0.2
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -167,6 +167,7 @@ const jsonObjectSchema = zod.z.lazy(() => {
|
|
|
167
167
|
);
|
|
168
168
|
return zod.z.record(jsonValueSchema);
|
|
169
169
|
});
|
|
170
|
+
const maxPageLimit = 100;
|
|
170
171
|
const allowedLocationProtocols = ["http:", "https:"];
|
|
171
172
|
async function createRouter(options) {
|
|
172
173
|
const { engine: inputEngine, types, permissions, config, logger } = options;
|
|
@@ -174,7 +175,18 @@ async function createRouter(options) {
|
|
|
174
175
|
term: zod.z.string().default(""),
|
|
175
176
|
filters: jsonObjectSchema.optional(),
|
|
176
177
|
types: zod.z.array(zod.z.string().refine((type) => Object.keys(types).includes(type))).optional(),
|
|
177
|
-
pageCursor: zod.z.string().optional()
|
|
178
|
+
pageCursor: zod.z.string().optional(),
|
|
179
|
+
pageLimit: zod.z.string().transform((pageLimit) => parseInt(pageLimit, 10)).refine(
|
|
180
|
+
(pageLimit) => !isNaN(pageLimit),
|
|
181
|
+
(pageLimit) => ({
|
|
182
|
+
message: `The page limit "${pageLimit}" is not a number`
|
|
183
|
+
})
|
|
184
|
+
).refine(
|
|
185
|
+
(pageLimit) => pageLimit <= maxPageLimit,
|
|
186
|
+
(pageLimit) => ({
|
|
187
|
+
message: `The page limit "${pageLimit}" is greater than "${maxPageLimit}"`
|
|
188
|
+
})
|
|
189
|
+
).optional()
|
|
178
190
|
});
|
|
179
191
|
let permissionEvaluator;
|
|
180
192
|
if ("authorizeConditional" in permissions) {
|
|
@@ -219,7 +231,7 @@ async function createRouter(options) {
|
|
|
219
231
|
"/query",
|
|
220
232
|
async (req, res) => {
|
|
221
233
|
var _a;
|
|
222
|
-
const parseResult = requestSchema.safeParse(req.query);
|
|
234
|
+
const parseResult = requestSchema.passthrough().safeParse(req.query);
|
|
223
235
|
if (!parseResult.success) {
|
|
224
236
|
throw new errors.InputError(`Invalid query string: ${parseResult.error}`);
|
|
225
237
|
}
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/service/AuthorizedSearchEngine.ts","../src/service/router.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 { compact, zipObject } from 'lodash';\nimport qs from 'qs';\nimport DataLoader from 'dataloader';\nimport {\n EvaluatePermissionResponse,\n EvaluatePermissionRequest,\n AuthorizeResult,\n isResourcePermission,\n PermissionEvaluator,\n AuthorizePermissionRequest,\n QueryPermissionRequest,\n} from '@backstage/plugin-permission-common';\nimport {\n DocumentTypeInfo,\n IndexableResult,\n IndexableResultSet,\n QueryRequestOptions,\n QueryTranslator,\n SearchEngine,\n SearchQuery,\n} from '@backstage/plugin-search-common';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport { Writable } from 'stream';\n\nexport function decodePageCursor(pageCursor?: string): { page: number } {\n if (!pageCursor) {\n return { page: 0 };\n }\n\n const page = Number(Buffer.from(pageCursor, 'base64').toString('utf-8'));\n if (isNaN(page)) {\n throw new InputError('Invalid page cursor');\n }\n\n if (page < 0) {\n throw new InputError('Invalid page cursor');\n }\n\n return {\n page,\n };\n}\n\nexport function encodePageCursor({ page }: { page: number }): string {\n return Buffer.from(`${page}`, 'utf-8').toString('base64');\n}\n\nexport class AuthorizedSearchEngine implements SearchEngine {\n private readonly pageSize = 25;\n private readonly queryLatencyBudgetMs: number;\n\n constructor(\n private readonly searchEngine: SearchEngine,\n private readonly types: Record<string, DocumentTypeInfo>,\n private readonly permissions: PermissionEvaluator,\n config: Config,\n ) {\n this.queryLatencyBudgetMs =\n config.getOptionalNumber('search.permissions.queryLatencyBudgetMs') ??\n 1000;\n }\n\n setTranslator(translator: QueryTranslator): void {\n this.searchEngine.setTranslator(translator);\n }\n\n async getIndexer(type: string): Promise<Writable> {\n return this.searchEngine.getIndexer(type);\n }\n\n async query(\n query: SearchQuery,\n options: QueryRequestOptions,\n ): Promise<IndexableResultSet> {\n const queryStartTime = Date.now();\n\n const conditionFetcher = new DataLoader(\n (requests: readonly QueryPermissionRequest[]) =>\n this.permissions.authorizeConditional(requests.slice(), options),\n {\n cacheKeyFn: ({ permission: { name } }) => name,\n },\n );\n\n const authorizer = new DataLoader(\n (requests: readonly AuthorizePermissionRequest[]) =>\n this.permissions.authorize(requests.slice(), options),\n {\n // Serialize the permission name and resourceRef as\n // a query string to avoid collisions from overlapping\n // permission names and resourceRefs.\n cacheKeyFn: ({ permission: { name }, resourceRef }) =>\n qs.stringify({ name, resourceRef }),\n },\n );\n\n const requestedTypes = query.types || Object.keys(this.types);\n\n const typeDecisions = zipObject(\n requestedTypes,\n await Promise.all(\n requestedTypes.map(type => {\n const permission = this.types[type]?.visibilityPermission;\n\n // No permission configured for this document type - always allow.\n if (!permission) {\n return { result: AuthorizeResult.ALLOW as const };\n }\n\n // Resource permission supplied, so we need to check for conditional decisions.\n if (isResourcePermission(permission)) {\n return conditionFetcher.load({ permission });\n }\n\n // Non-resource permission supplied - we can perform a standard authorization.\n return authorizer.load({ permission });\n }),\n ),\n );\n\n const authorizedTypes = requestedTypes.filter(\n type => typeDecisions[type]?.result !== AuthorizeResult.DENY,\n );\n\n const resultByResultFilteringRequired = authorizedTypes.some(\n type => typeDecisions[type]?.result === AuthorizeResult.CONDITIONAL,\n );\n\n // When there are no CONDITIONAL decisions for any of the requested\n // result types, we can skip filtering result by result by simply\n // skipping the types the user is not permitted to see, which will\n // be much more efficient.\n //\n // Since it's not currently possible to configure the page size used\n // by search engines, this detail means that a single user might see\n // a different page size depending on whether their search required\n // result-by-result filtering or not. We can fix this minor\n // inconsistency by introducing a configurable page size.\n //\n // cf. https://github.com/backstage/backstage/issues/9162\n if (!resultByResultFilteringRequired) {\n return this.searchEngine.query(\n { ...query, types: authorizedTypes },\n options,\n );\n }\n\n const { page } = decodePageCursor(query.pageCursor);\n const targetResults = (page + 1) * this.pageSize;\n\n let filteredResults: IndexableResult[] = [];\n let nextPageCursor: string | undefined;\n let latencyBudgetExhausted = false;\n\n do {\n const nextPage = await this.searchEngine.query(\n { ...query, types: authorizedTypes, pageCursor: nextPageCursor },\n options,\n );\n\n filteredResults = filteredResults.concat(\n await this.filterResults(nextPage.results, typeDecisions, authorizer),\n );\n\n nextPageCursor = nextPage.nextPageCursor;\n latencyBudgetExhausted =\n Date.now() - queryStartTime > this.queryLatencyBudgetMs;\n } while (\n nextPageCursor &&\n filteredResults.length < targetResults &&\n !latencyBudgetExhausted\n );\n\n return {\n results: filteredResults\n .slice(page * this.pageSize, (page + 1) * this.pageSize)\n .map((result, index) => {\n // Overwrite any/all rank entries to avoid leaking knowledge of filtered results.\n return {\n ...result,\n rank: page * this.pageSize + index + 1,\n };\n }),\n previousPageCursor:\n page === 0 ? undefined : encodePageCursor({ page: page - 1 }),\n nextPageCursor:\n !latencyBudgetExhausted &&\n (nextPageCursor || filteredResults.length > targetResults)\n ? encodePageCursor({ page: page + 1 })\n : undefined,\n };\n }\n\n private async filterResults(\n results: IndexableResult[],\n typeDecisions: Record<string, EvaluatePermissionResponse>,\n authorizer: DataLoader<\n EvaluatePermissionRequest,\n EvaluatePermissionResponse\n >,\n ) {\n return compact(\n await Promise.all(\n results.map(result => {\n if (typeDecisions[result.type]?.result === AuthorizeResult.ALLOW) {\n return result;\n }\n\n const permission = this.types[result.type]?.visibilityPermission;\n const resourceRef = result.document.authorization?.resourceRef;\n\n if (!permission || !resourceRef) {\n return result;\n }\n\n // We only reach this point in the code for types where the initial\n // authorization returned CONDITIONAL -- ALLOWs return early\n // immediately above, and types where the decision was DENY get\n // filtered out entirely when querying.\n //\n // This means the call to isResourcePermission here is mostly about\n // narrowing the type of permission - the only way to get here with a\n // non-resource permission is if the PermissionPolicy returns a\n // CONDITIONAL decision for a non-resource permission, which can't\n // happen - it would throw an error during validation in the\n // permission-backend.\n if (!isResourcePermission(permission)) {\n throw new Error(\n `Unexpected conditional decision returned for non-resource permission \"${permission.name}\"`,\n );\n }\n\n return authorizer\n .load({ permission, resourceRef })\n .then(decision =>\n decision.result === AuthorizeResult.ALLOW ? result : undefined,\n );\n }),\n ),\n );\n }\n}\n","/*\n * Copyright 2021 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 express from 'express';\nimport Router from 'express-promise-router';\nimport { Logger } from 'winston';\nimport { z } from 'zod';\nimport { errorHandler } from '@backstage/backend-common';\nimport { ErrorResponseBody, InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport { JsonObject, JsonValue } from '@backstage/types';\nimport { getBearerTokenFromAuthorizationHeader } from '@backstage/plugin-auth-node';\nimport {\n PermissionAuthorizer,\n PermissionEvaluator,\n toPermissionEvaluator,\n} from '@backstage/plugin-permission-common';\nimport {\n DocumentTypeInfo,\n IndexableResultSet,\n SearchResultSet,\n} from '@backstage/plugin-search-common';\nimport { SearchEngine } from '@backstage/plugin-search-common';\nimport { AuthorizedSearchEngine } from './AuthorizedSearchEngine';\n\nconst jsonObjectSchema: z.ZodSchema<JsonObject> = z.lazy(() => {\n const jsonValueSchema: z.ZodSchema<JsonValue> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(jsonValueSchema),\n jsonObjectSchema,\n ]),\n );\n\n return z.record(jsonValueSchema);\n});\n\n/**\n * @public\n */\nexport type RouterOptions = {\n engine: SearchEngine;\n types: Record<string, DocumentTypeInfo>;\n permissions: PermissionEvaluator | PermissionAuthorizer;\n config: Config;\n logger: Logger;\n};\n\nconst allowedLocationProtocols = ['http:', 'https:'];\n\n/**\n * @public\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { engine: inputEngine, types, permissions, config, logger } = options;\n\n const requestSchema = z.object({\n term: z.string().default(''),\n filters: jsonObjectSchema.optional(),\n types: z\n .array(z.string().refine(type => Object.keys(types).includes(type)))\n .optional(),\n pageCursor: z.string().optional(),\n });\n\n let permissionEvaluator: PermissionEvaluator;\n if ('authorizeConditional' in permissions) {\n permissionEvaluator = permissions as PermissionEvaluator;\n } else {\n logger.warn(\n 'PermissionAuthorizer is deprecated. Please use an instance of PermissionEvaluator instead of PermissionAuthorizer in PluginEnvironment#permissions',\n );\n permissionEvaluator = toPermissionEvaluator(permissions);\n }\n\n const engine = config.getOptionalBoolean('permission.enabled')\n ? new AuthorizedSearchEngine(\n inputEngine,\n types,\n permissionEvaluator,\n config,\n )\n : inputEngine;\n\n const filterResultSet = ({ results, ...resultSet }: SearchResultSet) => ({\n ...resultSet,\n results: results.filter(result => {\n const protocol = new URL(result.document.location, 'https://example.com')\n .protocol;\n const isAllowed = allowedLocationProtocols.includes(protocol);\n if (!isAllowed) {\n logger.info(\n `Rejected search result for \"${result.document.title}\" as location protocol \"${protocol}\" is unsafe`,\n );\n }\n return isAllowed;\n }),\n });\n\n const toSearchResults = (resultSet: IndexableResultSet): SearchResultSet => ({\n ...resultSet,\n results: resultSet.results.map(result => ({\n ...result,\n document: {\n ...result.document,\n authorization: undefined,\n },\n })),\n });\n\n const router = Router();\n router.get(\n '/query',\n async (\n req: express.Request,\n res: express.Response<SearchResultSet | ErrorResponseBody>,\n ) => {\n const parseResult = requestSchema.safeParse(req.query);\n\n if (!parseResult.success) {\n throw new InputError(`Invalid query string: ${parseResult.error}`);\n }\n\n const query = parseResult.data;\n\n logger.info(\n `Search request received: term=\"${\n query.term\n }\", filters=${JSON.stringify(query.filters)}, types=${\n query.types ? query.types.join(',') : ''\n }, pageCursor=${query.pageCursor ?? ''}`,\n );\n\n const token = getBearerTokenFromAuthorizationHeader(\n req.header('authorization'),\n );\n\n try {\n const resultSet = await engine?.query(query, { token });\n\n res.send(filterResultSet(toSearchResults(resultSet)));\n } catch (error) {\n if (error.name === 'MissingIndexError') {\n // re-throw and let the default error handler middleware captures it and serializes it with the right response code on the standard form\n throw error;\n }\n\n throw new Error(\n `There was a problem performing the search query. ${error}`,\n );\n }\n },\n );\n\n router.use(errorHandler());\n\n return router;\n}\n"],"names":["InputError","DataLoader","qs","zipObject","AuthorizeResult","isResourcePermission","compact","z","toPermissionEvaluator","Router","getBearerTokenFromAuthorizationHeader","errorHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCO,SAAS,iBAAiB,UAAuC,EAAA;AACtE,EAAA,IAAI,CAAC,UAAY,EAAA;AACf,IAAO,OAAA,EAAE,MAAM,CAAE,EAAA,CAAA;AAAA,GACnB;AAEA,EAAM,MAAA,IAAA,GAAO,OAAO,MAAO,CAAA,IAAA,CAAK,YAAY,QAAQ,CAAA,CAAE,QA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AAA;AAEtC,UAAM,MAAA,KAAA,CAAA;AAAA,SACR;AAEA,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAoD,iDAAA,EAAA,KAAA,CAAA,CAAA;AAAA,SACtD,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GACF,CAAA;AAEA,EAAO,MAAA,CAAA,GAAA,CAAIC,4BAAc,CAAA,CAAA;AAEzB,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/service/AuthorizedSearchEngine.ts","../src/service/router.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 { compact, zipObject } from 'lodash';\nimport qs from 'qs';\nimport DataLoader from 'dataloader';\nimport {\n EvaluatePermissionResponse,\n EvaluatePermissionRequest,\n AuthorizeResult,\n isResourcePermission,\n PermissionEvaluator,\n AuthorizePermissionRequest,\n QueryPermissionRequest,\n} from '@backstage/plugin-permission-common';\nimport {\n DocumentTypeInfo,\n IndexableResult,\n IndexableResultSet,\n QueryRequestOptions,\n QueryTranslator,\n SearchEngine,\n SearchQuery,\n} from '@backstage/plugin-search-common';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport { Writable } from 'stream';\n\nexport function decodePageCursor(pageCursor?: string): { page: number } {\n if (!pageCursor) {\n return { page: 0 };\n }\n\n const page = Number(Buffer.from(pageCursor, 'base64').toString('utf-8'));\n if (isNaN(page)) {\n throw new InputError('Invalid page cursor');\n }\n\n if (page < 0) {\n throw new InputError('Invalid page cursor');\n }\n\n return {\n page,\n };\n}\n\nexport function encodePageCursor({ page }: { page: number }): string {\n return Buffer.from(`${page}`, 'utf-8').toString('base64');\n}\n\nexport class AuthorizedSearchEngine implements SearchEngine {\n private readonly pageSize = 25;\n private readonly queryLatencyBudgetMs: number;\n\n constructor(\n private readonly searchEngine: SearchEngine,\n private readonly types: Record<string, DocumentTypeInfo>,\n private readonly permissions: PermissionEvaluator,\n config: Config,\n ) {\n this.queryLatencyBudgetMs =\n config.getOptionalNumber('search.permissions.queryLatencyBudgetMs') ??\n 1000;\n }\n\n setTranslator(translator: QueryTranslator): void {\n this.searchEngine.setTranslator(translator);\n }\n\n async getIndexer(type: string): Promise<Writable> {\n return this.searchEngine.getIndexer(type);\n }\n\n async query(\n query: SearchQuery,\n options: QueryRequestOptions,\n ): Promise<IndexableResultSet> {\n const queryStartTime = Date.now();\n\n const conditionFetcher = new DataLoader(\n (requests: readonly QueryPermissionRequest[]) =>\n this.permissions.authorizeConditional(requests.slice(), options),\n {\n cacheKeyFn: ({ permission: { name } }) => name,\n },\n );\n\n const authorizer = new DataLoader(\n (requests: readonly AuthorizePermissionRequest[]) =>\n this.permissions.authorize(requests.slice(), options),\n {\n // Serialize the permission name and resourceRef as\n // a query string to avoid collisions from overlapping\n // permission names and resourceRefs.\n cacheKeyFn: ({ permission: { name }, resourceRef }) =>\n qs.stringify({ name, resourceRef }),\n },\n );\n\n const requestedTypes = query.types || Object.keys(this.types);\n\n const typeDecisions = zipObject(\n requestedTypes,\n await Promise.all(\n requestedTypes.map(type => {\n const permission = this.types[type]?.visibilityPermission;\n\n // No permission configured for this document type - always allow.\n if (!permission) {\n return { result: AuthorizeResult.ALLOW as const };\n }\n\n // Resource permission supplied, so we need to check for conditional decisions.\n if (isResourcePermission(permission)) {\n return conditionFetcher.load({ permission });\n }\n\n // Non-resource permission supplied - we can perform a standard authorization.\n return authorizer.load({ permission });\n }),\n ),\n );\n\n const authorizedTypes = requestedTypes.filter(\n type => typeDecisions[type]?.result !== AuthorizeResult.DENY,\n );\n\n const resultByResultFilteringRequired = authorizedTypes.some(\n type => typeDecisions[type]?.result === AuthorizeResult.CONDITIONAL,\n );\n\n // When there are no CONDITIONAL decisions for any of the requested\n // result types, we can skip filtering result by result by simply\n // skipping the types the user is not permitted to see, which will\n // be much more efficient.\n //\n // Since it's not currently possible to configure the page size used\n // by search engines, this detail means that a single user might see\n // a different page size depending on whether their search required\n // result-by-result filtering or not. We can fix this minor\n // inconsistency by introducing a configurable page size.\n //\n // cf. https://github.com/backstage/backstage/issues/9162\n if (!resultByResultFilteringRequired) {\n return this.searchEngine.query(\n { ...query, types: authorizedTypes },\n options,\n );\n }\n\n const { page } = decodePageCursor(query.pageCursor);\n const targetResults = (page + 1) * this.pageSize;\n\n let filteredResults: IndexableResult[] = [];\n let nextPageCursor: string | undefined;\n let latencyBudgetExhausted = false;\n\n do {\n const nextPage = await this.searchEngine.query(\n { ...query, types: authorizedTypes, pageCursor: nextPageCursor },\n options,\n );\n\n filteredResults = filteredResults.concat(\n await this.filterResults(nextPage.results, typeDecisions, authorizer),\n );\n\n nextPageCursor = nextPage.nextPageCursor;\n latencyBudgetExhausted =\n Date.now() - queryStartTime > this.queryLatencyBudgetMs;\n } while (\n nextPageCursor &&\n filteredResults.length < targetResults &&\n !latencyBudgetExhausted\n );\n\n return {\n results: filteredResults\n .slice(page * this.pageSize, (page + 1) * this.pageSize)\n .map((result, index) => {\n // Overwrite any/all rank entries to avoid leaking knowledge of filtered results.\n return {\n ...result,\n rank: page * this.pageSize + index + 1,\n };\n }),\n previousPageCursor:\n page === 0 ? undefined : encodePageCursor({ page: page - 1 }),\n nextPageCursor:\n !latencyBudgetExhausted &&\n (nextPageCursor || filteredResults.length > targetResults)\n ? encodePageCursor({ page: page + 1 })\n : undefined,\n };\n }\n\n private async filterResults(\n results: IndexableResult[],\n typeDecisions: Record<string, EvaluatePermissionResponse>,\n authorizer: DataLoader<\n EvaluatePermissionRequest,\n EvaluatePermissionResponse\n >,\n ) {\n return compact(\n await Promise.all(\n results.map(result => {\n if (typeDecisions[result.type]?.result === AuthorizeResult.ALLOW) {\n return result;\n }\n\n const permission = this.types[result.type]?.visibilityPermission;\n const resourceRef = result.document.authorization?.resourceRef;\n\n if (!permission || !resourceRef) {\n return result;\n }\n\n // We only reach this point in the code for types where the initial\n // authorization returned CONDITIONAL -- ALLOWs return early\n // immediately above, and types where the decision was DENY get\n // filtered out entirely when querying.\n //\n // This means the call to isResourcePermission here is mostly about\n // narrowing the type of permission - the only way to get here with a\n // non-resource permission is if the PermissionPolicy returns a\n // CONDITIONAL decision for a non-resource permission, which can't\n // happen - it would throw an error during validation in the\n // permission-backend.\n if (!isResourcePermission(permission)) {\n throw new Error(\n `Unexpected conditional decision returned for non-resource permission \"${permission.name}\"`,\n );\n }\n\n return authorizer\n .load({ permission, resourceRef })\n .then(decision =>\n decision.result === AuthorizeResult.ALLOW ? result : undefined,\n );\n }),\n ),\n );\n }\n}\n","/*\n * Copyright 2021 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 express from 'express';\nimport Router from 'express-promise-router';\nimport { Logger } from 'winston';\nimport { z } from 'zod';\nimport { errorHandler } from '@backstage/backend-common';\nimport { ErrorResponseBody, InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport { JsonObject, JsonValue } from '@backstage/types';\nimport { getBearerTokenFromAuthorizationHeader } from '@backstage/plugin-auth-node';\nimport {\n PermissionAuthorizer,\n PermissionEvaluator,\n toPermissionEvaluator,\n} from '@backstage/plugin-permission-common';\nimport {\n DocumentTypeInfo,\n IndexableResultSet,\n SearchResultSet,\n} from '@backstage/plugin-search-common';\nimport { SearchEngine } from '@backstage/plugin-search-common';\nimport { AuthorizedSearchEngine } from './AuthorizedSearchEngine';\n\nconst jsonObjectSchema: z.ZodSchema<JsonObject> = z.lazy(() => {\n const jsonValueSchema: z.ZodSchema<JsonValue> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(jsonValueSchema),\n jsonObjectSchema,\n ]),\n );\n\n return z.record(jsonValueSchema);\n});\n\n/**\n * @public\n */\nexport type RouterOptions = {\n engine: SearchEngine;\n types: Record<string, DocumentTypeInfo>;\n permissions: PermissionEvaluator | PermissionAuthorizer;\n config: Config;\n logger: Logger;\n};\n\nconst maxPageLimit = 100;\nconst allowedLocationProtocols = ['http:', 'https:'];\n\n/**\n * @public\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { engine: inputEngine, types, permissions, config, logger } = options;\n\n const requestSchema = z.object({\n term: z.string().default(''),\n filters: jsonObjectSchema.optional(),\n types: z\n .array(z.string().refine(type => Object.keys(types).includes(type)))\n .optional(),\n pageCursor: z.string().optional(),\n pageLimit: z\n .string()\n .transform(pageLimit => parseInt(pageLimit, 10))\n .refine(\n pageLimit => !isNaN(pageLimit),\n pageLimit => ({\n message: `The page limit \"${pageLimit}\" is not a number`,\n }),\n )\n .refine(\n pageLimit => pageLimit <= maxPageLimit,\n pageLimit => ({\n message: `The page limit \"${pageLimit}\" is greater than \"${maxPageLimit}\"`,\n }),\n )\n .optional(),\n });\n\n let permissionEvaluator: PermissionEvaluator;\n if ('authorizeConditional' in permissions) {\n permissionEvaluator = permissions as PermissionEvaluator;\n } else {\n logger.warn(\n 'PermissionAuthorizer is deprecated. Please use an instance of PermissionEvaluator instead of PermissionAuthorizer in PluginEnvironment#permissions',\n );\n permissionEvaluator = toPermissionEvaluator(permissions);\n }\n\n const engine = config.getOptionalBoolean('permission.enabled')\n ? new AuthorizedSearchEngine(\n inputEngine,\n types,\n permissionEvaluator,\n config,\n )\n : inputEngine;\n\n const filterResultSet = ({ results, ...resultSet }: SearchResultSet) => ({\n ...resultSet,\n results: results.filter(result => {\n const protocol = new URL(result.document.location, 'https://example.com')\n .protocol;\n const isAllowed = allowedLocationProtocols.includes(protocol);\n if (!isAllowed) {\n logger.info(\n `Rejected search result for \"${result.document.title}\" as location protocol \"${protocol}\" is unsafe`,\n );\n }\n return isAllowed;\n }),\n });\n\n const toSearchResults = (resultSet: IndexableResultSet): SearchResultSet => ({\n ...resultSet,\n results: resultSet.results.map(result => ({\n ...result,\n document: {\n ...result.document,\n authorization: undefined,\n },\n })),\n });\n\n const router = Router();\n router.get(\n '/query',\n async (\n req: express.Request,\n res: express.Response<SearchResultSet | ErrorResponseBody>,\n ) => {\n const parseResult = requestSchema.passthrough().safeParse(req.query);\n\n if (!parseResult.success) {\n throw new InputError(`Invalid query string: ${parseResult.error}`);\n }\n\n const query = parseResult.data;\n\n logger.info(\n `Search request received: term=\"${\n query.term\n }\", filters=${JSON.stringify(query.filters)}, types=${\n query.types ? query.types.join(',') : ''\n }, pageCursor=${query.pageCursor ?? ''}`,\n );\n\n const token = getBearerTokenFromAuthorizationHeader(\n req.header('authorization'),\n );\n\n try {\n const resultSet = await engine?.query(query, { token });\n\n res.send(filterResultSet(toSearchResults(resultSet)));\n } catch (error) {\n if (error.name === 'MissingIndexError') {\n // re-throw and let the default error handler middleware captures it and serializes it with the right response code on the standard form\n throw error;\n }\n\n throw new Error(\n `There was a problem performing the search query. ${error}`,\n );\n }\n },\n );\n\n router.use(errorHandler());\n\n return router;\n}\n"],"names":["InputError","DataLoader","qs","zipObject","AuthorizeResult","isResourcePermission","compact","z","toPermissionEvaluator","Router","getBearerTokenFromAuthorizationHeader","errorHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCO,SAAS,iBAAiB,UAAuC,EAAA;AACtE,EAAA,IAAI,CAAC,UAAY,EAAA;AACf,IAAO,OAAA,EAAE,MAAM,CAAE,EAAA,CAAA;AAAA,GACnB;AAEA,EAAM,MA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A,QAAA,EAAA,KAAA,CAAM,KAAQ,GAAA,KAAA,CAAM,MAAM,IAAK,CAAA,GAAG,IAAI,EACxB,CAAA,aAAA,EAAA,CAAA,EAAA,GAAA,KAAA,CAAM,eAAN,IAAoB,GAAA,EAAA,GAAA,EAAA,CAAA,CAAA;AAAA,OACtC,CAAA;AAEA,MAAA,MAAM,KAAQ,GAAAU,oDAAA;AAAA,QACZ,GAAA,CAAI,OAAO,eAAe,CAAA;AAAA,OAC5B,CAAA;AAEA,MAAI,IAAA;AACF,QAAA,MAAM,YAAY,OAAM,MAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,MAAA,CAAQ,KAAM,CAAA,KAAA,EAAO,EAAE,KAAM,EAAA,CAAA,CAAA,CAAA;AAErD,QAAA,GAAA,CAAI,IAAK,CAAA,eAAA,CAAgB,eAAgB,CAAA,SAAS,CAAC,CAAC,CAAA,CAAA;AAAA,eAC7C,KAAP,EAAA;AACA,QAAI,IAAA,KAAA,CAAM,SAAS,mBAAqB,EAAA;AAEtC,UAAM,MAAA,KAAA,CAAA;AAAA,SACR;AAEA,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAoD,iDAAA,EAAA,KAAA,CAAA,CAAA;AAAA,SACtD,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GACF,CAAA;AAEA,EAAO,MAAA,CAAA,GAAA,CAAIC,4BAAc,CAAA,CAAA;AAEzB,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-search-backend",
|
|
3
3
|
"description": "The Backstage backend plugin that provides your backstage app with search",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.1.0-next.1",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"clean": "backstage-cli package clean"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@backstage/backend-common": "^0.15.1",
|
|
27
|
-
"@backstage/config": "^1.0.
|
|
28
|
-
"@backstage/errors": "^1.1.1",
|
|
29
|
-
"@backstage/plugin-auth-node": "^0.2.
|
|
30
|
-
"@backstage/plugin-permission-common": "^0.6.
|
|
31
|
-
"@backstage/plugin-permission-node": "^0.6.
|
|
32
|
-
"@backstage/plugin-search-backend-node": "^1.0.
|
|
33
|
-
"@backstage/plugin-search-common": "^1.0.1",
|
|
26
|
+
"@backstage/backend-common": "^0.15.2-next.1",
|
|
27
|
+
"@backstage/config": "^1.0.3-next.1",
|
|
28
|
+
"@backstage/errors": "^1.1.2-next.1",
|
|
29
|
+
"@backstage/plugin-auth-node": "^0.2.6-next.1",
|
|
30
|
+
"@backstage/plugin-permission-common": "^0.6.5-next.1",
|
|
31
|
+
"@backstage/plugin-permission-node": "^0.6.6-next.1",
|
|
32
|
+
"@backstage/plugin-search-backend-node": "^1.0.3-next.1",
|
|
33
|
+
"@backstage/plugin-search-common": "^1.1.0-next.1",
|
|
34
34
|
"@backstage/types": "^1.0.0",
|
|
35
35
|
"@types/express": "^4.17.6",
|
|
36
36
|
"dataloader": "^2.0.0",
|
|
@@ -43,12 +43,11 @@
|
|
|
43
43
|
"zod": "^3.11.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@backstage/cli": "^0.
|
|
46
|
+
"@backstage/cli": "^0.20.0-next.1",
|
|
47
47
|
"@types/supertest": "^2.0.8",
|
|
48
48
|
"supertest": "^6.1.3"
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
51
|
"dist"
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
}
|
|
52
|
+
]
|
|
53
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2020 The Backstage Authors
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|