this repo has no description
0
fork

Configure Feed

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

remove laputa command (PDS)

-201
-201
cmd/laputa/main.go
··· 1 - package main 2 - 3 - import ( 4 - "os" 5 - "path/filepath" 6 - 7 - "github.com/bluesky-social/indigo/api" 8 - "github.com/bluesky-social/indigo/carstore" 9 - "github.com/bluesky-social/indigo/pds" 10 - "github.com/bluesky-social/indigo/plc" 11 - "github.com/bluesky-social/indigo/util/cliutil" 12 - 13 - _ "github.com/joho/godotenv/autoload" 14 - _ "go.uber.org/automaxprocs" 15 - 16 - "github.com/carlmjohnson/versioninfo" 17 - "github.com/urfave/cli/v2" 18 - "go.opentelemetry.io/otel" 19 - "go.opentelemetry.io/otel/attribute" 20 - "go.opentelemetry.io/otel/exporters/jaeger" 21 - "go.opentelemetry.io/otel/sdk/resource" 22 - tracesdk "go.opentelemetry.io/otel/sdk/trace" 23 - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" 24 - "gorm.io/plugin/opentelemetry/tracing" 25 - ) 26 - 27 - func main() { 28 - run(os.Args) 29 - } 30 - 31 - func run(args []string) { 32 - 33 - app := cli.App{ 34 - Name: "laputa", 35 - Usage: "bluesky PDS in golang", 36 - Version: versioninfo.Short(), 37 - } 38 - 39 - app.Flags = []cli.Flag{ 40 - &cli.BoolFlag{ 41 - Name: "jaeger", 42 - }, 43 - &cli.StringFlag{ 44 - Name: "db-url", 45 - Value: "sqlite://./data/laputa/pds.sqlite", 46 - EnvVars: []string{"DATABASE_URL"}, 47 - }, 48 - &cli.StringFlag{ 49 - Name: "carstore-db-url", 50 - Value: "sqlite://./data/laputa/carstore.sqlite", 51 - EnvVars: []string{"CARSTORE_DATABASE_URL"}, 52 - }, 53 - &cli.BoolFlag{ 54 - Name: "db-tracing", 55 - }, 56 - &cli.StringFlag{ 57 - Name: "name", 58 - Usage: "hostname of this PDS instance", 59 - Value: "localhost:4989", 60 - }, 61 - &cli.StringFlag{ 62 - Name: "plc-host", 63 - Usage: "method, hostname, and port of PLC registry", 64 - Value: "https://plc.directory", 65 - EnvVars: []string{"ATP_PLC_HOST"}, 66 - }, 67 - &cli.StringFlag{ 68 - Name: "data-dir", 69 - Usage: "path of directory for CAR files and other data", 70 - Value: "data/laputa", 71 - EnvVars: []string{"DATA_DIR"}, 72 - }, 73 - &cli.StringFlag{ 74 - Name: "jwt-secret", 75 - Usage: "secret used for authenticating JWT tokens", 76 - Value: "jwtsecretplaceholder", 77 - EnvVars: []string{"ATP_JWT_SECRET"}, 78 - }, 79 - &cli.StringFlag{ 80 - Name: "handle-domains", 81 - Usage: "comma-separated list of domain suffixes for handle registration", 82 - Value: ".test", 83 - EnvVars: []string{"ATP_PDS_HANDLE_DOMAINS"}, 84 - }, 85 - &cli.IntFlag{ 86 - Name: "max-carstore-connections", 87 - EnvVars: []string{"MAX_CARSTORE_CONNECTIONS"}, 88 - Value: 40, 89 - }, 90 - &cli.IntFlag{ 91 - Name: "max-metadb-connections", 92 - EnvVars: []string{"MAX_METADB_CONNECTIONS"}, 93 - Value: 40, 94 - }, 95 - } 96 - 97 - app.Commands = []*cli.Command{ 98 - generateKeyCmd, 99 - } 100 - 101 - app.Action = func(cctx *cli.Context) error { 102 - 103 - if cctx.Bool("jaeger") { 104 - url := "http://localhost:14268/api/traces" 105 - exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) 106 - if err != nil { 107 - return err 108 - } 109 - tp := tracesdk.NewTracerProvider( 110 - // Always be sure to batch in production. 111 - tracesdk.WithBatcher(exp), 112 - // Record information about this application in a Resource. 113 - tracesdk.WithResource(resource.NewWithAttributes( 114 - semconv.SchemaURL, 115 - semconv.ServiceNameKey.String("pds"), 116 - attribute.String("environment", "test"), 117 - attribute.Int64("ID", 1), 118 - )), 119 - ) 120 - 121 - otel.SetTracerProvider(tp) 122 - } 123 - 124 - dbtracing := cctx.Bool("db-tracing") 125 - datadir := cctx.String("data-dir") 126 - csdir := filepath.Join(datadir, "carstore") 127 - keypath := filepath.Join(datadir, "server.key") 128 - jwtsecret := []byte(cctx.String("jwt-secret")) 129 - 130 - // TODO(bnewbold): split this on comma, and have PDS support multiple 131 - // domain suffixes that can be registered 132 - pdsdomain := cctx.String("handle-domains") 133 - 134 - // ensure data directories exist; won't error if it does 135 - os.MkdirAll(csdir, os.ModePerm) 136 - 137 - // default postgres setup: postgresql://postgres:password@localhost:5432/pdsdb?sslmode=disable 138 - db, err := cliutil.SetupDatabase(cctx.String("db-url"), cctx.Int("max-metadb-connections")) 139 - if err != nil { 140 - return err 141 - } 142 - 143 - // default postgres setup: postgresql://postgres:password@localhost:5432/cardb?sslmode=disable 144 - csdb, err := cliutil.SetupDatabase(cctx.String("carstore-db-url"), cctx.Int("max-carstore-connections")) 145 - if err != nil { 146 - return err 147 - } 148 - 149 - if dbtracing { 150 - if err := db.Use(tracing.NewPlugin()); err != nil { 151 - return err 152 - } 153 - if err := csdb.Use(tracing.NewPlugin()); err != nil { 154 - return err 155 - } 156 - } 157 - 158 - cstore, err := carstore.NewCarStore(csdb, []string{csdir}) 159 - if err != nil { 160 - return err 161 - } 162 - 163 - var didr plc.PLCClient 164 - if plchost := cctx.String("plc-host"); plchost != "" { 165 - didr = &api.PLCServer{Host: plchost} 166 - } else { 167 - didr = plc.NewFakeDid(db) 168 - } 169 - 170 - pdshost := cctx.String("name") 171 - 172 - key, err := cliutil.LoadKeyFromFile(keypath) 173 - if err != nil { 174 - return err 175 - } 176 - 177 - srv, err := pds.NewServer(db, cstore, key, pdsdomain, pdshost, didr, jwtsecret) 178 - if err != nil { 179 - return err 180 - } 181 - 182 - return srv.RunAPI(":4989") 183 - } 184 - 185 - app.RunAndExitOnError() 186 - } 187 - 188 - var generateKeyCmd = &cli.Command{ 189 - Name: "gen-key", 190 - Flags: []cli.Flag{ 191 - &cli.StringFlag{ 192 - Name: "output", 193 - Aliases: []string{"o"}, 194 - Value: "data/laputa/server.key", 195 - }, 196 - }, 197 - Action: func(cctx *cli.Context) error { 198 - fname := cctx.String("output") 199 - return cliutil.GenerateKeyToFile(fname) 200 - }, 201 - }