emissary/internal/datastore/agent.go

59 lines
1.3 KiB
Go
Raw Permalink Normal View History

2023-02-02 10:55:24 +01:00
package datastore
import (
"encoding/json"
2023-02-02 10:55:24 +01:00
"time"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/pkg/errors"
2023-02-02 10:55:24 +01:00
)
type AgentID int64
type AgentStatus int
const (
AgentStatusPending AgentStatus = 0
AgentStatusAccepted AgentStatus = 1
AgentStatusRejected AgentStatus = 2
AgentStatusForgotten AgentStatus = 3
)
type Agent struct {
ID AgentID `json:"id"`
Label string `json:"label"`
Thumbprint string `json:"thumbprint"`
KeySet *SerializableKeySet `json:"keyset,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Status AgentStatus `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ContactedAt *time.Time `json:"contactedAt,omitempty"`
2024-02-26 18:20:40 +01:00
TenantID *TenantID `json:"tenantId"`
}
type SerializableKeySet struct {
jwk.Set
}
func (s *SerializableKeySet) UnmarshalJSON(data []byte) error {
keySet := jwk.NewSet()
if err := json.Unmarshal(data, &keySet); err != nil {
return errors.WithStack(err)
}
s.Set = keySet
return nil
}
func (s *SerializableKeySet) MarshalJSON() ([]byte, error) {
data, err := json.Marshal(s.Set)
if err != nil {
return nil, errors.WithStack(err)
}
return data, nil
2023-02-02 10:55:24 +01:00
}