emissary/internal/datastore/agent.go

56 lines
1.1 KiB
Go
Raw 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"`
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"`
}
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
}