emissary/pkg/client/update_agent_spec.go
William Petit 42d49eb090
All checks were successful
arcad/emissary/pipeline/head This commit looks good
feat: move client to public package
2023-06-25 11:46:33 -06:00

40 lines
977 B
Go

package client
import (
"context"
"fmt"
"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"`
Revision int `json:"revision"`
Data metadata.Metadata `json:"data"`
}{
Name: spc.SpecName(),
Revision: spc.SpecRevision(),
Data: spc.SpecData(),
}
response := withResponse[struct {
Spec *datastore.Spec `json:"spec"`
}]()
path := fmt.Sprintf("/api/v1/agents/%d/specs", agentID)
if err := c.apiPost(ctx, path, payload, &response, funcs...); err != nil {
return nil, errors.WithStack(err)
}
if response.Error != nil {
return nil, errors.WithStack(response.Error)
}
return response.Data.Spec, nil
}