fork of indigo with slightly nicer lexgen

fakermaker: add support for invite code and domain suffix

This gets the tool working with, eg, staging

Changed files
+46 -12
cmd
fakermaker
fakedata
testing
+1
cmd/fakermaker/README.md
··· 23 export GOLOG_LOG_LEVEL=info 24 25 # setup and create initial accounts; 100 by default 26 go run ./cmd/fakermaker/ gen-accounts > data/fakermaker/accounts.json 27 28 # create or update profiles for all the accounts
··· 23 export GOLOG_LOG_LEVEL=info 24 25 # setup and create initial accounts; 100 by default 26 + # supply --use-invite-code and/or --domain-suffix SUFFIX as needed 27 go run ./cmd/fakermaker/ gen-accounts > data/fakermaker/accounts.json 28 29 # create or update profiles for all the accounts
+31 -2
cmd/fakermaker/main.go
··· 5 package main 6 7 import ( 8 "encoding/json" 9 "fmt" 10 "os" 11 "runtime" 12 13 "github.com/bluesky-social/indigo/fakedata" 14 "github.com/bluesky-social/indigo/util/cliutil" 15 "github.com/bluesky-social/indigo/util/version" ··· 69 Name: "count-celebrities", 70 Usage: "number of accounts as 'celebrities' (many followers)", 71 Value: 10, 72 }, 73 }, 74 }, ··· 203 204 countTotal := cctx.Int("count") 205 countCelebrities := cctx.Int("count-celebrities") 206 if countCelebrities > countTotal { 207 return fmt.Errorf("more celebrities than total accounts!") 208 } 209 countRegulars := countTotal - countCelebrities 210 211 // call helper to do actual creation 212 var usr *fakedata.AccountContext 213 var line []byte 214 t1 := fakedata.MeasureIterations("register celebrity accounts") 215 for i := 0; i < countCelebrities; i++ { 216 - if usr, err = fakedata.GenAccount(xrpcc, i, "celebrity"); err != nil { 217 return err 218 } 219 // compact single-line JSON by default ··· 226 227 t2 := fakedata.MeasureIterations("register regular accounts") 228 for i := 0; i < countRegulars; i++ { 229 - if usr, err = fakedata.GenAccount(xrpcc, i, "regular"); err != nil { 230 return err 231 } 232 // compact single-line JSON by default
··· 5 package main 6 7 import ( 8 + "context" 9 "encoding/json" 10 "fmt" 11 "os" 12 "runtime" 13 14 + comatproto "github.com/bluesky-social/indigo/api/atproto" 15 "github.com/bluesky-social/indigo/fakedata" 16 "github.com/bluesky-social/indigo/util/cliutil" 17 "github.com/bluesky-social/indigo/util/version" ··· 71 Name: "count-celebrities", 72 Usage: "number of accounts as 'celebrities' (many followers)", 73 Value: 10, 74 + }, 75 + &cli.StringFlag{ 76 + Name: "domain-suffix", 77 + Usage: "domain to register handle under", 78 + Value: "test", 79 + }, 80 + &cli.BoolFlag{ 81 + Name: "use-invite-code", 82 + Usage: "create and use an invite code", 83 + Value: false, 84 }, 85 }, 86 }, ··· 215 216 countTotal := cctx.Int("count") 217 countCelebrities := cctx.Int("count-celebrities") 218 + domainSuffix := cctx.String("domain-suffix") 219 if countCelebrities > countTotal { 220 return fmt.Errorf("more celebrities than total accounts!") 221 } 222 countRegulars := countTotal - countCelebrities 223 224 + var inviteCode *string = nil 225 + if cctx.Bool("use-invite-code") { 226 + resp, err := comatproto.ServerCreateInviteCodes(context.TODO(), xrpcc, &comatproto.ServerCreateInviteCodes_Input{ 227 + UseCount: int64(countTotal), 228 + ForAccounts: nil, 229 + CodeCount: 1, 230 + }) 231 + if err != nil { 232 + return err 233 + } 234 + if len(resp.Codes) != 1 || len(resp.Codes[0].Codes) != 1 { 235 + return fmt.Errorf("expected a single invite code") 236 + } 237 + inviteCode = &resp.Codes[0].Codes[0] 238 + } 239 + 240 // call helper to do actual creation 241 var usr *fakedata.AccountContext 242 var line []byte 243 t1 := fakedata.MeasureIterations("register celebrity accounts") 244 for i := 0; i < countCelebrities; i++ { 245 + if usr, err = fakedata.GenAccount(xrpcc, i, "celebrity", domainSuffix, inviteCode); err != nil { 246 return err 247 } 248 // compact single-line JSON by default ··· 255 256 t2 := fakedata.MeasureIterations("register regular accounts") 257 for i := 0; i < countRegulars; i++ { 258 + if usr, err = fakedata.GenAccount(xrpcc, i, "regular", domainSuffix, inviteCode); err != nil { 259 return err 260 } 261 // compact single-line JSON by default
+12 -8
fakedata/generators.go
··· 32 } 33 } 34 35 - func GenAccount(xrpcc *xrpc.Client, index int, accountType string) (*AccountContext, error) { 36 - var suffix string 37 if accountType == "celebrity" { 38 - suffix = "C" 39 } else { 40 - suffix = "" 41 } 42 prefix := gofakeit.Username() 43 if len(prefix) > 10 { 44 prefix = prefix[0:10] 45 } 46 - handle := fmt.Sprintf("%s-%s%d.test", prefix, suffix, index) 47 email := gofakeit.Email() 48 password := gofakeit.Password(true, true, true, true, true, 24) 49 ctx := context.TODO() 50 resp, err := comatproto.ServerCreateAccount(ctx, xrpcc, &comatproto.ServerCreateAccount_Input{ 51 - Email: email, 52 - Handle: handle, 53 - Password: password, 54 }) 55 if err != nil { 56 return nil, err
··· 32 } 33 } 34 35 + func GenAccount(xrpcc *xrpc.Client, index int, accountType, domainSuffix string, inviteCode *string) (*AccountContext, error) { 36 + if domainSuffix == "" { 37 + domainSuffix = "test" 38 + } 39 + var handleSuffix string 40 if accountType == "celebrity" { 41 + handleSuffix = "C" 42 } else { 43 + handleSuffix = "" 44 } 45 prefix := gofakeit.Username() 46 if len(prefix) > 10 { 47 prefix = prefix[0:10] 48 } 49 + handle := fmt.Sprintf("%s-%s%d.%s", prefix, handleSuffix, index, domainSuffix) 50 email := gofakeit.Email() 51 password := gofakeit.Password(true, true, true, true, true, 24) 52 ctx := context.TODO() 53 resp, err := comatproto.ServerCreateAccount(ctx, xrpcc, &comatproto.ServerCreateAccount_Input{ 54 + Email: email, 55 + Handle: handle, 56 + InviteCode: inviteCode, 57 + Password: password, 58 }) 59 if err != nil { 60 return nil, err
+2 -2
testing/pds_fakedata_test.go
··· 37 38 var catalog fakedata.AccountCatalog 39 for i := 0; i < celebCount; i++ { 40 - usr, err := fakedata.GenAccount(&xrpccAdmin, i, "celebrity") 41 if err != nil { 42 t.Fatal(err) 43 } 44 catalog.Celebs = append(catalog.Celebs, *usr) 45 } 46 for i := 0; i < regularCount; i++ { 47 - usr, err := fakedata.GenAccount(&xrpccAdmin, i, "regular") 48 if err != nil { 49 t.Fatal(err) 50 }
··· 37 38 var catalog fakedata.AccountCatalog 39 for i := 0; i < celebCount; i++ { 40 + usr, err := fakedata.GenAccount(&xrpccAdmin, i, "celebrity", "", nil) 41 if err != nil { 42 t.Fatal(err) 43 } 44 catalog.Celebs = append(catalog.Celebs, *usr) 45 } 46 for i := 0; i < regularCount; i++ { 47 + usr, err := fakedata.GenAccount(&xrpccAdmin, i, "regular", "", nil) 48 if err != nil { 49 t.Fatal(err) 50 }