2023-02-02 10:55:24 +01:00
|
|
|
package datastore
|
|
|
|
|
2023-03-02 13:05:24 +01:00
|
|
|
import (
|
|
|
|
"context"
|
2023-04-01 14:33:19 +02:00
|
|
|
"time"
|
2023-03-02 13:05:24 +01:00
|
|
|
|
|
|
|
"github.com/lestrrat-go/jwx/v2/jwk"
|
|
|
|
)
|
2023-02-02 10:55:24 +01:00
|
|
|
|
|
|
|
type AgentRepository interface {
|
2023-03-02 13:05:24 +01:00
|
|
|
Create(ctx context.Context, thumbprint string, keySet jwk.Set, metadata map[string]any) (*Agent, error)
|
2024-02-26 18:20:40 +01:00
|
|
|
|
|
|
|
Attach(ctx context.Context, tenantID TenantID, agentID AgentID) (*Agent, error)
|
|
|
|
Detach(ctx context.Context, agentID AgentID) (*Agent, error)
|
|
|
|
|
2023-02-02 10:55:24 +01:00
|
|
|
Get(ctx context.Context, id AgentID) (*Agent, error)
|
|
|
|
Update(ctx context.Context, id AgentID, updates ...AgentUpdateOptionFunc) (*Agent, error)
|
|
|
|
Query(ctx context.Context, opts ...AgentQueryOptionFunc) ([]*Agent, int, error)
|
|
|
|
Delete(ctx context.Context, id AgentID) error
|
|
|
|
|
2024-03-12 16:22:35 +01:00
|
|
|
UpdateSpec(ctx context.Context, id AgentID, name string, version string, revision int, data map[string]any) (*Spec, error)
|
2024-03-13 16:07:16 +01:00
|
|
|
QuerySpecs(ctx context.Context, id AgentID) ([]*SpecHeader, error)
|
|
|
|
GetSpec(ctx context.Context, id AgentID, name string, version string) (*Spec, error)
|
2024-03-12 16:22:35 +01:00
|
|
|
DeleteSpec(ctx context.Context, id AgentID, name string, version string) error
|
2023-02-02 10:55:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type AgentQueryOptionFunc func(*AgentQueryOptions)
|
|
|
|
|
|
|
|
type AgentQueryOptions struct {
|
2023-03-02 13:05:24 +01:00
|
|
|
Limit *int
|
|
|
|
Offset *int
|
|
|
|
IDs []AgentID
|
2024-02-26 18:20:40 +01:00
|
|
|
TenantIDs []TenantID
|
2023-03-02 13:05:24 +01:00
|
|
|
Thumbprints []string
|
|
|
|
Metadata *map[string]any
|
|
|
|
Statuses []AgentStatus
|
2023-02-02 10:55:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentQueryLimit(limit int) AgentQueryOptionFunc {
|
|
|
|
return func(opts *AgentQueryOptions) {
|
|
|
|
opts.Limit = &limit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentQueryOffset(offset int) AgentQueryOptionFunc {
|
|
|
|
return func(opts *AgentQueryOptions) {
|
|
|
|
opts.Offset = &offset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:05:24 +01:00
|
|
|
func WithAgentQueryMetadata(metadata map[string]any) AgentQueryOptionFunc {
|
2023-02-02 10:55:24 +01:00
|
|
|
return func(opts *AgentQueryOptions) {
|
2023-03-02 13:05:24 +01:00
|
|
|
opts.Metadata = &metadata
|
2023-02-02 10:55:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentQueryID(ids ...AgentID) AgentQueryOptionFunc {
|
|
|
|
return func(opts *AgentQueryOptions) {
|
|
|
|
opts.IDs = ids
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-26 18:20:40 +01:00
|
|
|
func WithAgentQueryTenantID(ids ...TenantID) AgentQueryOptionFunc {
|
|
|
|
return func(opts *AgentQueryOptions) {
|
|
|
|
opts.TenantIDs = ids
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-02 10:55:24 +01:00
|
|
|
func WithAgentQueryStatus(statuses ...AgentStatus) AgentQueryOptionFunc {
|
|
|
|
return func(opts *AgentQueryOptions) {
|
|
|
|
opts.Statuses = statuses
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:05:24 +01:00
|
|
|
func WithAgentQueryThumbprints(thumbprints ...string) AgentQueryOptionFunc {
|
|
|
|
return func(opts *AgentQueryOptions) {
|
|
|
|
opts.Thumbprints = thumbprints
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-02 10:55:24 +01:00
|
|
|
type AgentUpdateOptionFunc func(*AgentUpdateOptions)
|
|
|
|
|
|
|
|
type AgentUpdateOptions struct {
|
2023-04-01 14:33:19 +02:00
|
|
|
Label *string
|
|
|
|
Status *AgentStatus
|
|
|
|
ContactedAt *time.Time
|
|
|
|
Metadata *map[string]any
|
|
|
|
KeySet *jwk.Set
|
|
|
|
Thumbprint *string
|
2024-02-26 18:20:40 +01:00
|
|
|
TenantID *TenantID
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentUpdateTenant(id TenantID) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.TenantID = &id
|
|
|
|
}
|
2023-02-02 10:55:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentUpdateStatus(status AgentStatus) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.Status = &status
|
|
|
|
}
|
|
|
|
}
|
2023-03-02 13:05:24 +01:00
|
|
|
|
|
|
|
func WithAgentUpdateMetadata(metadata map[string]any) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.Metadata = &metadata
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentUpdateKeySet(keySet jwk.Set) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.KeySet = &keySet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAgentUpdateThumbprint(thumbprint string) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.Thumbprint = &thumbprint
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 13:28:18 +02:00
|
|
|
|
|
|
|
func WithAgentUpdateLabel(label string) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.Label = &label
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 14:33:19 +02:00
|
|
|
|
|
|
|
func WithAgentUpdateContactedAt(contactedAt time.Time) AgentUpdateOptionFunc {
|
|
|
|
return func(opts *AgentUpdateOptions) {
|
|
|
|
opts.ContactedAt = &contactedAt
|
|
|
|
}
|
|
|
|
}
|