2023-02-02 10:55:24 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2023-06-25 19:45:43 +02:00
|
|
|
func (c *Client) GetAgent(ctx context.Context, agentID AgentID, funcs ...OptionFunc) (*Agent, error) {
|
2023-02-02 10:55:24 +01:00
|
|
|
response := withResponse[struct {
|
2023-06-25 19:45:43 +02:00
|
|
|
Agent *Agent `json:"agent"`
|
2023-02-02 10:55:24 +01:00
|
|
|
}]()
|
|
|
|
|
|
|
|
path := fmt.Sprintf("/api/v1/agents/%d", agentID)
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
if err := c.apiGet(ctx, path, &response, funcs...); err != nil {
|
2023-02-02 10:55:24 +01:00
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if response.Error != nil {
|
|
|
|
return nil, errors.WithStack(response.Error)
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.Data.Agent, nil
|
|
|
|
}
|