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(NameProxy, 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://proxy.emissary.cadoles.com/spec.json",
"title": "ProxySpec",
"description": "Emissary 'Proxy' specification",
@ -26,16 +26,24 @@
"type": "string"
}
},
"required": ["hostPattern", "target"]
"required": [
"hostPattern",
"target"
]
}
}
},
"required": ["address", "mappings"],
"required": [
"address",
"mappings"
],
"additionalProperties": false
}
}
}
},
"required": ["proxies"],
"required": [
"proxies"
],
"additionalProperties": false
}

View File

@ -2,7 +2,10 @@ package proxy
import "forge.cadoles.com/Cadoles/emissary/internal/spec"
const NameProxy spec.Name = "proxy.emissary.cadoles.com"
const (
Name string = "proxy.emissary.cadoles.com"
Version = "0.0.0"
)
type ID string
@ -21,8 +24,12 @@ type ProxyMapping struct {
Target string `json:"target"`
}
func (s *Spec) SpecName() spec.Name {
return NameProxy
func (s *Spec) SpecDefinitionName() string {
return Name
}
func (s *Spec) SpecDefinitionVersion() string {
return Version
}
func (s *Spec) SpecRevision() int {

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"testing"
"forge.cadoles.com/Cadoles/emissary/internal/datastore/memory"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/pkg/errors"
)
@ -37,11 +38,15 @@ var validatorTestCases = []validatorTestCase{
func TestValidator(t *testing.T) {
t.Parallel()
validator := spec.NewValidator()
if err := validator.Register(NameProxy, 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) {