Skip to content

Commit

Permalink
catalog-model: deprecate ENTITY_DEFAULT_NAMESPACE, replace with DEFAU…
Browse files Browse the repository at this point in the history
…LT_NAMESPACE

Signed-off-by: Johan Haals <johan.haals@gmail.com>
  • Loading branch information
jhaals committed Feb 15, 2022
1 parent 1c9891e commit 7aeb491
Show file tree
Hide file tree
Showing 37 changed files with 108 additions and 91 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-bees-join.md
@@ -0,0 +1,5 @@
---
'@backstage/catalog-model': patch
---

Deprecates `ENTITY_DEFAULT_NAMESPACE` constant in favour of `DEFAULT_NAMESPACE`.
18 changes: 18 additions & 0 deletions .changeset/three-roses-swim.md
@@ -0,0 +1,18 @@
---
'@backstage/techdocs-common': patch
'@backstage/plugin-auth-backend': patch
'@backstage/plugin-badges': patch
'@backstage/plugin-badges-backend': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-catalog-graph': patch
'@backstage/plugin-catalog-react': patch
'@backstage/plugin-cost-insights': patch
'@backstage/plugin-ilert': patch
'@backstage/plugin-org': patch
'@backstage/plugin-pagerduty': patch
'@backstage/plugin-search': patch
'@backstage/plugin-techdocs-backend': patch
---

Replace use of deprecated `ENTITY_DEFAULT_NAMESPACE` constant with `DEFAULT_NAMESPACE`.
5 changes: 4 additions & 1 deletion packages/catalog-model/api-report.md
Expand Up @@ -97,6 +97,9 @@ export { ComponentEntityV1alpha1 };
// @public
export const componentEntityV1alpha1Validator: KindValidator;

// @public
export const DEFAULT_NAMESPACE = 'default';

// @public
export class DefaultNamespaceEntityPolicy implements EntityPolicy {
constructor(namespace?: string);
Expand Down Expand Up @@ -133,7 +136,7 @@ export type Entity = {
relations?: EntityRelation[];
};

// @public
// @public @deprecated
export const ENTITY_DEFAULT_NAMESPACE = 'default';

// @public @deprecated
Expand Down
8 changes: 8 additions & 0 deletions packages/catalog-model/src/entity/constants.ts
Expand Up @@ -18,9 +18,17 @@
* The namespace that entities without an explicit namespace fall into.
*
* @public
* @deprecated use {@link DEFAULT_NAMESPACE} instead.
*/
export const ENTITY_DEFAULT_NAMESPACE = 'default';

/**
* The namespace that entities without an explicit namespace fall into.
*
* @public
*/
export const DEFAULT_NAMESPACE = 'default';

/**
* The keys of EntityMeta that are auto-generated.
*
Expand Down
1 change: 1 addition & 0 deletions packages/catalog-model/src/entity/index.ts
Expand Up @@ -17,6 +17,7 @@
export {
EDIT_URL_ANNOTATION,
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
ENTITY_META_GENERATED_FIELDS,
VIEW_URL_ANNOTATION,
ANNOTATION_EDIT_URL,
Expand Down
4 changes: 2 additions & 2 deletions packages/techdocs-common/src/stages/publish/awsS3.test.ts
Expand Up @@ -15,7 +15,7 @@
*/

import { getVoidLogger } from '@backstage/backend-common';
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import request from 'supertest';
Expand All @@ -34,7 +34,7 @@ const getEntityRootDir = (entity: Entity) => {
metadata: { namespace, name },
} = entity;

return path.join(rootDir, namespace || ENTITY_DEFAULT_NAMESPACE, kind, name);
return path.join(rootDir, namespace || DEFAULT_NAMESPACE, kind, name);
};

const logger = getVoidLogger();
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/

import { getVoidLogger } from '@backstage/backend-common';
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import request from 'supertest';
Expand All @@ -34,7 +34,7 @@ const getEntityRootDir = (entity: Entity) => {
metadata: { namespace, name },
} = entity;

return path.join(rootDir, namespace || ENTITY_DEFAULT_NAMESPACE, kind, name);
return path.join(rootDir, namespace || DEFAULT_NAMESPACE, kind, name);
};

const logger = getVoidLogger();
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/

import { getVoidLogger } from '@backstage/backend-common';
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import request from 'supertest';
Expand All @@ -34,7 +34,7 @@ const getEntityRootDir = (entity: Entity) => {
metadata: { namespace, name },
} = entity;

return path.join(rootDir, namespace || ENTITY_DEFAULT_NAMESPACE, kind, name);
return path.join(rootDir, namespace || DEFAULT_NAMESPACE, kind, name);
};

