feat(catalog): add an ldap processor

This commit is contained in:
Fredrik Adelöw
2020-10-02 13:08:54 +02:00
parent 2d73c037a0
commit b9c8062c08
22 changed files with 1782 additions and 93 deletions
@@ -15,6 +15,7 @@
*/
import { ENTITY_DEFAULT_NAMESPACE } from './constants';
import { Entity } from './Entity';
import { parseEntityName, parseEntityRef, serializeEntityRef } from './ref';
describe('ref', () => {
@@ -333,6 +334,26 @@ describe('ref', () => {
expect(serializeEntityRef({ name: 'c' })).toEqual('c');
});
it('handles entities', () => {
const entityWithNamespace: Entity = {
apiVersion: 'a',
kind: 'b',
metadata: {
name: 'c',
namespace: 'd',
},
};
const entityWithoutNamespace: Entity = {
apiVersion: 'a',
kind: 'b',
metadata: {
name: 'c',
},
};
expect(serializeEntityRef(entityWithNamespace)).toEqual('b:d/c');
expect(serializeEntityRef(entityWithoutNamespace)).toEqual('b:c');
});
it('picks the least complex form', () => {
expect(
serializeEntityRef({ kind: 'a', namespace: 'b', name: 'c' }),
+23 -6
View File
@@ -160,12 +160,29 @@ export function parseEntityRef(
* @param ref The reference to serialize
* @returns The same reference on either string or compound form
*/
export function serializeEntityRef(ref: {
kind?: string;
namespace?: string;
name: string;
}): EntityRef {
const { kind, namespace, name } = ref;
export function serializeEntityRef(
ref:
| Entity
| {
kind?: string;
namespace?: string;
name: string;
},
): EntityRef {
let kind;
let namespace;
let name;
if ('apiVersion' in ref) {
kind = ref.kind;
namespace = ref.metadata.namespace;
name = ref.metadata.name;
} else {
kind = ref.kind;
namespace = ref.namespace;
name = ref.name;
}
if (
kind?.includes(':') ||
kind?.includes('/') ||