csit-microcks-backend-backstage-plugin 0.1.1-main.c822a801
Install from the command line:
Learn more about npm packages
$ npm install @bcgov/csit-microcks-backend-backstage-plugin@0.1.1-main.c822a801
Install via package.json:
"@bcgov/csit-microcks-backend-backstage-plugin": "0.1.1-main.c822a801"
About this version
This Backstage backend plugin synchronizes API mocks defined in a repository into a Microcks server.
The plugin reads configuration from catalog entities, determines the desired state of mocks, and reconciles Microcks so that the correct mock services exist.
The system is intentionally designed to be deterministic, observable, and fail fast.
Install the plugin in your Backstage backend.
yarn add @bcgov/csit-microcks-backend-backstage-plugin
Register the plugin in your backend.
Example (packages/backend/src/index.ts):
backend.add(import('@bcgov/csit-microcks-backend-backstage-plugin'));
Restart the backend after installing the plugin.
Backstage app-config.yaml must define a Microcks server.
Example:
csitMicrocks:
server:
baseUrl: https://csit-microcks-apps-gov-bc-ca.dev.api.gov.bc.ca
auth:
type: keycloak
issuerUrl: https://authz-b8840c-dev.apps.gold.devops.gov.bc.ca/auth/realms/aps
clientId: devhub-microcks-sync
clientSecret: ${BACKSTAGE_MICROCKS_CLIENT_SECRET}
If this configuration is missing:
- The processor continues queuing jobs
- The worker will not claim jobs
The backend plugin authenticates to Microcks using the OAuth 2.0 client credentials flow via Keycloak.
A Keycloak confidential client with a service account must be created so the plugin can obtain access tokens.
Recommended client id:
devhub-microcks-sync
The client id is configurable in app-config.yaml.
The service client must be granted the role:
microcks-app → manager
This role allows the plugin to perform Microcks operations such as importing artifacts and managing services.
Create the client in the same Keycloak realm used by Microcks.
- Open the Keycloak Admin Console
- Select the Microcks realm
- Navigate to Clients
- Click Create client
Configure:
Client ID
devhub-microcks-sync
Client Type
OpenID Connect
Click Next.
Enable the following settings:
- Client authentication
- Service accounts roles
Save the client.
- Open the client you created
- Navigate to the Credentials tab
- Copy the Client Secret
Store the secret securely. It should not be committed to source control.
- Open the client
- Navigate to Service Account Roles
- Change the filter to Filter by clients
- Select:
microcks-app
- Assign the role:
manager
The service client can now perform Microcks management operations.
Catalog entities enable Microcks synchronization using the annotation:
bcgov/microcks-config-ref
Example:
metadata:
annotations:
bcgov/microcks-config-ref: ./microcks.yaml
The referenced file defines one or more mocks.
Example structure:
spec:
mocks:
- mockId: default
openapi:
path: openapi.yaml
artifacts:
- kind: examples
path: examples
Artifacts may reference:
- local repository paths
- URLs
Multiple mocks per API are supported.
flowchart LR
A[Backstage Catalog Entity] --> B[CsitMicrocksProcessor]
B --> C[(csit_microcks_sync_status)]
C --> D[MicrocksSyncWorker]
D --> E[MicrocksSyncJobRunner]
E --> F[MicrocksDesiredStateLoader]
E --> G[MicrocksReconciler]
E --> H[MicrocksClient]
F --> I[Repository Artifacts]
H --> J[Microcks Server]
B --> K[(csit_microcks_sync_events)]
E --> K- A catalog entity references a
microcks.yamlfile. - The Catalog Processor reads this file and records desired sync state.
- The Background Worker polls the database for pending jobs.
- Each job is executed by the Job Runner.
- The job runner loads artifacts, reconciles Microcks services, and records events.
Both the processor and worker emit events for observability.
This section describes what happens when a developer updates microcks.yaml in a repository.
Understanding this flow helps when debugging synchronization behavior.
A developer modifies the mock configuration referenced by a catalog entity.
Example changes:
- add a new mock
- update OpenAPI
- add example responses
- remove a mock
The change is committed to the repository.
During the next catalog refresh:
CsitMicrocksProcessor
runs for the entity.
The processor:
- Detects the annotation
bcgov/microcks-config-ref
- Loads the
microcks.yamlfile. - Parses mock definitions.
- Computes a fingerprint hash of inputs.
- Upserts rows in:
csit_microcks_sync_status
| Scenario | Result |
|---|---|
| New mock | desired_action = reconcile |
| Updated configuration | desired_action = reconcile |
| Removed mock | desired_action = delete |
| No changes | no new job created |
The processor does not communicate with Microcks.
Its responsibility is to determine desired state and record synchronization jobs.
Processor activity is also recorded in the event table for observability.
Example record:
| field | value |
|---|---|
| entity_ref | component:default/my-api |
| mock_id | default |
| desired_action | reconcile |
| microcks_version_id | bk-8ad514d6fc316e04-default |
| status | pending |
The record waits to be claimed by the worker.
MicrocksSyncWorker periodically polls the database.
The worker:
- checks configuration
- verifies global backoff is not active
- claims a job using a lease
claimNextPending()
The job status transitions to leased.
Execution is delegated to:
MicrocksSyncJobRunner
The runner performs the following steps.
MicrocksDesiredStateLoader
Loads:
- OpenAPI specification
- example artifacts
- metadata
Artifacts may come from:
- repository files
- URLs
Ownership is determined using:
bk-<entityHash>
Example:
bk-8ad514d6fc316e04-*
MicrocksReconciler determines:
- services owned by the entity
- exact version matches
- services to delete
- whether action is
createorupdate
Artifacts are uploaded using:
MicrocksClient.uploadArtifacts()
Before upload:
MicrocksArtifactIdentityStamper
injects deterministic identity metadata.
Any services owned by the entity that are not part of the desired version set are deleted.
This ensures:
Microcks always reflects the desired configuration
If successful:
status = completed
The worker records events in:
csit_microcks_sync_events
Example events:
- reconcile_started
- artifact_upload_started
- artifact_upload_finished
- reconcile_finished
Microcks service versions are deterministic.
Format
bk-<entityHash>-<mockId>
Example
bk-8ad514d6fc316e04-default
bk-8ad514d6fc316e04-swagger
bk-8ad514d6fc316e04-sdpr
Ownership of services is determined by the prefix:
bk-<entityHash>
Reconciliation is handled by:
MicrocksReconciler
The worker ensures that only the desired versions exist in Microcks.
If desired state cannot be loaded:
- A failure event is recorded
- Microcks services owned by the failed mock are deleted
- The sync record is marked
error
Tracks synchronization jobs.
| Field | Description |
|---|---|
| id | primary key |
| entity_ref | Backstage entity reference |
| mock_id | mock identifier |
| desired_action | reconcile or delete |
| microcks_version_id | deterministic Microcks version |
| fingerprint_hash | processor fingerprint |
| status | pending, completed, error |
Stores detailed sync history.
| Field | Description |
|---|---|
| entity_ref | entity reference |
| mock_id | mock identifier |
| sync_status_id | sync record id |
| event_type | event category |
| level | info or error |
| message | event message |
| Class | Responsibility |
|---|---|
CsitMicrocksProcessor |
Reads entity configuration and queues sync jobs |
MicrocksSyncWorker |
Polls database and orchestrates job execution |
MicrocksSyncJobRunner |
Executes a single sync job |
MicrocksDesiredStateLoader |
Loads artifacts |
MicrocksClient |
Communicates with the Microcks API |
MicrocksReconciler |
Determines required actions |
MicrocksTokenProvider |
Handles authentication tokens |
MicrocksArtifactIdentityStamper |
Injects deterministic artifact identity |
MicrocksSyncStore |
Database access layer |
Microcks service versions derive from entity identity and mockId.
Invalid configuration immediately removes owned mocks.
Service ownership is determined by the entity version prefix.
All actions emit events to csit_microcks_sync_events.
Worker orchestration, job execution, reconciliation, and storage are separated into focused classes.
Details
- csit-microcks-backend-backstage-plugin
-
bcgov
- 4 months ago
- Apache-2.0
- 14 dependencies
Assets
- csit-microcks-backend-backstage-plugin-0.1.1-main.c822a801.tgz
Download activity
- Total downloads 4
- Last 30 days 0
- Last week 0
- Today 0
Recent versions
View all- 0.1.1-main.c822a801
- 0.1.0-feature.aps-4105-connect-pipelines.86dd1a72
- 0.1.0-feature.aps-4105-connect-pipelines.b0745ca4
- 0.1.0-feature.aps-4105-connect-pipelines.063bfdb8
- 0.1.0-feature.aps-4105-connect-pipelines.b885fab5
- 0.1.0-feature.aps-4105-connect-pipelines.4049db97
- 0.1.0-feature.aps-4105-connect-pipelines.80c00df3
- 0.1.1-main.fc7ba821
- 0.1.0-feature.aps-devops.c571e26d
- 0.1.0-feature.aps-devops.94d8fd78