Skip to content

Commit

Permalink
catalog-model: Prefix annotations with ANNOTATION_
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Haals <johan.haals@gmail.com>
  • Loading branch information
jhaals committed Feb 15, 2022
1 parent 80c627d commit 27eccab
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 115 deletions.
14 changes: 14 additions & 0 deletions .changeset/tasty-taxis-dance.md
@@ -0,0 +1,14 @@
---
'@backstage/catalog-client': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-catalog-backend-module-ldap': patch
'@backstage/plugin-catalog-backend-module-msgraph': patch
'@backstage/plugin-catalog-react': patch
'@backstage/plugin-github-deployments': patch
'@backstage/plugin-scaffolder-backend': patch
'@backstage/plugin-todo': patch
'@backstage/plugin-todo-backend': patch
---

Replaces use of deprecated catalog-model constants.
6 changes: 6 additions & 0 deletions .changeset/twenty-dodos-rule.md
@@ -0,0 +1,6 @@
---
'@backstage/catalog-model': patch
---

Deprecates `EDIT_URL_ANNOTATION`, `LOCATION_ANNOTATION`, `ORIGIN_LOCATION_ANNOTATION`, `SOURCE_LOCATION_ANNOTATION`, `VIEW_URL_ANNOTATION`
and replaces these constants all prefixed with ANNOTATION_ `ANNOTATION_EDIT_URL`, `ANNOTATION_LOCATION`, `ANNOTATION_ORIGIN_LOCATION`, `ANNOTATION_SOURCE_LOCATION`, `ANNOTATION_VIEW_URL`
8 changes: 4 additions & 4 deletions packages/catalog-client/src/CatalogClient.ts
Expand Up @@ -15,10 +15,10 @@
*/

