feat: add spec definition api with versioning
All checks were successful
arcad/emissary/pipeline/head This commit looks good
arcad/emissary/pipeline/pr-master This commit looks good

This commit is contained in:
2024-03-12 16:22:35 +01:00
parent 0b34b485da
commit f612721b4e
69 changed files with 1468 additions and 273 deletions

View File

@ -11,7 +11,7 @@ import (
var schema []byte
func init() {
if err := spec.Register(NameUCI, schema); err != nil {
if err := spec.Register(string(Name), Version, schema); err != nil {
panic(errors.WithStack(err))
}
}

View File

@ -1,5 +1,5 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://uci.emissary.cadoles.com/spec.json",
"title": "UCISpec",
"description": "Emissary 'UCI' specification",
@ -15,7 +15,9 @@
}
}
},
"required": ["packages"],
"required": [
"packages"
],
"additionalProperties": false
},
"postImportCommands": {
@ -33,12 +35,18 @@
}
}
},
"required": ["command", "args"],
"required": [
"command",
"args"
],
"additionalProperties": false
}
}
},
"required": ["config", "postImportCommands"],
"required": [
"config",
"postImportCommands"
],
"additionalProperties": false,
"$defs": {
"package": {
@ -54,7 +62,10 @@
}
}
},
"required": ["name", "configs"],
"required": [
"name",
"configs"
],
"additionalProperties": false
},
"config": {
@ -74,11 +85,15 @@
"$ref": "#/$defs/option"
}
},
{ "type": "null" }
{
"type": "null"
}
]
}
},
"required": ["name"],
"required": [
"name"
],
"additionalProperties": false
},
"option": {
@ -86,7 +101,10 @@
"properties": {
"type": {
"type": "string",
"enum": ["list", "option"]
"enum": [
"list",
"option"
]
},
"name": {
"type": "string"
@ -95,7 +113,11 @@
"type": "string"
}
},
"required": ["type", "name", "value"],
"required": [
"type",
"name",
"value"
],
"additionalProperties": false
}
}

View File

@ -5,7 +5,10 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/spec"
)
const NameUCI spec.Name = "uci.emissary.cadoles.com"
const (
Name string = "uci.emissary.cadoles.com"
Version string = "0.0.0"
)
type Spec struct {
Revision int `json:"revision"`
@ -18,8 +21,12 @@ type UCIPostImportCommand struct {
Args []string `json:"args"`
}
func (s *Spec) SpecName() spec.Name {
return NameUCI
func (s *Spec) SpecDefinitionName() string {
return Name
}
func (s *Spec) SpecDefinitionVersion() string {
return Version
}
func (s *Spec) SpecRevision() int {

View File

@ -3,9 +3,10 @@ package uci
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"
"forge.cadoles.com/Cadoles/emissary/internal/datastore/memory"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/pkg/errors"
)
@ -32,17 +33,21 @@ var validatorTestCases = []validatorTestCase{
func TestValidator(t *testing.T) {
t.Parallel()
validator := spec.NewValidator()
if err := validator.Register(NameUCI, schema); err != nil {
ctx := context.Background()
repo := memory.NewSpecDefinitionRepository()
if _, err := repo.Upsert(ctx, Name, Version, schema); err != nil {
t.Fatalf("+%v", errors.WithStack(err))
}
validator := spec.NewValidator(repo)
for _, tc := range validatorTestCases {
func(tc validatorTestCase) {
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
rawSpec, err := ioutil.ReadFile(tc.Source)
rawSpec, err := os.ReadFile(tc.Source)
if err != nil {
t.Fatalf("+%v", errors.WithStack(err))
}