this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve relay helpers

+192 -27
+189 -6
cmd/goat/relay.go
··· 5 5 "fmt" 6 6 7 7 comatproto "github.com/bluesky-social/indigo/api/atproto" 8 + "github.com/bluesky-social/indigo/atproto/syntax" 8 9 "github.com/bluesky-social/indigo/xrpc" 9 10 10 11 "github.com/urfave/cli/v2" ··· 27 28 Usage: "sub-commands for accounts/repos on relay", 28 29 Subcommands: []*cli.Command{ 29 30 &cli.Command{ 30 - Name: "list", 31 - Usage: "enumerate all accounts", 31 + Name: "list", 32 + Aliases: []string{"ls"}, 33 + Usage: "enumerate all accounts", 32 34 Flags: []cli.Flag{ 33 35 &cli.StringFlag{ 34 36 Name: "collection", ··· 42 44 }, 43 45 Action: runRelayAccountList, 44 46 }, 47 + &cli.Command{ 48 + Name: "status", 49 + ArgsUsage: `<did>`, 50 + Usage: "describe status of individual account", 51 + Flags: []cli.Flag{ 52 + &cli.BoolFlag{ 53 + Name: "json", 54 + Usage: "print output as JSON", 55 + }, 56 + }, 57 + Action: runRelayAccountStatus, 58 + }, 45 59 }, 46 60 }, 47 61 &cli.Command{ ··· 49 63 Usage: "sub-commands for upstream hosts (eg, PDS)", 50 64 Subcommands: []*cli.Command{ 51 65 &cli.Command{ 52 - Name: "add", 66 + Name: "request-crawl", 67 + Aliases: []string{"add"}, 53 68 Usage: "request crawl of upstream host (eg, PDS)", 54 69 ArgsUsage: `<hostname>`, 55 - Action: runRelayHostAdd, 70 + Action: runRelayHostRequestCrawl, 71 + }, 72 + &cli.Command{ 73 + Name: "list", 74 + Aliases: []string{"ls"}, 75 + Usage: "enumerate all hosts indexed by relay", 76 + Flags: []cli.Flag{ 77 + &cli.BoolFlag{ 78 + Name: "json", 79 + Usage: "print output as JSON lines", 80 + }, 81 + }, 82 + Action: runRelayHostList, 83 + }, 84 + &cli.Command{ 85 + Name: "status", 86 + ArgsUsage: `<hostname>`, 87 + Usage: "describe status of individual host", 88 + Flags: []cli.Flag{ 89 + &cli.BoolFlag{ 90 + Name: "json", 91 + Usage: "print output as JSON", 92 + }, 93 + }, 94 + Action: runRelayHostStatus, 56 95 }, 57 96 }, 58 97 }, ··· 103 142 fmt.Println(string(b)) 104 143 } else { 105 144 status := "unknown" 106 - if r.Active != nil && *r.Active == true { 145 + if r.Active != nil && *r.Active { 107 146 status = "active" 108 147 } else if r.Status != nil { 109 148 status = *r.Status ··· 121 160 return nil 122 161 } 123 162 124 - func runRelayHostAdd(cctx *cli.Context) error { 163 + func runRelayAccountStatus(cctx *cli.Context) error { 164 + ctx := cctx.Context 165 + 166 + didStr := cctx.Args().First() 167 + if didStr == "" { 168 + return fmt.Errorf("need to provide account DID as argument") 169 + } 170 + if cctx.Args().Len() != 1 { 171 + return fmt.Errorf("unexpected arguments") 172 + } 173 + 174 + did, err := syntax.ParseDID(didStr) 175 + if err != nil { 176 + return err 177 + } 178 + 179 + client := xrpc.Client{ 180 + Host: cctx.String("relay-host"), 181 + } 182 + 183 + r, err := comatproto.SyncGetRepoStatus(ctx, &client, did.String()) 184 + if err != nil { 185 + return err 186 + } 187 + 188 + if cctx.Bool("json") { 189 + b, err := json.Marshal(r) 190 + if err != nil { 191 + return err 192 + } 193 + fmt.Println(string(b)) 194 + } else { 195 + status := "unknown" 196 + if r.Active { 197 + status = "active" 198 + } else if r.Status != nil { 199 + status = *r.Status 200 + } 201 + rev := "" 202 + if r.Rev != nil { 203 + rev = *r.Rev 204 + } 205 + fmt.Printf("%s\t%s\t%s\n", r.Did, status, rev) 206 + } 207 + 208 + return nil 209 + } 210 + 211 + func runRelayHostRequestCrawl(cctx *cli.Context) error { 125 212 ctx := cctx.Context 126 213 127 214 hostname := cctx.Args().First() ··· 143 230 fmt.Println("success") 144 231 return nil 145 232 } 233 + 234 + func runRelayHostList(cctx *cli.Context) error { 235 + ctx := cctx.Context 236 + 237 + if cctx.Args().Len() > 0 { 238 + return fmt.Errorf("unexpected arguments") 239 + } 240 + 241 + client := xrpc.Client{ 242 + Host: cctx.String("relay-host"), 243 + } 244 + 245 + cursor := "" 246 + var size int64 = 500 247 + for { 248 + resp, err := comatproto.SyncListHosts(ctx, &client, cursor, size) 249 + if err != nil { 250 + return err 251 + } 252 + 253 + for _, h := range resp.Hosts { 254 + if cctx.Bool("json") { 255 + b, err := json.Marshal(h) 256 + if err != nil { 257 + return err 258 + } 259 + fmt.Println(string(b)) 260 + } else { 261 + status := "" 262 + if h.Status != nil { 263 + status = *h.Status 264 + } 265 + count := "" 266 + if h.AccountCount != nil { 267 + count = fmt.Sprintf("%d", *h.AccountCount) 268 + } 269 + seq := "" 270 + if h.Seq != nil { 271 + seq = fmt.Sprintf("%d", *h.Seq) 272 + } 273 + fmt.Printf("%s\t%s\t%s\t%s\n", h.Hostname, status, count, seq) 274 + } 275 + } 276 + 277 + if resp.Cursor == nil || *resp.Cursor == "" { 278 + break 279 + } 280 + cursor = *resp.Cursor 281 + } 282 + return nil 283 + } 284 + 285 + func runRelayHostStatus(cctx *cli.Context) error { 286 + ctx := cctx.Context 287 + 288 + hostname := cctx.Args().First() 289 + if hostname == "" { 290 + return fmt.Errorf("need to provide hostname as argument") 291 + } 292 + if cctx.Args().Len() != 1 { 293 + return fmt.Errorf("unexpected arguments") 294 + } 295 + 296 + client := xrpc.Client{ 297 + Host: cctx.String("relay-host"), 298 + } 299 + 300 + h, err := comatproto.SyncGetHostStatus(ctx, &client, hostname) 301 + if err != nil { 302 + return err 303 + } 304 + 305 + if cctx.Bool("json") { 306 + b, err := json.Marshal(h) 307 + if err != nil { 308 + return err 309 + } 310 + fmt.Println(string(b)) 311 + } else { 312 + status := "" 313 + if h.Status != nil { 314 + status = *h.Status 315 + } 316 + count := "" 317 + if h.AccountCount != nil { 318 + count = fmt.Sprintf("%d", *h.AccountCount) 319 + } 320 + seq := "" 321 + if h.Seq != nil { 322 + seq = fmt.Sprintf("%d", *h.Seq) 323 + } 324 + fmt.Printf("%s\t%s\t%s\t%s\n", h.Hostname, status, count, seq) 325 + } 326 + 327 + return nil 328 + }
+3 -21
cmd/goat/relay_admin.go
··· 92 92 ArgsUsage: `<hostname>`, 93 93 Flags: []cli.Flag{ 94 94 &cli.IntFlag{ 95 - Name: "per-second", 96 - }, 97 - &cli.IntFlag{ 98 - Name: "per-hour", 99 - }, 100 - &cli.IntFlag{ 101 - Name: "per-day", 102 - }, 103 - &cli.IntFlag{ 104 - Name: "repo-limit", 95 + Name: "account-limit", 105 96 }, 106 97 }, 107 98 Action: runRelayAdminHostConfig, ··· 376 367 body := map[string]any{ 377 368 "host": hostname, 378 369 } 379 - if cctx.IsSet("per-second") { 380 - body["per_second"] = cctx.Int("per-second") 381 - } 382 - if cctx.IsSet("per-hour") { 383 - body["per_hour"] = cctx.Int("per-hour") 384 - } 385 - if cctx.IsSet("per-day") { 386 - body["per_day"] = cctx.Int("per-day") 387 - } 388 - if cctx.IsSet("repo-limit") { 389 - body["repo_limit"] = cctx.Int("repo-limit") 370 + if cctx.IsSet("account-limit") { 371 + body["repo_limit"] = cctx.Int("account-limit") 390 372 } 391 373 392 374 _, err = client.Do("POST", path, nil, body)