const logger = getVoidLogger();
Expand Down
4 changes: 2 additions & 2 deletions packages/techdocs-common/src/stages/publish/helpers.test.ts
Expand Up @@ -16,7 +16,7 @@
import mockFs from 'mock-fs';
import * as os from 'os';
import * as path from 'path';
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import {
getStaleFiles,
getFileTreeRecursively,
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('getCloudPathForLocalPath', () => {
localPath,
);
expect(remoteBucket).toBe(
`${ENTITY_DEFAULT_NAMESPACE}/component/backstage/${localPath}`,
`${DEFAULT_NAMESPACE}/component/backstage/${localPath}`,
);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/techdocs-common/src/stages/publish/helpers.ts
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import mime from 'mime-types';
import path from 'path';
import createLimiter from 'p-limit';
Expand Down Expand Up @@ -188,9 +188,9 @@ export const getCloudPathForLocalPath = (
const relativeFilePathPosix = localPath.split(path.sep).join(path.posix.sep);

// The / delimiter is intentional since it represents the cloud storage and not the local file system.
const entityRootDir = `${
entity.metadata?.namespace ?? ENTITY_DEFAULT_NAMESPACE
}/${entity.kind}/${entity.metadata.name}`;
const entityRootDir = `${entity.metadata?.namespace ?? DEFAULT_NAMESPACE}/${
entity.kind
}/${entity.metadata.name}`;

const relativeFilePathTriplet = `${entityRootDir}/${relativeFilePathPosix}`;

Expand Down
Expand Up @@ -18,7 +18,7 @@ import { getVoidLogger } from '@backstage/backend-common';
import {
Entity,
EntityName,
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
} from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import express from 'express';
Expand Down Expand Up @@ -59,7 +59,7 @@ const getEntityRootDir = (entity: Entity) => {
metadata: { namespace, name },
} = entity;

return path.join(rootDir, namespace || ENTITY_DEFAULT_NAMESPACE, kind, name);
return path.join(rootDir, namespace || DEFAULT_NAMESPACE, kind, name);
};

const getPosixEntityRootDir = (entity: Entity) => {
Expand All @@ -70,7 +70,7 @@ const getPosixEntityRootDir = (entity: Entity) => {

return path.posix.join(
'/rootDir',
namespace || ENTITY_DEFAULT_NAMESPACE,
namespace || DEFAULT_NAMESPACE,
kind,
name,
);
Expand Down
4 changes: 2 additions & 2 deletions plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts
Expand Up @@ -18,7 +18,7 @@ import express, { CookieOptions } from 'express';
import crypto from 'crypto';
import { URL } from 'url';
import {
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
parseEntityRef,
stringifyEntityRef,
} from '@backstage/catalog-model';
Expand Down Expand Up @@ -271,7 +271,7 @@ export class OAuthAdapter implements AuthProviderRouteHandlers {
const userEntityRef = stringifyEntityRef(
parseEntityRef(identity.id, {
defaultKind: 'user',
defaultNamespace: ENTITY_DEFAULT_NAMESPACE,
defaultNamespace: DEFAULT_NAMESPACE,
}),
);
const token = await this.options.tokenIssuer.issueToken({
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/

import {
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
parseEntityRef,
stringifyEntityRef,
} from '@backstage/catalog-model';
Expand Down Expand Up @@ -44,7 +44,7 @@ export function prepareBackstageIdentityResponse(
const userEntityRef = stringifyEntityRef(
parseEntityRef(sub, {
defaultKind: 'user',
defaultNamespace: ENTITY_DEFAULT_NAMESPACE,
defaultNamespace: DEFAULT_NAMESPACE,
}),
);
return {
Expand Down
8 changes: 4 additions & 4 deletions plugins/badges-backend/src/badges.ts
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { InputError } from '@backstage/errors';
import { Badge, BadgeContext, BadgeFactories } from './types';

Expand All @@ -24,9 +24,9 @@ function appTitle(context: BadgeContext): string {

function entityUrl(context: BadgeContext): string {
const e = context.entity!;
const entityUri = `${e.metadata.namespace || ENTITY_DEFAULT_NAMESPACE}/${
e.kind
}/${e.metadata.name}`;
const entityUri = `${e.metadata.namespace || DEFAULT_NAMESPACE}/${e.kind}/${
e.metadata.name
}`;
const catalogUrl = `${context.config.getString('app.baseUrl')}/catalog`;
return `${catalogUrl}/${entityUri}`.toLowerCase();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/badges/src/api/BadgesClient.ts
Expand Up @@ -16,7 +16,7 @@

import { generatePath } from 'react-router';
import { ResponseError } from '@backstage/errors';
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { BadgesApi, BadgeSpec } from './types';
import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';

Expand Down Expand Up @@ -63,7 +63,7 @@ export class BadgesClient implements BadgesApi {
kind: entity.kind.toLocaleLowerCase('en-US'),
namespace:
entity.metadata.namespace?.toLocaleLowerCase('en-US') ??
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
name: entity.metadata.name,
};
}
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { Entity, DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import { buildEntitySearch, mapToRows, traverse } from './buildEntitySearch';

describe('buildEntitySearch', () => {
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('buildEntitySearch', () => {
{
entity_id: 'eid',
key: 'metadata.namespace',
value: ENTITY_DEFAULT_NAMESPACE,
value: DEFAULT_NAMESPACE,
},
]);
});
Expand All @@ -157,7 +157,7 @@ describe('buildEntitySearch', () => {
{
entity_id: 'eid',
key: 'metadata.namespace',
value: ENTITY_DEFAULT_NAMESPACE,
value: DEFAULT_NAMESPACE,
},
{ entity_id: 'eid', key: 'relations.t1', value: 'k:ns/a' },
{ entity_id: 'eid', key: 'relations.t2', value: 'k:ns/b' },
Expand Down
4 changes: 2 additions & 2 deletions plugins/catalog-backend/src/stitching/buildEntitySearch.ts
Expand Up @@ -16,7 +16,7 @@

import {
Entity,
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
stringifyEntityRef,
} from '@backstage/catalog-model';
import { InputError } from '@backstage/errors';
Expand Down Expand Up @@ -174,7 +174,7 @@ export function buildEntitySearch(
// Namespace not specified has the default value "default", so we want to
// match on that as well
if (!entity.metadata.namespace) {
raw.push({ key: 'metadata.namespace', value: ENTITY_DEFAULT_NAMESPACE });
raw.push({ key: 'metadata.namespace', value: DEFAULT_NAMESPACE });
}

// Visit relations
Expand Down
4 changes: 2 additions & 2 deletions plugins/catalog-graph/dev/index.tsx
Expand Up @@ -17,7 +17,7 @@ import { GetEntitiesResponse } from '@backstage/catalog-client';
import {
Entity,
EntityName,
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
RELATION_API_CONSUMED_BY,
RELATION_API_PROVIDED_BY,
RELATION_CONSUMES_API,
Expand Down Expand Up @@ -117,7 +117,7 @@ const entities = (
name,
},
relations: relations.map(([type, k, n]) => ({
target: { kind: k, name: n, namespace: ENTITY_DEFAULT_NAMESPACE },
target: { kind: k, name: n, namespace: DEFAULT_NAMESPACE },
type,
})),
};
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import {
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
stringifyEntityRef,
} from '@backstage/catalog-model';
import { MouseEvent, useState } from 'react';
Expand Down Expand Up @@ -77,7 +77,7 @@ export function useEntityRelationNodesAndEdges({
title: entity.metadata?.title ?? undefined,
kind: entity.kind,
name: entity.metadata.name,
namespace: entity.metadata.namespace ?? ENTITY_DEFAULT_NAMESPACE,
namespace: entity.metadata.namespace ?? DEFAULT_NAMESPACE,
focused,
color: focused ? 'secondary' : 'primary',
};
Expand Down
Expand Up @@ -17,7 +17,7 @@
import {
Entity,
EntityName,
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
} from '@backstage/catalog-model';
import React, { forwardRef } from 'react';
import { entityRouteRef } from '../../routes';
Expand Down Expand Up @@ -66,8 +66,7 @@ export const EntityRefLink = forwardRef<any, EntityRefLinkProps>(

const routeParams = {
kind,
namespace:
namespace?.toLocaleLowerCase('en-US') ?? ENTITY_DEFAULT_NAMESPACE,
namespace: namespace?.toLocaleLowerCase('en-US') ?? DEFAULT_NAMESPACE,
name,
};
const formattedEntityRefTitle = formatEntityRefTitle(entityRef, {
Expand Down
4 changes: 2 additions & 2 deletions plugins/catalog-react/src/components/EntityRefLink/format.ts
Expand Up @@ -17,7 +17,7 @@
import {
Entity,
EntityName,
ENTITY_DEFAULT_NAMESPACE,
DEFAULT_NAMESPACE,
} from '@backstage/catalog-model';

export function formatEntityRefTitle(
Expand All @@ -39,7 +39,7 @@ export function formatEntityRefTitle(
name = entityRef.name;
}

if (namespace === ENTITY_DEFAULT_NAMESPACE) {
if (namespace === DEFAULT_NAMESPACE) {
namespace = undefined;
}

Expand Down

0 comments on commit 7aeb491

Please sign in to comment.