emissary/pkg/client/update_agent_spec.go

41 lines
1022 B
Go
Raw Permalink Normal View History

package client
import (
"context"
"fmt"
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
"github.com/pkg/errors"
)
2023-06-25 19:45:43 +02:00
func (c *Client) UpdateAgentSpec(ctx context.Context, agentID AgentID, spc Spec, funcs ...OptionFunc) (Spec, error) {
payload := struct {
Name string `json:"name"`
Version string `json:"version"`
Revision int `json:"revision"`
Data metadata.Metadata `json:"data"`
}{
Name: spc.SpecDefinitionName(),
Version: spc.SpecDefinitionVersion(),
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
}