feat: agent metadata with custom collectors
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
|
||||
type Client struct {
|
||||
http *http.Client
|
||||
token string
|
||||
serverURL string
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,11 @@ import (
|
||||
type QueryAgentsOptionFunc func(*QueryAgentsOptions)
|
||||
|
||||
type QueryAgentsOptions struct {
|
||||
Limit *int
|
||||
Offset *int
|
||||
RemoteIDs []string
|
||||
IDs []datastore.AgentID
|
||||
Statuses []datastore.AgentStatus
|
||||
Limit *int
|
||||
Offset *int
|
||||
Thumbprints []string
|
||||
IDs []datastore.AgentID
|
||||
Statuses []datastore.AgentStatus
|
||||
}
|
||||
|
||||
func WithQueryAgentsLimit(limit int) QueryAgentsOptionFunc {
|
||||
@ -31,9 +31,9 @@ func WithQueryAgentsOffset(offset int) QueryAgentsOptionFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func WithQueryAgentsRemoteID(remoteIDs ...string) QueryAgentsOptionFunc {
|
||||
func WithQueryAgentsThumbprints(thumbprints ...string) QueryAgentsOptionFunc {
|
||||
return func(opts *QueryAgentsOptions) {
|
||||
opts.RemoteIDs = remoteIDs
|
||||
opts.Thumbprints = thumbprints
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,11 +61,11 @@ func (c *Client) QueryAgents(ctx context.Context, funcs ...QueryAgentsOptionFunc
|
||||
query.Set("ids", joinSlice(options.IDs))
|
||||
}
|
||||
|
||||
if options.RemoteIDs != nil && len(options.RemoteIDs) > 0 {
|
||||
query.Set("remoteIds", joinSlice(options.RemoteIDs))
|
||||
if options.Thumbprints != nil && len(options.Thumbprints) > 0 {
|
||||
query.Set("thumbprints", joinSlice(options.Thumbprints))
|
||||
}
|
||||
|
||||
if options.Statuses != nil && len(options.RemoteIDs) > 0 {
|
||||
if options.Statuses != nil && len(options.Statuses) > 0 {
|
||||
query.Set("statuses", joinSlice(options.Statuses))
|
||||
}
|
||||
|
||||
|
@ -3,15 +3,33 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/jwk"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) RegisterAgent(ctx context.Context, remoteID string) (*datastore.Agent, error) {
|
||||
func (c *Client) RegisterAgent(ctx context.Context, key jwk.Key, thumbprint string, meta []metadata.Tuple) (*datastore.Agent, error) {
|
||||
keySet, err := jwk.PublicKeySet(key)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
signature, err := jwk.Sign(key, thumbprint, meta)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
payload := struct {
|
||||
RemoteID string `json:"remoteId"`
|
||||
KeySet jwk.Set `json:"keySet"`
|
||||
Thumbprint string `json:"thumbprint"`
|
||||
Metadata []metadata.Tuple `json:"metadata"`
|
||||
Signature string `json:"signature"`
|
||||
}{
|
||||
RemoteID: remoteID,
|
||||
Thumbprint: thumbprint,
|
||||
Metadata: meta,
|
||||
Signature: signature,
|
||||
KeySet: keySet,
|
||||
}
|
||||
|
||||
response := withResponse[struct {
|
||||
|
@ -4,20 +4,21 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
|
||||
"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) {
|
||||
func (c *Client) UpdateAgentSpec(ctx context.Context, agentID datastore.AgentID, spc spec.Spec) (*datastore.Spec, error) {
|
||||
payload := struct {
|
||||
Name spec.Name `json:"name"`
|
||||
Revision int `json:"revision"`
|
||||
Data any `json:"data"`
|
||||
Name spec.Name `json:"name"`
|
||||
Revision int `json:"revision"`
|
||||
Data metadata.Metadata `json:"data"`
|
||||
}{
|
||||
Name: name,
|
||||
Revision: revision,
|
||||
Data: data,
|
||||
Name: spc.SpecName(),
|
||||
Revision: spc.SpecRevision(),
|
||||
Data: spc.SpecData(),
|
||||
}
|
||||
|
||||
response := withResponse[struct {
|
||||
|
Reference in New Issue
Block a user