emissary/internal/client/register_agent.go

31 lines
622 B
Go
Raw Normal View History

2023-02-02 10:55:24 +01:00
package client
import (
"context"
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
"github.com/pkg/errors"
)
func (c *Client) RegisterAgent(ctx context.Context, remoteID string) (*datastore.Agent, error) {
payload := struct {
RemoteID string `json:"remoteId"`
}{
RemoteID: remoteID,
}
response := withResponse[struct {
Agent *datastore.Agent `json:"agent"`
}]()
if err := c.apiPost(ctx, "/api/v1/register", payload, &response); err != nil {
return nil, errors.WithStack(err)
}
if response.Error != nil {
return nil, errors.WithStack(response.Error)
}
return response.Data.Agent, nil
}