emissary/internal/datastore/agent.go
William Petit d02eb91b11
Some checks reported errors
arcad/emissary/pipeline/head Something is wrong with the build of this commit
feat(agent): add contactedAt attribute to agent
2023-04-01 14:33:19 +02:00

58 lines
1.2 KiB
Go

package datastore
import (
"encoding/json"
"time"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/pkg/errors"
)
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"`
}
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
}