feat: agent specifications query and get endpoints
All checks were successful
arcad/emissary/pipeline/head This commit looks good

This commit is contained in:
2024-03-13 16:07:16 +01:00
parent cec5c783fe
commit 85ccf2e1df
15 changed files with 261 additions and 55 deletions

View File

@ -0,0 +1,27 @@
package client
import (
"context"
"fmt"
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
"github.com/pkg/errors"
)
func (c *Client) GetAgentSpec(ctx context.Context, agentID AgentID, specName string, specVersion string, funcs ...OptionFunc) (*datastore.Spec, error) {
response := withResponse[struct {
Spec *datastore.Spec `json:"spec"`
}]()
path := fmt.Sprintf("/api/v1/agents/%d/specs/%s/%s", agentID, specName, specVersion)
if err := c.apiGet(ctx, path, &response, funcs...); err != nil {
return nil, errors.WithStack(err)
}
if response.Error != nil {
return nil, errors.WithStack(response.Error)
}
return response.Data.Spec, nil
}

View File

@ -5,13 +5,12 @@ import (
"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) {
func (c *Client) QueryAgentSpecs(ctx context.Context, agentID AgentID, funcs ...OptionFunc) ([]*datastore.SpecHeader, error) {
response := withResponse[struct {
Specs []*datastore.Spec `json:"specs"`
Specs []*datastore.SpecHeader `json:"specs"`
}]()
path := fmt.Sprintf("/api/v1/agents/%d/specs", agentID)
@ -24,10 +23,5 @@ func (c *Client) GetAgentSpecs(ctx context.Context, agentID AgentID, funcs ...Op
return nil, errors.WithStack(response.Error)
}
specs := make([]spec.Spec, 0, len(response.Data.Specs))
for _, s := range response.Data.Specs {
specs = append(specs, spec.Spec(s))
}
return specs, nil
return response.Data.Specs, nil
}