2023-02-02 10:55:24 +01:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
2023-03-02 13:05:24 +01:00
|
|
|
"encoding/json"
|
2023-02-02 10:55:24 +01:00
|
|
|
"time"
|
2023-03-02 13:05:24 +01:00
|
|
|
|
|
|
|
"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 {
|
2023-04-01 14:33:19 +02:00
|
|
|
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"`
|
2023-03-02 13:05:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|