-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): initial implementation of entity validation
POC using versioned entity JSON schemas from the Backstage repo. Validation error output and overall configurability to be improved.
- Loading branch information
Showing
20 changed files
with
1,192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: backstage-go | ||
description: Backstage SDK for Go | ||
links: | ||
- url: https://pkg.go.dev/go.einride.tech/backstage | ||
title: GoDoc | ||
icon: docs | ||
spec: | ||
type: go-library | ||
lifecycle: production | ||
owner: team-cloud-control |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
|
||
"go.einride.tech/sage/sg" | ||
) | ||
|
||
func Schema(ctx context.Context) error { | ||
sg.Deps( | ||
ctx, | ||
sg.Fn(downloadSchema, "Entity.schema.json"), | ||
sg.Fn(downloadSchema, "EntityEnvelope.schema.json"), | ||
sg.Fn(downloadSchema, "EntityMeta.schema.json"), | ||
sg.Fn(downloadSchema, "shared/common.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/API.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/Component.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/Domain.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/Group.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/Location.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/Resource.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/System.v1alpha1.schema.json"), | ||
sg.Fn(downloadSchema, "kinds/User.v1alpha1.schema.json"), | ||
) | ||
return nil | ||
} | ||
|
||
func downloadSchema(ctx context.Context, path string) error { | ||
const version = "v1.12.1" | ||
url := fmt.Sprintf( | ||
"https://raw.githubusercontent.com/backstage/backstage/%s/packages/catalog-model/src/schema/%s", | ||
version, | ||
path, | ||
) | ||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) | ||
if err != nil { | ||
return err | ||
} | ||
response, err := http.DefaultClient.Do(request) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
_ = response.Body.Close() | ||
}() | ||
data, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return err | ||
} | ||
out := sg.FromGitRoot("cmd", "backstage", "internal", "schema", filepath.Base(path)) | ||
if err := os.WriteFile(out, data, 0o600); err != nil { | ||
return err | ||
} | ||
sg.Logger(ctx).Println("wrote schema", out) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "ApiV1alpha1", | ||
"description": "An API describes an interface that can be exposed by a component. The API can be defined in different formats, like OpenAPI, AsyncAPI, GraphQL, gRPC, or other formats.", | ||
"examples": [ | ||
{ | ||
"apiVersion": "backstage.io/v1alpha1", | ||
"kind": "API", | ||
"metadata": { | ||
"name": "artist-api", | ||
"description": "Retrieve artist details", | ||
"labels": { | ||
"product_name": "Random value Generator" | ||
}, | ||
"annotations": { | ||
"docs": "https://github.com/..../tree/develop/doc" | ||
} | ||
}, | ||
"spec": { | ||
"type": "openapi", | ||
"lifecycle": "production", | ||
"owner": "artist-relations-team", | ||
"system": "artist-engagement-portal", | ||
"definition": "openapi: \"3.0.0\"\ninfo:..." | ||
} | ||
} | ||
], | ||
"allOf": [ | ||
{ | ||
"$ref": "Entity" | ||
}, | ||
{ | ||
"type": "object", | ||
"required": ["spec"], | ||
"properties": { | ||
"apiVersion": { | ||
"enum": ["backstage.io/v1alpha1", "backstage.io/v1beta1"] | ||
}, | ||
"kind": { | ||
"enum": ["API"] | ||
}, | ||
"spec": { | ||
"type": "object", | ||
"required": ["type", "lifecycle", "owner", "definition"], | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"description": "The type of the API definition.", | ||
"examples": ["openapi", "asyncapi", "graphql", "grpc", "trpc"], | ||
"minLength": 1 | ||
}, | ||
"lifecycle": { | ||
"type": "string", | ||
"description": "The lifecycle state of the API.", | ||
"examples": ["experimental", "production", "deprecated"], | ||
"minLength": 1 | ||
}, | ||
"owner": { | ||
"type": "string", | ||
"description": "An entity reference to the owner of the API.", | ||
"examples": ["artist-relations-team", "user:john.johnson"], | ||
"minLength": 1 | ||
}, | ||
"system": { | ||
"type": "string", | ||
"description": "An entity reference to the system that the API belongs to.", | ||
"minLength": 1 | ||
}, | ||
"definition": { | ||
"type": "string", | ||
"description": "The definition of the API, based on the format defined by the type.", | ||
"minLength": 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
101 changes: 101 additions & 0 deletions
101
cmd/backstage/internal/schema/Component.v1alpha1.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "ComponentV1alpha1", | ||
"description": "A Component describes a software component. It is typically intimately linked to the source code that constitutes the component, and should be what a developer may regard a \"unit of software\", usually with a distinct deployable or linkable artifact.", | ||
"examples": [ | ||
{ | ||
"apiVersion": "backstage.io/v1alpha1", | ||
"kind": "Component", | ||
"metadata": { | ||
"name": "LoremService", | ||
"description": "Creates Lorems like a pro.", | ||
"labels": { | ||
"product_name": "Random value Generator" | ||
}, | ||
"annotations": { | ||
"docs": "https://github.com/..../tree/develop/doc" | ||
} | ||
}, | ||
"spec": { | ||
"type": "service", | ||
"lifecycle": "production", | ||
"owner": "tools" | ||
} | ||
} | ||
], | ||
"allOf": [ | ||
{ | ||
"$ref": "Entity" | ||
}, | ||
{ | ||
"type": "object", | ||
"required": ["spec"], | ||
"properties": { | ||
"apiVersion": { | ||
"enum": ["backstage.io/v1alpha1", "backstage.io/v1beta1"] | ||
}, | ||
"kind": { | ||
"enum": ["Component"] | ||
}, | ||
"spec": { | ||
"type": "object", | ||
"required": ["type", "lifecycle", "owner"], | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"description": "The type of component.", | ||
"examples": ["service", "website", "library"], | ||
"minLength": 1 | ||
}, | ||
"lifecycle": { | ||
"type": "string", | ||
"description": "The lifecycle state of the component.", | ||
"examples": ["experimental", "production", "deprecated"], | ||
"minLength": 1 | ||
}, | ||
"owner": { | ||
"type": "string", | ||
"description": "An entity reference to the owner of the component.", | ||
"examples": ["artist-relations-team", "user:john.johnson"], | ||
"minLength": 1 | ||
}, | ||
"system": { | ||
"type": "string", | ||
"description": "An entity reference to the system that the component belongs to.", | ||
"minLength": 1 | ||
}, | ||
"subcomponentOf": { | ||
"type": "string", | ||
"description": "An entity reference to another component of which the component is a part.", | ||
"minLength": 1 | ||
}, | ||
"providesApis": { | ||
"type": "array", | ||
"description": "An array of entity references to the APIs that are provided by the component.", | ||
"items": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"consumesApis": { | ||
"type": "array", | ||
"description": "An array of entity references to the APIs that are consumed by the component.", | ||
"items": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
}, | ||
"dependsOn": { | ||
"type": "array", | ||
"description": "An array of references to other entities that the component depends on to function.", | ||
"items": { | ||
"type": "string", | ||
"minLength": 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "DomainV1alpha1", | ||
"description": "A Domain groups a collection of systems that share terminology, domain models, business purpose, or documentation, i.e. form a bounded context.", | ||
"examples": [ | ||
{ | ||
"apiVersion": "backstage.io/v1alpha1", | ||
"kind": "Domain", | ||
"metadata": { | ||
"name": "artists", | ||
"description": "Everything about artists" | ||
}, | ||
"spec": { | ||
"owner": "artist-relations-team" | ||
} | ||
} | ||
], | ||
"allOf": [ | ||
{ | ||
"$ref": "Entity" | ||
}, | ||
{ | ||
"type": "object", | ||
"required": ["spec"], | ||
"properties": { | ||
"apiVersion": { | ||
"enum": ["backstage.io/v1alpha1", "backstage.io/v1beta1"] | ||
}, | ||
"kind": { | ||
"enum": ["Domain"] | ||
}, | ||
"spec": { | ||
"type": "object", | ||
"required": ["owner"], | ||
"properties": { | ||
"owner": { | ||
"type": "string", | ||
"description": "An entity reference to the owner of the component.", | ||
"examples": ["artist-relations-team", "user:john.johnson"], | ||
"minLength": 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.