34 lines
789 B
Go
34 lines
789 B
Go
package client
|
|
|
|
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 datastore.AgentID, funcs ...OptionFunc) ([]spec.Spec, error) {
|
|
response := withResponse[struct {
|
|
Specs []*spec.RawSpec `json:"specs"`
|
|
}]()
|
|
|
|
path := fmt.Sprintf("/api/v1/agents/%d/specs", agentID)
|
|
|
|
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)
|
|
}
|
|
|
|
specs := make([]spec.Spec, 0, len(response.Data.Specs))
|
|
for _, s := range response.Data.Specs {
|
|
specs = append(specs, spec.Spec(s))
|
|
}
|
|
|
|
return specs, nil
|
|
}
|