Merge pull request #9753 from backstage/freben/no-default
remove usage of deprecated ENTITY_DEFAULT_NAMESPACE
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/catalog-model': patch
|
||||
---
|
||||
|
||||
Remove all usage of the deprecated `ENTITY_DEFAULT_NAMESPACE`
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import yaml from 'yaml';
|
||||
import { ENTITY_DEFAULT_NAMESPACE } from '../constants';
|
||||
import { DEFAULT_NAMESPACE } from '../constants';
|
||||
import { DefaultNamespaceEntityPolicy } from './DefaultNamespaceEntityPolicy';
|
||||
|
||||
describe('DefaultNamespaceEntityPolicy', () => {
|
||||
@@ -57,7 +57,7 @@ describe('DefaultNamespaceEntityPolicy', () => {
|
||||
expect.objectContaining({
|
||||
metadata: {
|
||||
name: 'my-component-yay',
|
||||
namespace: ENTITY_DEFAULT_NAMESPACE,
|
||||
namespace: DEFAULT_NAMESPACE,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import lodash from 'lodash';
|
||||
import { EntityPolicy } from './types';
|
||||
import { ENTITY_DEFAULT_NAMESPACE } from '../constants';
|
||||
import { DEFAULT_NAMESPACE } from '../constants';
|
||||
import { Entity } from '../Entity';
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ import { Entity } from '../Entity';
|
||||
export class DefaultNamespaceEntityPolicy implements EntityPolicy {
|
||||
private readonly namespace: string;
|
||||
|
||||
constructor(namespace: string = ENTITY_DEFAULT_NAMESPACE) {
|
||||
constructor(namespace: string = DEFAULT_NAMESPACE) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ENTITY_DEFAULT_NAMESPACE } from './constants';
|
||||
import { DEFAULT_NAMESPACE } from './constants';
|
||||
import { Entity } from './Entity';
|
||||
import { compareEntityToRef, parseEntityName, parseEntityRef } from './ref';
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('ref', () => {
|
||||
expect(() => parseEntityName('b/c')).toThrow(/kind/);
|
||||
expect(parseEntityName('a:c')).toEqual({
|
||||
kind: 'a',
|
||||
namespace: ENTITY_DEFAULT_NAMESPACE,
|
||||
namespace: DEFAULT_NAMESPACE,
|
||||
name: 'c',
|
||||
});
|
||||
expect(() => parseEntityName('c')).toThrow(/kind/);
|
||||
@@ -118,7 +118,7 @@ describe('ref', () => {
|
||||
).toEqual({ kind: 'a', namespace: 'y', name: 'c' });
|
||||
expect(parseEntityName('a:c', { defaultKind: 'x' })).toEqual({
|
||||
kind: 'a',
|
||||
namespace: ENTITY_DEFAULT_NAMESPACE,
|
||||
namespace: DEFAULT_NAMESPACE,
|
||||
name: 'c',
|
||||
});
|
||||
expect(
|
||||
@@ -126,7 +126,7 @@ describe('ref', () => {
|
||||
).toEqual({ kind: 'x', namespace: 'y', name: 'c' });
|
||||
expect(parseEntityName('c', { defaultKind: 'x' })).toEqual({
|
||||
kind: 'x',
|
||||
namespace: ENTITY_DEFAULT_NAMESPACE,
|
||||
namespace: DEFAULT_NAMESPACE,
|
||||
name: 'c',
|
||||
});
|
||||
});
|
||||
@@ -152,7 +152,7 @@ describe('ref', () => {
|
||||
).toEqual({ kind: 'a', namespace: 'y', name: 'c' });
|
||||
expect(
|
||||
parseEntityName({ kind: 'a', name: 'c' }, { defaultKind: 'x' }),
|
||||
).toEqual({ kind: 'a', namespace: ENTITY_DEFAULT_NAMESPACE, name: 'c' });
|
||||
).toEqual({ kind: 'a', namespace: DEFAULT_NAMESPACE, name: 'c' });
|
||||
expect(
|
||||
parseEntityName(
|
||||
{ name: 'c' },
|
||||
@@ -161,7 +161,7 @@ describe('ref', () => {
|
||||
).toEqual({ kind: 'x', namespace: 'y', name: 'c' });
|
||||
expect(parseEntityName({ name: 'c' }, { defaultKind: 'x' })).toEqual({
|
||||
kind: 'x',
|
||||
namespace: ENTITY_DEFAULT_NAMESPACE,
|
||||
namespace: DEFAULT_NAMESPACE,
|
||||
name: 'c',
|
||||
});
|
||||
// empty strings are errors, not defaults
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { EntityName, EntityRef } from '../types';
|
||||
import { ENTITY_DEFAULT_NAMESPACE } from './constants';
|
||||
import { DEFAULT_NAMESPACE } from './constants';
|
||||
import { Entity } from './Entity';
|
||||
|
||||
function parseRefString(ref: string): {
|
||||
@@ -48,7 +48,7 @@ function parseRefString(ref: string): {
|
||||
export function getEntityName(entity: Entity): EntityName {
|
||||
return {
|
||||
kind: entity.kind,
|
||||
namespace: entity.metadata.namespace || ENTITY_DEFAULT_NAMESPACE,
|
||||
namespace: entity.metadata.namespace || DEFAULT_NAMESPACE,
|
||||
name: entity.metadata.name,
|
||||
};
|
||||
}
|
||||
@@ -91,7 +91,7 @@ export function parseEntityName(
|
||||
} = {},
|
||||
): EntityName {
|
||||
const { kind, namespace, name } = parseEntityRef(ref, {
|
||||
defaultNamespace: ENTITY_DEFAULT_NAMESPACE,
|
||||
defaultNamespace: DEFAULT_NAMESPACE,
|
||||
...context,
|
||||
});
|
||||
|
||||
@@ -218,11 +218,11 @@ export function stringifyEntityRef(
|
||||
|
||||
if ('metadata' in ref) {
|
||||
kind = ref.kind;
|
||||
namespace = ref.metadata.namespace ?? ENTITY_DEFAULT_NAMESPACE;
|
||||
namespace = ref.metadata.namespace ?? DEFAULT_NAMESPACE;
|
||||
name = ref.metadata.name;
|
||||
} else {
|
||||
kind = ref.kind;
|
||||
namespace = ref.namespace ?? ENTITY_DEFAULT_NAMESPACE;
|
||||
namespace = ref.namespace ?? DEFAULT_NAMESPACE;
|
||||
name = ref.name;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ export function compareEntityToRef(
|
||||
},
|
||||
): boolean {
|
||||
const entityKind = entity.kind;
|
||||
const entityNamespace = entity.metadata.namespace || ENTITY_DEFAULT_NAMESPACE;
|
||||
const entityNamespace = entity.metadata.namespace || DEFAULT_NAMESPACE;
|
||||
const entityName = entity.metadata.name;
|
||||
|
||||
let refKind: string | undefined;
|
||||
@@ -268,12 +268,12 @@ export function compareEntityToRef(
|
||||
const parsed = parseRefString(ref);
|
||||
refKind = parsed.kind || context?.defaultKind;
|
||||
refNamespace =
|
||||
parsed.namespace || context?.defaultNamespace || ENTITY_DEFAULT_NAMESPACE;
|
||||
parsed.namespace || context?.defaultNamespace || DEFAULT_NAMESPACE;
|
||||
refName = parsed.name;
|
||||
} else {
|
||||
refKind = ref.kind || context?.defaultKind;
|
||||
refNamespace =
|
||||
ref.namespace || context?.defaultNamespace || ENTITY_DEFAULT_NAMESPACE;
|
||||
ref.namespace || context?.defaultNamespace || DEFAULT_NAMESPACE;
|
||||
refName = ref.name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user