import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
Entity,
EntityName,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
parseEntityRef,
stringifyEntityRef,
stringifyLocationRef,
Expand Down Expand Up @@ -253,7 +253,7 @@ export class CatalogClient implements CatalogApi {
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const locationCompound =
entity.metadata.annotations?.[ORIGIN_LOCATION_ANNOTATION];
entity.metadata.annotations?.[ANNOTATION_ORIGIN_LOCATION];
if (!locationCompound) {
return undefined;
}
Expand All @@ -274,7 +274,7 @@ export class CatalogClient implements CatalogApi {
entity: Entity,
options?: CatalogRequestOptions,
): Promise<Location | undefined> {
const locationCompound = entity.metadata.annotations?.[LOCATION_ANNOTATION];
const locationCompound = entity.metadata.annotations?.[ANNOTATION_LOCATION];
if (!locationCompound) {
return undefined;
}
Expand Down
26 changes: 21 additions & 5 deletions packages/catalog-model/api-report.md
Expand Up @@ -13,6 +13,22 @@ export interface AlphaEntity extends Entity {
status?: EntityStatus;
}

// @public
export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url';

// @public
export const ANNOTATION_LOCATION = 'backstage.io/managed-by-location';

// @public
export const ANNOTATION_ORIGIN_LOCATION =
'backstage.io/managed-by-origin-location';

// @public
export const ANNOTATION_SOURCE_LOCATION = 'backstage.io/source-location';

// @public
export const ANNOTATION_VIEW_URL = 'backstage.io/view-url';

// @public
interface ApiEntityV1alpha1 extends Entity {
// (undocumented)
Expand Down Expand Up @@ -105,7 +121,7 @@ export { DomainEntityV1alpha1 };
// @public
export const domainEntityV1alpha1Validator: KindValidator;

// @public
// @public @deprecated
export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url';

// @public
Expand Down Expand Up @@ -325,7 +341,7 @@ type Location_2 = {
} & LocationSpec;
export { Location_2 as Location };

// @public
// @public @deprecated
export const LOCATION_ANNOTATION = 'backstage.io/managed-by-location';

// @public
Expand Down Expand Up @@ -365,7 +381,7 @@ export class NoForeignRootFieldsEntityPolicy implements EntityPolicy {
enforce(entity: Entity): Promise<Entity>;
}

// @public
// @public @deprecated
export const ORIGIN_LOCATION_ANNOTATION =
'backstage.io/managed-by-origin-location';

Expand Down Expand Up @@ -489,7 +505,7 @@ export class SchemaValidEntityPolicy implements EntityPolicy {
enforce(entity: Entity): Promise<Entity>;
}

// @public
// @public @deprecated
export const SOURCE_LOCATION_ANNOTATION = 'backstage.io/source-location';

// @public
Expand Down Expand Up @@ -595,6 +611,6 @@ export type Validators = {
isValidTag(value: unknown): boolean;
};

// @public
// @public @deprecated
export const VIEW_URL_ANNOTATION = 'backstage.io/view-url';
```
16 changes: 16 additions & 0 deletions packages/catalog-model/src/entity/constants.ts
Expand Up @@ -37,12 +37,28 @@ export const ENTITY_META_GENERATED_FIELDS = [
* Annotation for linking to entity page from catalog pages.
*
* @public
* @deprecated use {@link ANNOTATION_VIEW_URL} instead.
*/
export const VIEW_URL_ANNOTATION = 'backstage.io/view-url';

/**
* Annotation for linking to entity edit page from catalog pages.
*
* @public
* @deprecated use {@link ANNOTATION_EDIT_URL} instead.
*/
export const EDIT_URL_ANNOTATION = 'backstage.io/edit-url';

/**
* Annotation for linking to entity page from catalog pages.
*
* @public
*/
export const ANNOTATION_VIEW_URL = 'backstage.io/view-url';

/**
* Annotation for linking to entity edit page from catalog pages.
*
* @public
*/
export const ANNOTATION_EDIT_URL = 'backstage.io/edit-url';
2 changes: 2 additions & 0 deletions packages/catalog-model/src/entity/index.ts
Expand Up @@ -19,6 +19,8 @@ export {
ENTITY_DEFAULT_NAMESPACE,
ENTITY_META_GENERATED_FIELDS,
VIEW_URL_ANNOTATION,
ANNOTATION_EDIT_URL,
ANNOTATION_VIEW_URL,
} from './constants';
export type {
AlphaEntity,
Expand Down
30 changes: 27 additions & 3 deletions packages/catalog-model/src/location/annotation.ts
Expand Up @@ -17,17 +17,41 @@
/**
* Constant storing location annotation.
*
* @public */
* @public
* @deprecated use {@link ANNOTATION_LOCATION} instead.
* */
export const LOCATION_ANNOTATION = 'backstage.io/managed-by-location';
/**
* Constant storing origin location annotation
*
* @public */
* @public
* @deprecated use {@link ANNOTATION_ORIGIN_LOCATION} instead.
*/
export const ORIGIN_LOCATION_ANNOTATION =
'backstage.io/managed-by-origin-location';

/**
* Contant storing source location annotation
*
* @public */
* @public
* @deprecated use {@link ANNOTATION_SOURCE_LOCATION} instead.
* */
export const SOURCE_LOCATION_ANNOTATION = 'backstage.io/source-location';

/**
* Constant storing location annotation.
*
* @public */
export const ANNOTATION_LOCATION = 'backstage.io/managed-by-location';
/**
* Constant storing origin location annotation
*
* @public */
export const ANNOTATION_ORIGIN_LOCATION =
'backstage.io/managed-by-origin-location';

/**
* Contant storing source location annotation
*
* @public */
export const ANNOTATION_SOURCE_LOCATION = 'backstage.io/source-location';
7 changes: 4 additions & 3 deletions packages/catalog-model/src/location/helpers.ts
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/

import { ANNOTATION_SOURCE_LOCATION } from '.';
import { Entity, stringifyEntityRef } from '../entity';
import { LOCATION_ANNOTATION, SOURCE_LOCATION_ANNOTATION } from './annotation';
import { ANNOTATION_LOCATION } from './annotation';

/**
* Parses a string form location reference.
Expand Down Expand Up @@ -142,8 +143,8 @@ export function getEntitySourceLocation(entity: Entity): {
target: string;
} {
const locationRef =
entity.metadata?.annotations?.[SOURCE_LOCATION_ANNOTATION] ??
entity.metadata?.annotations?.[LOCATION_ANNOTATION];
entity.metadata?.annotations?.[ANNOTATION_SOURCE_LOCATION] ??
entity.metadata?.annotations?.[ANNOTATION_LOCATION];

if (!locationRef) {
throw new Error(
Expand Down
3 changes: 3 additions & 0 deletions packages/catalog-model/src/location/index.ts
Expand Up @@ -15,6 +15,9 @@
*/

export {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
ANNOTATION_SOURCE_LOCATION,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
SOURCE_LOCATION_ANNOTATION,
Expand Down
Expand Up @@ -15,9 +15,9 @@
*/

import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
Entity,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
} from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import {
Expand Down Expand Up @@ -207,8 +207,8 @@ function withLocations(providerId: string, entity: Entity): Entity {
{
metadata: {
annotations: {
[LOCATION_ANNOTATION]: location,
[ORIGIN_LOCATION_ANNOTATION]: location,
[ANNOTATION_LOCATION]: location,
[ANNOTATION_ORIGIN_LOCATION]: location,
},
},
},
Expand Down
Expand Up @@ -15,9 +15,9 @@
*/
import { getVoidLogger } from '@backstage/backend-common';
import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
GroupEntity,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
UserEntity,
} from '@backstage/catalog-model';
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
Expand Down Expand Up @@ -162,8 +162,8 @@ describe('withLocations', () => {
name: 'u1',
annotations: {
[MICROSOFT_GRAPH_USER_ID_ANNOTATION]: 'uid',
[LOCATION_ANNOTATION]: 'msgraph:test/uid',
[ORIGIN_LOCATION_ANNOTATION]: 'msgraph:test/uid',
[ANNOTATION_LOCATION]: 'msgraph:test/uid',
[ANNOTATION_ORIGIN_LOCATION]: 'msgraph:test/uid',
},
},
spec: {
Expand Down
Expand Up @@ -15,9 +15,9 @@
*/

import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
Entity,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
} from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import {
Expand Down Expand Up @@ -180,8 +180,8 @@ export function withLocations(providerId: string, entity: Entity): Entity {
{
metadata: {
annotations: {
[LOCATION_ANNOTATION]: location,
[ORIGIN_LOCATION_ANNOTATION]: location,
[ANNOTATION_LOCATION]: location,
[ANNOTATION_ORIGIN_LOCATION]: location,
},
},
},
Expand Down
Expand Up @@ -15,14 +15,14 @@
*/

import {
EDIT_URL_ANNOTATION,
ANNOTATION_EDIT_URL,
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
ANNOTATION_SOURCE_LOCATION,
ANNOTATION_VIEW_URL,
Entity,
LocationSpec,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
SOURCE_LOCATION_ANNOTATION,
stringifyLocationRef,
VIEW_URL_ANNOTATION,
} from '@backstage/catalog-model';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { identity, merge, pickBy } from 'lodash';
Expand Down Expand Up @@ -70,12 +70,12 @@ export class AnnotateLocationEntityProcessor implements CatalogProcessor {
metadata: {
annotations: pickBy(
{
[LOCATION_ANNOTATION]: stringifyLocationRef(location),
[ORIGIN_LOCATION_ANNOTATION]:
[ANNOTATION_LOCATION]: stringifyLocationRef(location),
[ANNOTATION_ORIGIN_LOCATION]:
stringifyLocationRef(originLocation),
[VIEW_URL_ANNOTATION]: viewUrl,
[EDIT_URL_ANNOTATION]: editUrl,
[SOURCE_LOCATION_ANNOTATION]: sourceLocation,
[ANNOTATION_VIEW_URL]: viewUrl,
[ANNOTATION_EDIT_URL]: editUrl,
[ANNOTATION_SOURCE_LOCATION]: sourceLocation,
},
identity,
),
Expand Down
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/
import {
ANNOTATION_LOCATION,
ANNOTATION_ORIGIN_LOCATION,
Entity,
LOCATION_ANNOTATION,
ORIGIN_LOCATION_ANNOTATION,
} from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import {
Expand Down Expand Up @@ -178,8 +178,8 @@ export function withLocations(
{
metadata: {
annotations: {
[LOCATION_ANNOTATION]: location,
[ORIGIN_LOCATION_ANNOTATION]: location,
[ANNOTATION_LOCATION]: location,
[ANNOTATION_ORIGIN_LOCATION]: location,
},
},
},
Expand Down

0 comments on commit 27eccab

Please sign in to comment.