diff --git a/start/admin.go b/start/admin.go index c4722ee..13f1537 100644 --- a/start/admin.go +++ b/start/admin.go @@ -11,6 +11,7 @@ import ( "runtime" "github.com/getsentry/sentry-go" + "github.com/kr/pretty" "github.com/urfave/cli/v2" "go.uber.org/zap" "golang.org/x/crypto/bcrypt" @@ -154,8 +155,16 @@ func initAdminCommandAction(cliCtx *cli.Context) error { // ActorFromUserInfo(name, displayName, domain, publicKey string, privateKey *rsa.PrivateKey) Payload { userActor := storage.ActorFromUserInfo(name, displayName, domain, publicKey, key) - actorID, _ := storage.JSONString(userActor, "id") - keyID, _ := storage.JSONDeepString(userActor, "publicKey", "id") + actorID, hasActorID := storage.JSONString(userActor, "id") + if !hasActorID || len(actorID) == 0 { + pretty.Println(userActor) + return fmt.Errorf("missing id from actor") + } + keyID, hasKeyID := storage.JSONDeepString(userActor, "publicKey", "id") + if !hasKeyID || len(keyID) == 0 { + pretty.Println(userActor) + return fmt.Errorf("missing key id from actor") + } err = s.CreateActor(ctx, actorID, userActor) if err != nil { diff --git a/storage/actor.go b/storage/actor.go index 0e43b36..3d9174f 100644 --- a/storage/actor.go +++ b/storage/actor.go @@ -235,7 +235,7 @@ func (s pgStorage) RecordActorAlias(ctx context.Context, actorID uuid.UUID, alia func (s pgStorage) RecordActorKey(ctx context.Context, actorID uuid.UUID, keyID, pem string) error { now := s.now() _, err := s.db.ExecContext(ctx, "INSERT INTO actor_keys (id, actor_id, key_id, pem, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $5) ON CONFLICT ON CONSTRAINT actor_keys_lookup DO UPDATE SET pem = $4, updated_at = $5", NewV4(), actorID, keyID, pem, now) - return errors.WrapInsertQueryFailedError(err) + return errors.WrapActorKeyInsertFailedError(err) } func (s pgStorage) ActorsByActorID(ctx context.Context, actorIDs []string) ([]*Actor, error) { diff --git a/storage/json.go b/storage/json.go index 932f1dd..983bce2 100644 --- a/storage/json.go +++ b/storage/json.go @@ -82,6 +82,9 @@ func JSONMap(document map[string]interface{}, key string) (map[string]interface{ if mapVal, isMap := value.(map[string]interface{}); isMap { return mapVal, true } + if payloadVal, isPayload := value.(Payload); isPayload { + return payloadVal, true + } } return nil, false } @@ -158,6 +161,8 @@ func JSONMapList(document map[string]interface{}, key string) ([]map[string]inte switch v := value.(type) { case map[string]interface{}: results = append(results, v) + case Payload: + results = append(results, v) case []interface{}: for _, el := range v { if mapValue, isMap := el.(map[string]interface{}); isMap {