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

@ -8,8 +8,7 @@ import (
)
type (
Spec = spec.Spec
SpecName = spec.Name
Spec = spec.Spec
)
type (

View File

@ -4,30 +4,32 @@ import (
"context"
"fmt"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/pkg/errors"
)
func (c *Client) DeleteAgentSpec(ctx context.Context, agentID AgentID, name SpecName, funcs ...OptionFunc) (SpecName, error) {
func (c *Client) DeleteAgentSpec(ctx context.Context, agentID AgentID, name string, version string, funcs ...OptionFunc) (string, string, error) {
payload := struct {
Name spec.Name `json:"name"`
Name string `json:"name"`
Version string `json:"version"`
}{
Name: name,
Name: name,
Version: version,
}
response := withResponse[struct {
Name spec.Name `json:"name"`
Name string `json:"name"`
Version string `json:"version"`
}]()
path := fmt.Sprintf("/api/v1/agents/%d/specs", agentID)
if err := c.apiDelete(ctx, path, payload, &response, funcs...); err != nil {
return "", errors.WithStack(err)
return "", "", errors.WithStack(err)
}
if response.Error != nil {
return "", errors.WithStack(response.Error)
return "", "", errors.WithStack(response.Error)
}
return response.Data.Name, nil
return response.Data.Name, response.Data.Version, nil
}

View File

@ -4,13 +4,14 @@ import (
"context"
"fmt"
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/pkg/errors"
)
func (c *Client) GetAgentSpecs(ctx context.Context, agentID AgentID, funcs ...OptionFunc) ([]Spec, error) {
response := withResponse[struct {
Specs []*spec.RawSpec `json:"specs"`
Specs []*datastore.Spec `json:"specs"`
}]()
path := fmt.Sprintf("/api/v1/agents/%d/specs", agentID)

View File

@ -6,17 +6,18 @@ import (
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/pkg/errors"
)
func (c *Client) UpdateAgentSpec(ctx context.Context, agentID AgentID, spc Spec, funcs ...OptionFunc) (Spec, error) {
payload := struct {
Name spec.Name `json:"name"`
Name string `json:"name"`
Version string `json:"version"`
Revision int `json:"revision"`
Data metadata.Metadata `json:"data"`
}{
Name: spc.SpecName(),
Name: spc.SpecDefinitionName(),
Version: spc.SpecDefinitionVersion(),
Revision: spc.SpecRevision(),
Data: spc.SpecData(),
}