Expose catalogFactRetriever & configure in backend

Signed-off-by: Iain Billett <iain@roadie.io>
This commit is contained in:
Iain Billett
2021-11-15 18:27:48 +00:00
parent 5b31874a76
commit d4a3dbb75b
5 changed files with 40 additions and 49 deletions
@@ -25,3 +25,4 @@ export type {
export type { PersistenceContext } from './service/persistence/persistenceContext';
export { createFactRetrieverRegistration } from './service/fact/createFactRetriever';
export * from './service/fact/factRetrievers';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createEntityFactRetriever } from './entityFactRetriever';
import { createCatalogFactRetriever } from './catalogFactRetriever';
import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model';
import {
PluginEndpointDiscovery,
@@ -52,7 +52,7 @@ const defaultEntityListResponse: CatalogListResponse<Entity> = {
spec: {
type: 'service',
lifecycle: 'test',
owner: 'group:team-a',
owner: 'team-a',
},
relations: [
{
@@ -106,7 +106,7 @@ const handlerContext = {
config: ConfigReader.fromConfigs([]),
};
const entityFactRetriever = createEntityFactRetriever({
const entityFactRetriever = createCatalogFactRetriever({
annotations: ['backstage.io/techdocs-ref'],
});
@@ -14,18 +14,23 @@
* limitations under the License.
*/
import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node';
import {
FactRetriever,
FactRetrieverContext,
} from '@backstage/plugin-tech-insights-node';
import { CatalogClient } from '@backstage/catalog-client';
import { Entity } from '@backstage/catalog-model';
import isEmpty from 'lodash/isEmpty';
import camelCase from 'lodash/camelCase';
import { get } from 'lodash';
export const createEntityFactRetriever = ({
annotations = [],
}: {
type Options = {
annotations?: string[];
}) => ({
};
export const createCatalogFactRetriever = (
{ annotations = [] }: Options = { annotations: [] },
): FactRetriever => ({
id: 'entityRetriever',
version: '0.0.1',
schema: {
@@ -39,18 +44,18 @@ export const createEntityFactRetriever = ({
},
hasDescription: {
type: 'boolean',
description: 'The entity has an owned_by relation',
description: 'The entity has a description in metadata',
},
hasTags: {
type: 'boolean',
description: 'The entity has tags in metadata',
},
...annotations.reduce((acc: object, it: string) => {
...annotations.reduce((acc: object, annotation: string) => {
return {
...acc,
[camelCase(`hasAnnotation-${it}`)]: {
[camelCase(`hasAnnotation-${annotation}`)]: {
type: 'boolean',
description: `The entity has the annotation: ${it} `,
description: `The entity has the annotation: ${annotation} `,
},
};
}, {}),
@@ -72,7 +77,7 @@ export const createEntityFactRetriever = ({
hasOwner: Boolean(entity.spec?.owner),
hasGroupOwner: Boolean(
entity.spec?.owner &&
(entity.spec?.owner as string).startsWith('group:'),
!(entity.spec?.owner as string).startsWith('user:'),
),
hasDescription: Boolean(entity.metadata?.description),
hasTags: !isEmpty(entity.metadata?.tags),
@@ -0,0 +1,16 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './catalogFactRetriever';