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