-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnections.ts
50 lines (44 loc) · 1.25 KB
/
connections.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import isEmpty from 'lodash/isEmpty'
import { ServiceConnection } from '@cloudgraph/sdk'
import { V1Namespace } from '@kubernetes/client-node'
import services from '../../enums/services'
import plurals from '../../enums/pluralization'
/**
* Service Account
*/
export default ({
service: namespace,
data,
}: {
data: { name: string; context: string; data: any[] }[]
service: V1Namespace
}): { [key: string]: ServiceConnection[] } => {
const connections: ServiceConnection[] = []
const {
metadata: {
uid: id,
name
}
} = namespace
// Find all non-namespace services
const serviceData = data.filter(({ name: serviceName }) => serviceName !== services.namespace)
if (!isEmpty(serviceData)) {
for (const entity of serviceData) {
const servicesToConnect = entity.data.filter(val => val?.metadata?.namespace === name)
if (!isEmpty(servicesToConnect)) {
for (const service of servicesToConnect) {
connections.push({
id: service.metadata?.uid,
resourceType: entity.name,
relation: 'child',
field: plurals[entity.name] ?? entity.name
})
}
}
}
}
const namespaceResult = {
[id]: connections,
}
return namespaceResult
}