@backstage/plugin-tech-insights-backend-module-jsonfc
Advanced tools
Comparing version 0.1.49 to 0.1.50
# @backstage/plugin-tech-insights-backend-module-jsonfc | ||
## 0.1.50 | ||
### Patch Changes | ||
- c2112f2: These packages have been migrated to the [backstage/community-plugins](https://github.com/backstage/community-plugins) repository. | ||
- Updated dependencies | ||
- @backstage/plugin-tech-insights-common@0.2.13 | ||
- @backstage/plugin-tech-insights-node@0.6.1 | ||
- @backstage/backend-common@0.21.7 | ||
- @backstage/backend-plugin-api@0.6.17 | ||
- @backstage/config@1.2.0 | ||
- @backstage/errors@1.2.4 | ||
- @backstage/types@1.1.1 | ||
## 0.1.49 | ||
@@ -4,0 +18,0 @@ |
{ | ||
"name": "@backstage/plugin-tech-insights-backend-module-jsonfc", | ||
"version": "0.1.49", | ||
"version": "0.1.50", | ||
"backstage": { | ||
"role": "backend-plugin-module" | ||
"role": "backend-plugin-module", | ||
"moved": "@backstage-community/plugin-tech-insights-backend-module-jsonfc" | ||
}, | ||
@@ -44,4 +45,4 @@ "publishConfig": { | ||
"@backstage/errors": "^1.2.4", | ||
"@backstage/plugin-tech-insights-common": "^0.2.12", | ||
"@backstage/plugin-tech-insights-node": "^0.6.0", | ||
"@backstage/plugin-tech-insights-common": "^0.2.13", | ||
"@backstage/plugin-tech-insights-node": "^0.6.1", | ||
"@backstage/types": "^1.1.1", | ||
@@ -55,5 +56,6 @@ "ajv": "^8.10.0", | ||
"@backstage/backend-test-utils": "^0.3.7", | ||
"@backstage/cli": "^0.26.3" | ||
"@backstage/cli": "^0.26.4" | ||
}, | ||
"configSchema": "config.json" | ||
"configSchema": "config.json", | ||
"deprecated": "This package has been moved to the backstage/community-plugins repository. You should migrate to using @backstage-community/plugin-tech-insights-backend-module-jsonfc instead." | ||
} |
156
README.md
@@ -1,155 +0,3 @@ | ||
# Tech Insights Backend JSON Rules engine fact checker module | ||
# Deprecated | ||
This is an extension to module to tech-insights-backend plugin, which provides basic framework and functionality to implement tech insights within Backstage. | ||
This module provides functionality to run checks against a [json-rules-engine](https://github.com/CacheControl/json-rules-engine) and provide boolean logic by simply building checks using JSON conditions. | ||
## Getting started | ||
To add this FactChecker into your Tech Insights you need to install the module into your backend application: | ||
```bash | ||
# From your Backstage root directory | ||
yarn --cwd packages/backend add @backstage/plugin-tech-insights-backend-module-jsonfc | ||
``` | ||
### Add to the backend | ||
```ts title="packages/backend/src/index.ts" | ||
backend.add(import('@backstage/plugin-tech-insights-backend-module-jsonfc')); | ||
``` | ||
This setup requires checks to be provided using the config. | ||
### Add to the backend (old) | ||
Modify the `techInsights.ts` file to contain a reference to the FactCheckers implementation. | ||
```diff | ||
+import { JsonRulesEngineFactCheckerFactory } from '@backstage/plugin-tech-insights-backend-module-jsonfc'; | ||
+const myFactCheckerFactory = new JsonRulesEngineFactCheckerFactory({ | ||
+ checks: [], | ||
+ logger: env.logger, | ||
+}), | ||
const builder = buildTechInsightsContext({ | ||
logger: env.logger, | ||
config: env.config, | ||
database: env.database, | ||
discovery: env.discovery, | ||
tokenManager: env.tokenManager, | ||
factRetrievers: [myFactRetrieverRegistration], | ||
+ factCheckerFactory: myFactCheckerFactory | ||
}); | ||
``` | ||
By default, this implementation comes with an in-memory storage to store checks. You can inject an additional data store by adding an implementation of `TechInsightCheckRegistry` into the constructor options when creating a `JsonRulesEngineFactCheckerFactory`. That can be done as follows | ||
```diff | ||
const myTechInsightCheckRegistry: TechInsightCheckRegistry<MyCheckType> = // snip | ||
const myFactCheckerFactory = new JsonRulesEngineFactCheckerFactory({ | ||
checks: [], | ||
logger: env.logger, | ||
+ checkRegistry: myTechInsightCheckRegistry | ||
}), | ||
``` | ||
## Adding checks in code | ||
Checks for this FactChecker are constructed as [`json-rules-engine` compatible JSON rules](https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#conditions). A check could look like the following for example: | ||
```ts | ||
import { | ||
JSON_RULE_ENGINE_CHECK_TYPE, | ||
TechInsightJsonRuleCheck, | ||
} from '@backstage/plugin-tech-insights-backend-module-jsonfc'; | ||
export const exampleCheck: TechInsightJsonRuleCheck = { | ||
id: 'demodatacheck', // Unique identifier of this check | ||
name: 'demodatacheck', // A human readable name of this check to be displayed in the UI | ||
type: JSON_RULE_ENGINE_CHECK_TYPE, // Type identifier of the check. Used to run logic against, determine persistence option to use and render correct components on the UI | ||
description: 'A fact check for demoing purposes', // A description to be displayed in the UI | ||
factIds: ['documentation-number-factretriever'], // References to fact ids that this check uses. See documentation on FactRetrievers for more information on these | ||
rule: { | ||
// The actual rule | ||
conditions: { | ||
all: [ | ||
// 2 options are available, all and any conditions. | ||
{ | ||
fact: 'examplenumberfact', // Reference to an individual fact to check against | ||
operator: 'greaterThanInclusive', // Operator to use. See: https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#operators for more | ||
value: 2, // The threshold value that the fact must satisfy | ||
}, | ||
], | ||
}, | ||
}, | ||
successMetadata: { | ||
// Additional metadata to be returned if the check has passed | ||
link: 'https://link.to.some.information.com', | ||
}, | ||
failureMetadata: { | ||
// Additional metadata to be returned if the check has failed | ||
link: 'https://sonar.mysonarqube.com/increasing-number-value', | ||
}, | ||
}; | ||
``` | ||
## Adding checks in config | ||
Example: | ||
```yaml title="app-config.yaml" | ||
techInsights: | ||
factChecker: | ||
checks: | ||
groupOwnerCheck: | ||
type: json-rules-engine | ||
name: Group Owner Check | ||
description: Verifies that a group has been set as the spec.owner for this entity | ||
factIds: | ||
- entityOwnershipFactRetriever | ||
rule: | ||
conditions: | ||
all: | ||
- fact: hasGroupOwner | ||
operator: equal | ||
value: true | ||
``` | ||
### More than one `factIds` for a check. | ||
When more than one is supplied, the requested fact **MUST** be present in at least one of the fact retrievers. | ||
The order of the fact retrievers defined in the `factIds` array has no bearing on the checks, the check will merge all facts from the various retrievers, and then check against latest fact . | ||
# Custom operators | ||
json-rules-engine supports a limited [number of built-in operators](https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#operators) that can be used in conditions. You can add your own operators by adding them to the `operators` array in the `JsonRulesEngineFactCheckerFactory` constructor. For example: | ||
```diff | ||
+ import { Operator } from 'json-rules-engine'; | ||
const myFactCheckerFactory = new JsonRulesEngineFactCheckerFactory({ | ||
checks: [], | ||
logger: env.logger, | ||
+ operators: [ new Operator("startsWith", (a, b) => a.startsWith(b) ] | ||
}) | ||
``` | ||
And you can then use it in your checks like this: | ||
```js | ||
... | ||
rule: { | ||
conditions: { | ||
any: [ | ||
{ | ||
fact: 'version', | ||
operator: 'startsWith', | ||
value: '12', | ||
}, | ||
], | ||
}, | ||
} | ||
``` | ||
This package has been moved to the [backstage-community/plugins](https://github.com/backstage/community-plugins) repository. Migrate to using `@backstage-community/plugin-tech-insights-backend-module-jsonfc` instead. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98433
1
4