Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-hands-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dweber019/backstage-plugin-relations-backend': minor
---

fix: nested relations for entities will now be generated
2 changes: 1 addition & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ relationsProcessor:
- sourceKind: group
targetKinds:
- user
attribute: productOwner
attribute: nestedContact.productOwner
multi: false
pairs:
- incoming: productOwnerOf
Expand Down
3 changes: 2 additions & 1 deletion plugins/relations-backend/examples/group-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ spec:
members:
- john-doe
- kevin-po
productOwner: user:default/kevin-po
nestedContact:
productOwner: user:default/kevin-po
32 changes: 32 additions & 0 deletions plugins/relations-backend/src/processor/processorConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,38 @@ describe('processorConfig', () => {
expect(relations).toHaveLength(2);
});

test('should return relation for nested attribute', async () => {
const config = new ConfigReader({
relationsProcessor: {
relations: [
{
sourceKind: 'System',
attribute: 'contacts.technologyOwner',
pairs: [
{
incoming: 'technologyOwnerOf',
outgoing: 'technologyOwner',
},
],
},
],
},
});
const entity = {
kind: 'System',
spec: {
contacts: {
technologyOwner: 'user:default/john.doe',
},
},
} as unknown as Entity;

const processorConfig = new ProcessorConfig(config);
const relations = processorConfig.getRelations(entity);

expect(relations).toHaveLength(1);
});

test('should throw error for config errors', async () => {
const config = new ConfigReader({
relationsProcessor: {
Expand Down
3 changes: 2 additions & 1 deletion plugins/relations-backend/src/processor/processorConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config } from '@backstage/config';
import relationV1alpha1Schema from './Relation.v1alpha1.schema.json';
import { Entity } from '@backstage/catalog-model';
import { has } from 'lodash';

interface RelationConfig {
sourceKind: string;
Expand All @@ -25,7 +26,7 @@ export class ProcessorConfig {
return this.relations.filter(relation => {
return (
entity.kind.toLocaleLowerCase() === relation.sourceKind &&
entity.spec?.hasOwnProperty(relation.attribute) &&
has(entity.spec, relation.attribute) &&
(relation.sourceType === undefined ||
(entity.spec?.type &&
(entity.spec?.type as string).toLocaleLowerCase() ===
Expand Down