2.0.1 • Published 8 months ago

@janus-idp/backstage-scaffolder-backend-module-annotator-dynamic v2.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

Annotator custom action for Scaffolder Backstage

The annotator module for @backstage/plugin-scaffolder-backend.

This module allows users to create custom actions for annotating their entity objects. Additionally, it enables users to utilize existing custom actions provided by the module for annotating entities with timestamps and scaffolder entity references.

Installation

Available custom actions

ActionDescription
catalog:timestampingAdds the backstage.io/createdAt annotation containing the current timestamp to your entity object
catalog:scaffolded-fromAdds scaffoldedFrom spec containing the template entityRef to your entity object
catalog:annotateAllows you to annotate your entity object with specified label(s), annotation(s) and spec property(ies)

To begin, install the module package into the backend workspace of your backstage instance:

yarn workspace backend add @janus-idp/backstage-scaffolder-backend-module-annotator

Registering the annotator action plugin with the backend system

To install the module into the backend system, add the following into the packages/backend/src/index.ts file:

const backend = createBackend();

// highlight-add-start
backend.add(import('@janus-idp/backstage-scaffolder-backend-module-annotator'));
// highlight-add-end

backend.start();

Creating custom actions for your templates using the annotator module

Create the custom action

The createAnnotatorAction action accepts the following parameters:

Parameter NameTypeRequiredDescription
actionIdstringYesA unique id for the action. Default: catalog:annotate, please provide one or else it may conflict with the generic catalog:annotate custom action that is provided by this module.
actionDescriptionstringNoA description of what the action accomplishes. Default: "Creates a new scaffolder action to annotate the entity object with specified label(s), annotation(s) and spec property(ies)."
loggerInfoMsgstringNoA message that will be logged upon the execution of the action. Default: "Annotating your object"
annotateEntityObject.labelsobjectNoKey-value pairs to be added to the metadata.labels of the entity
annotateEntityObject.annotationsobjectNoKey-value pairs to be added to the metadata.annotations of the entity
annotateEntityObject.specobjectNoKey-value pairs to be added to the spec of the entity. The value for each key can either be a string or an object with the key readFromContext, enabling users to specify the path in the context from which the value should be retrieved.
  1. Create your custom action

  2. Add the annotator module package @janus-idp/backstage-scaffolder-backend-module-annotator into your module's package.json

  3. In the action file, add the following snippet to it:

// highlight-add-start
import { createAnnotatorAction } from '@janus-idp/backstage-scaffolder-backend-module-annotator';

export const createAddCompanyTitleAction = () => {
  return createAnnotatorAction(
    'catalog:company-title',
    'Creates a new `catalog:company-title` Scaffolder action to annotate scaffolded entities with the company title.',
    'Annotating catalog-info.yaml with the company title',
  );
};
// highlight-add-end
  1. Install the custom action into your backstage instance following steps similar to the installation instructions above

Use your custom action in your desired template(s)

The annotator template action accepts the following inputs

Input

Parameter NameTypeRequiredDescription
labelsobjectNoKey-value pairs to be added to the metadata.labels of the entity
annotationsobjectNoKey-value pairs to be added to the metadata.annotations of the entity
specobjectNoKey-value pairs to be added to the spec of the entity
entityFilePathstringNoThe file path from which the YAML representation of the entity should be read
objectYamlobjectNoThe YAML representation of the object/entity
writeToFilestringNoThe file path where the YAML representation of the entity should be stored. Default value is './catalog-info.yaml'

Output

NameTypeDescription
annotatedObjectobjectThe entity object marked with your specified annotation(s), label(s), and spec property(ies)

To annotate the entity file, add your custom action to your template file after Fetch Skeleton + Template step. Please note that your custom action needs to be installed into the backstage instance running the software template.

// highlight-add-start
- id: company-title
  name: Add company title to catalog-info.yaml
  action: catalog:company-title
  input:
    labels: {
      company: 'My Company'
    }
// highlight-add-end
2.0.1

8 months ago

2.0.0

9 months ago

1.4.0

9 months ago

1.3.1

10 months ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.3.0

11 months ago

1.2.1

11 months ago

1.0.3

1 year ago

0.1.0

1 year ago