Skip to content

Commit

Permalink
Support a list of subdomain gateway domains and legacy gateway domains
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Oct 20, 2023
1 parent 36552d0 commit 2f8cf9a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
14 changes: 12 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ func setupGatewayHandler(cfg Config, nd *Node) (http.Handler, error) {
UseSubdomains: true,
},
}
if cfg.GatewayDomain != "" {
publicGateways[cfg.GatewayDomain] = &gateway.PublicGateway{
for _, domain := range cfg.GatewayDomains {
publicGateways[domain] = &gateway.PublicGateway{
Paths: []string{"/ipfs", "/ipns", "/version", "/api/v0"},
NoDNSLink: noDNSLink,
InlineDNSLink: true,
DeserializedResponses: true,
UseSubdomains: false,
}
}

Check warning on line 127 in handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers.go#L118-L127

Added lines #L118 - L127 were not covered by tests

for _, domain := range cfg.SubdomainGatewayDomains {
publicGateways[domain] = &gateway.PublicGateway{

Check warning on line 130 in handlers.go

View check run for this annotation

Codecov / codecov/patch

handlers.go#L129-L130

Added lines #L129 - L130 were not covered by tests
Paths: []string{"/ipfs", "/ipns", "/version", "/api/v0"},
NoDNSLink: noDNSLink,
InlineDNSLink: true,
Expand Down
53 changes: 33 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ func main() {
Usage: "Specify an index to derivate the peerID from the key (needs --seed)",
},
&cli.StringFlag{
Name: "gateway-domain",
Name: "gateway-domains",
Value: "",
EnvVars: []string{"RAINBOW_GATEWAY_DOMAIN"},
Usage: "Set to enable subdomain gateway on this domain",
EnvVars: []string{"RAINBOW_GATEWAY_DOMAINS"},
Usage: "Set to enable legacy gateway on these domains. Comma-separated list.",
},
&cli.StringFlag{
Name: "subdomain-gateway-domains",
Value: "",
EnvVars: []string{"RAINBOW_SUBDOMAIN_GATEWAY_DOMAINS"},
Usage: "Set to enable legacy gateway on these domains. Comma-separated list.",
},

Check warning on line 66 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L55-L66

Added lines #L55 - L66 were not covered by tests
&cli.IntFlag{
Name: "gateway-port",
Expand Down Expand Up @@ -191,24 +197,20 @@ to create libp2p identities for the gateway.
return err
}

var denylists []string
if list := cctx.String("denylists"); len(list) > 0 {
denylists = strings.Split(list, ",")
}

cfg := Config{
DataDir: ddir,
GatewayDomain: cctx.String("gateway-domain"),
ConnMgrLow: cctx.Int("connmgr-low"),
ConnMgrHi: cctx.Int("connmgr-high"),
ConnMgrGrace: cctx.Duration("connmgr-grace"),
MaxMemory: cctx.Uint64("max-memory"),
MaxFD: cctx.Int("max-fd"),
InMemBlockCache: cctx.Int64("inmem-block-cache"),
RoutingV1: cctx.String("routing"),
KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC),
DHTSharedHost: cctx.Bool("dht-fallback-shared-host"),
DenylistSubs: denylists,
DataDir: ddir,
GatewayDomains: getCommaSeparatedList(cctx.String("gateway-domains")),
SubdomainGatewayDomains: getCommaSeparatedList(cctx.String("subdomain-gateway-domains")),
ConnMgrLow: cctx.Int("connmgr-low"),
ConnMgrHi: cctx.Int("connmgr-high"),
ConnMgrGrace: cctx.Duration("connmgr-grace"),
MaxMemory: cctx.Uint64("max-memory"),
MaxFD: cctx.Int("max-fd"),
InMemBlockCache: cctx.Int64("inmem-block-cache"),
RoutingV1: cctx.String("routing"),
KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC),
DHTSharedHost: cctx.Bool("dht-fallback-shared-host"),
DenylistSubs: getCommaSeparatedList(cctx.String("denylists")),
}

goLog.Debugf("Rainbow config: %+v", cfg)
Expand Down Expand Up @@ -344,3 +346,14 @@ func getEnvs(key, defaultValue string) []string {
value = strings.TrimSpace(value)
return strings.Split(value, ",")
}

func getCommaSeparatedList(val string) []string {
if val == "" {
return nil
}
items := strings.Split(val, ",")
for i, item := range items {
items[i] = strings.TrimSpace(item)
}
return items

Check warning on line 358 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L350-L358

Added lines #L350 - L358 were not covered by tests
}
9 changes: 5 additions & 4 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ type Config struct {
MaxMemory uint64
MaxFD int

GatewayDomain string
RoutingV1 string
KuboRPCURLs []string
DHTSharedHost bool
GatewayDomains []string
SubdomainGatewayDomains []string
RoutingV1 string
KuboRPCURLs []string
DHTSharedHost bool

DenylistSubs []string
}
Expand Down

0 comments on commit 2f8cf9a

Please sign in to comment.