porting all github actions from bluesky-social/indigo to tangled CI

goat plc: address review comments

Changed files
+24 -13
cmd
goat
+24 -13
cmd/goat/plc.go
··· 6 6 "fmt" 7 7 "io" 8 8 "net/http" 9 + "net/url" 9 10 "strings" 10 11 "time" 11 12 ··· 18 19 19 20 "github.com/urfave/cli/v2" 20 21 ) 21 - 22 - // TODO: use this consistently for all requests 23 - const GOAT_PLC_USER_AGENT = "goat-cli" 24 22 25 23 var cmdPLC = &cli.Command{ 26 24 Name: "plc", ··· 113 111 ArgsUsage: `<operation.json>`, 114 112 Flags: []cli.Flag{ 115 113 &cli.StringFlag{ 116 - Name: "plc-private-rotation-key", 117 - Usage: "private key used as a rotation key, if operation is not signed (multibase syntax)", 118 - EnvVars: []string{"PLC_PRIVATE_ROTATION_KEY"}, 114 + Name: "plc-signing-key", 115 + Usage: "private key used to sign operation (multibase syntax)", 116 + EnvVars: []string{"PLC_SIGNING_KEY"}, 119 117 }, 120 118 }, 121 119 Action: runPLCSign, ··· 443 441 if err != nil { 444 442 return err 445 443 } 444 + parsedHandle = parsedHandle.Normalize() 446 445 op.AlsoKnownAs = append(op.AlsoKnownAs, "at://"+string(parsedHandle)) 447 446 } 448 447 ··· 456 455 457 456 pds := cctx.String("pds") 458 457 if pds != "" { 459 - // TODO: check pds is valid URI? 458 + parsedUrl, err := url.Parse(pds) 459 + if err != nil { 460 + return err 461 + } 462 + if !parsedUrl.IsAbs() { 463 + return fmt.Errorf("invalid PDS URL: must be absolute") 464 + } 460 465 op.Services["atproto_pds"] = didplc.OpService{ 461 466 Type: "AtprotoPersonalDataServer", 462 467 Endpoint: pds, ··· 510 515 return fmt.Errorf("need to provide PLC operation json path as input") 511 516 } 512 517 513 - privStr := cctx.String("plc-private-rotation-key") 518 + privStr := cctx.String("plc-signing-key") 514 519 if privStr == "" { 515 520 return fmt.Errorf("private key must be provided") 516 521 } ··· 607 612 608 613 c := didplc.Client{ 609 614 DirectoryURL: cctx.String("plc-host"), 610 - UserAgent: GOAT_PLC_USER_AGENT, 615 + UserAgent: *userAgent(), 611 616 } 612 617 613 618 if err = c.Submit(ctx, didString, op); err != nil { 614 619 return err 615 620 } 616 621 617 - // TODO: print confirmation? 622 + fmt.Println("success") 618 623 619 624 return nil 620 625 } ··· 656 661 op = *baseOp 657 662 op.Sig = nil 658 663 case *didplc.LegacyOp: 659 - op = baseOp.RegularOp() 664 + op = baseOp.RegularOp() // also strips sig 660 665 case *didplc.TombstoneOp: 661 666 return nil, fmt.Errorf("cannot update from a tombstone op") 662 667 } ··· 675 680 676 681 c := didplc.Client{ 677 682 DirectoryURL: cctx.String("plc-host"), 678 - UserAgent: GOAT_PLC_USER_AGENT, 683 + UserAgent: *userAgent(), 679 684 } 680 685 op, err := fetchOpForUpdate(ctx, c, didString, prevCID) 681 686 if err != nil { ··· 735 740 736 741 pds := cctx.String("pds") 737 742 if pds != "" { 738 - // TODO: check pds is valid URI? 743 + parsedUrl, err := url.Parse(pds) 744 + if err != nil { 745 + return err 746 + } 747 + if !parsedUrl.IsAbs() { 748 + return fmt.Errorf("invalid PDS URL: must be absolute") 749 + } 739 750 op.Services["atproto_pds"] = didplc.OpService{ 740 751 Type: "AtprotoPersonalDataServer", 741 752 Endpoint: pds,