@kumori/aurora-backend-handler 1.0.114 → 1.0.116
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.
|
@@ -5,6 +5,9 @@ import { decodeRegistryAuth } from "../utils/utils";
|
|
|
5
5
|
|
|
6
6
|
type ResourceType = "domain" | "port" | "secret" | "certificate" | "ca" | "volume";
|
|
7
7
|
|
|
8
|
+
const isPlatformManaged = (eventData: any): boolean =>
|
|
9
|
+
eventData.meta?.labels?.["kumori/controller"] === "certcontroller";
|
|
10
|
+
|
|
8
11
|
interface HandleResourceEventParams {
|
|
9
12
|
kind: ResourceType;
|
|
10
13
|
eventData: any;
|
|
@@ -224,6 +227,9 @@ export const handleResourceEvent = ({
|
|
|
224
227
|
default:
|
|
225
228
|
throw new Error(`Unknown resource kind: ${kind}`);
|
|
226
229
|
}
|
|
230
|
+
if (isPlatformManaged(eventData)) {
|
|
231
|
+
resource.axebowManaged = true;
|
|
232
|
+
}
|
|
227
233
|
const tenant = tenantsMap.get(tenantId);
|
|
228
234
|
let tenantFound = false;
|
|
229
235
|
let updatedTenant: Tenant | null = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumori/aurora-backend-handler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.116",
|
|
4
4
|
"description": "backend handler",
|
|
5
5
|
"main": "backend-handler.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"glob": "^11.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@kumori/aurora-interfaces": "
|
|
14
|
+
"@kumori/aurora-interfaces": "1.0.34",
|
|
15
15
|
"@kumori/kumori-dsl-generator": "1.0.11",
|
|
16
16
|
"@kumori/kumori-module-generator": "^1.1.6",
|
|
17
17
|
"ts-node": "^10.9.2",
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Tenant } from '@kumori/aurora-interfaces';
|
|
2
|
+
import {
|
|
3
|
+
handleCertificateEvent,
|
|
4
|
+
handleDomainEvent,
|
|
5
|
+
handleSecretEvent,
|
|
6
|
+
} from '../helpers/resource-helper';
|
|
7
|
+
|
|
8
|
+
const buildTenantsMap = () => {
|
|
9
|
+
const tenant = { name: 'tenant1', resources: [] } as unknown as Tenant;
|
|
10
|
+
return new Map<string, Tenant>([['tenant1', tenant]]);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const parentParts = { tenant: 'tenant1' };
|
|
14
|
+
|
|
15
|
+
const buildCertificateEvent = (labels?: Record<string, string>) => ({
|
|
16
|
+
id: { name: 'cert1' },
|
|
17
|
+
spec: { certificate: { cert: 'CERT', key: 'KEY', domain: 'example.com' } },
|
|
18
|
+
meta: labels ? { labels } : {},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('resource-helper axebowManaged', () => {
|
|
22
|
+
it('marca el certificado como gestionado por la plataforma cuando el controller es certcontroller', () => {
|
|
23
|
+
const tenantsMap = buildTenantsMap();
|
|
24
|
+
|
|
25
|
+
const result = handleCertificateEvent(
|
|
26
|
+
buildCertificateEvent({ 'kumori/controller': 'certcontroller' }),
|
|
27
|
+
parentParts,
|
|
28
|
+
tenantsMap,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(result.resource.axebowManaged).toBe(true);
|
|
32
|
+
expect(tenantsMap.get('tenant1')!.resources[0].axebowManaged).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('no marca el flag cuando el evento no lleva labels', () => {
|
|
36
|
+
const result = handleCertificateEvent(
|
|
37
|
+
buildCertificateEvent(),
|
|
38
|
+
parentParts,
|
|
39
|
+
buildTenantsMap(),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(result.resource.axebowManaged).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('no marca el flag cuando el controller es distinto de certcontroller', () => {
|
|
46
|
+
const result = handleCertificateEvent(
|
|
47
|
+
buildCertificateEvent({
|
|
48
|
+
'kumori/controller': 'othercontroller',
|
|
49
|
+
certNameWUI: 'my-cert',
|
|
50
|
+
}),
|
|
51
|
+
parentParts,
|
|
52
|
+
buildTenantsMap(),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(result.resource.axebowManaged).toBeUndefined();
|
|
56
|
+
expect(result.resource.certName).toBe('my-cert');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('aplica el flag a cualquier tipo de resource, no solo a certificados', () => {
|
|
60
|
+
const labels = { 'kumori/controller': 'certcontroller' };
|
|
61
|
+
|
|
62
|
+
const secretResult = handleSecretEvent(
|
|
63
|
+
{ id: { name: 'secret1' }, spec: { secret: 'plain' }, meta: { labels } },
|
|
64
|
+
parentParts,
|
|
65
|
+
buildTenantsMap(),
|
|
66
|
+
new Map(),
|
|
67
|
+
);
|
|
68
|
+
const domainResult = handleDomainEvent(
|
|
69
|
+
{ id: { name: 'domain1' }, spec: { domain: 'example.com' }, meta: { labels } },
|
|
70
|
+
parentParts,
|
|
71
|
+
buildTenantsMap(),
|
|
72
|
+
false,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(secretResult.resource.axebowManaged).toBe(true);
|
|
76
|
+
expect(domainResult.resource.axebowManaged).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('mantiene el flag al actualizar un resource existente', () => {
|
|
80
|
+
const tenantsMap = buildTenantsMap();
|
|
81
|
+
const event = buildCertificateEvent({ 'kumori/controller': 'certcontroller' });
|
|
82
|
+
|
|
83
|
+
handleCertificateEvent(event, parentParts, tenantsMap);
|
|
84
|
+
const update = handleCertificateEvent(event, parentParts, tenantsMap, true);
|
|
85
|
+
|
|
86
|
+
expect(update.publishUpdate).toBe(true);
|
|
87
|
+
expect(tenantsMap.get('tenant1')!.resources).toHaveLength(1);
|
|
88
|
+
expect(tenantsMap.get('tenant1')!.resources[0].axebowManaged).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|