39 lines
881 B
Go
39 lines
881 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) UpdateAgentSpec(ctx context.Context, agentID datastore.AgentID, name spec.Name, revision int, data any) (*datastore.Spec, error) {
|
|
payload := struct {
|
|
Name spec.Name `json:"name"`
|
|
Revision int `json:"revision"`
|
|
Data any `json:"data"`
|
|
}{
|
|
Name: name,
|
|
Revision: revision,
|
|
Data: data,
|
|
}
|
|
|
|
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); err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
if response.Error != nil {
|
|
return nil, errors.WithStack(response.Error)
|
|
}
|
|
|
|
return response.Data.Spec, nil
|
|
}
|