From ac853e2a5bab2ef5e55741b39f2626621b1f4e55 Mon Sep 17 00:00:00 2001 From: Fabio Pugliese Ornellas Date: Fri, 7 Jun 2024 14:23:42 +0100 Subject: [PATCH] add status structs --- backstage/entity.go | 43 ++++++++++++++++++++++++++++++++ backstage/testdata/entities.json | 39 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/backstage/entity.go b/backstage/entity.go index 303bc18..3d562a6 100644 --- a/backstage/entity.go +++ b/backstage/entity.go @@ -26,6 +26,9 @@ type Entity struct { // Relations that this entity has with other entities. Relations []EntityRelation `json:"relations,omitempty"` + + // The current status of the entity, as claimed by various sources. + Status *EntityStatus `json:"status,omitempty"` } // EntityMeta represents metadata fields common to all versions/kinds of entity. @@ -108,6 +111,46 @@ type EntityRelationTarget struct { Namespace string `json:"namespace"` } +// EntityStatus informs current status of the entity, as claimed by various sources. +// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json +type EntityStatus struct { + // A specific status item on a well known format. + Items []EntityStatusItem `json:"items,omitempty"` +} + +// EntityStatusItem contains a specific status item on a well known format. +// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json +type EntityStatusItem struct { + // The item type + Type string `json:"type"` + + // The status level / severity of the status item. + // Either ["info", "warning", "error"] + Level string `json:"level"` + + // A brief message describing the status, intended for human consumption. + Message string `json:"message"` + + // An optional serialized error object related to the status. + Error *EntityStatusItemError `json:"error"` +} + +// EntityStatusItemError has aA serialized error object. +// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json +type EntityStatusItemError struct { + // The type name of the error" + Name string `json:"name"` + + // The message of the error + Message string `json:"message"` + + // An error code associated with the error + Code *string `json:"code"` + + // An error stack trace + Stack *string `json:"stack"` +} + // ListEntityOrder defines a condition that can be used to order entities. type ListEntityOrder struct { // Direction is the direction to order by. diff --git a/backstage/testdata/entities.json b/backstage/testdata/entities.json index 39b3284..6cd4017 100644 --- a/backstage/testdata/entities.json +++ b/backstage/testdata/entities.json @@ -421,5 +421,44 @@ "relations":[ ] + }, + { + "metadata":{ + "namespace":"default", + "annotations":{ + "backstage.io/managed-by-location":"file:/private/tmp/back/examples/org.yaml", + "backstage.io/managed-by-origin-location":"file:/private/tmp/back/examples/org.yaml" + }, + "name":"generated-aa156660b91ff3cfa0819c08e413581e6d4e4136", + "uid":"f5e4edef-f547-430d-8fee-13f4919888b7", + "etag":"d9b5d5f05fe7901d90c68b62a9b2d30b3f9f0f87" + }, + "apiVersion":"backstage.io/v1alpha1", + "kind":"Location", + "spec":{ + "type":"file", + "target":"/private/tmp/back/examples/org.yaml" + }, + "relations":[ + + ], + "status": { + "items": [ + { + "type": "backstage.io/catalog-processing", + "level": "error", + "message": "SomeError: it broke", + "error": { + "name": "SomeError", + "message": "Error message", + "cause": { + "name": "Error", + "message": "error message", + "stack": "stack trace" + } + } + } + ] + } } ]