2023-02-28 15:50:35 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-02 13:05:24 +01:00
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
|
2023-02-28 15:50:35 +01:00
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/spec"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2023-03-02 13:05:24 +01:00
|
|
|
func (c *Client) UpdateAgentSpec(ctx context.Context, agentID datastore.AgentID, spc spec.Spec) (*datastore.Spec, error) {
|
2023-02-28 15:50:35 +01:00
|
|
|
payload := struct {
|
2023-03-02 13:05:24 +01:00
|
|
|
Name spec.Name `json:"name"`
|
|
|
|
Revision int `json:"revision"`
|
|
|
|
Data metadata.Metadata `json:"data"`
|
2023-02-28 15:50:35 +01:00
|
|
|
}{
|
2023-03-02 13:05:24 +01:00
|
|
|
Name: spc.SpecName(),
|
|
|
|
Revision: spc.SpecRevision(),
|
|
|
|
Data: spc.SpecData(),
|
2023-02-28 15:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|