debugging issue with init-admin.

This commit is contained in:
Nick Gerakines 2020-04-09 14:23:10 -04:00
parent 94c268ac69
commit 8b54f5c78d
No known key found for this signature in database
GPG Key ID: 33D43D854F96B2E4
3 changed files with 17 additions and 3 deletions

View File

@ -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 {

View File

@ -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) {

View File

@ -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 {