Skip to content

Commit

Permalink
fix: tests provide incomplete ipfs config, add defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Dec 13, 2023
1 parent c3b4d82 commit a4152f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/config/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ type IpfsConfig struct {
// Path of the IPFS repo
ServePath string `yaml:"ServePath"`

Profile string `yaml:"Profile"`
SwarmListenAddresses []string
GatewayListenAddresses []string
APIListenAddresses []string
Profile string `yaml:"Profile"`
SwarmListenAddresses []string `yaml:"SwarmListenAddresses"`
GatewayListenAddresses []string `yaml:"GatewayListenAddresses"`
APIListenAddresses []string `yaml:"APIListenAddresses"`
}

// Due to a bug in Viper (https://github.com/spf13/viper/issues/380), string
Expand Down
28 changes: 24 additions & 4 deletions pkg/ipfs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ import (
)

func buildIPFSConfig(cfg types.IpfsConfig) (*config.Config, error) {
profile := config.Profiles[cfg.Profile]
profileName := cfg.Profile
if profileName == "" {
profileName = "flatfs"
}

swarmListenAddresses := cfg.SwarmListenAddresses
if len(swarmListenAddresses) == 0 {
swarmListenAddresses = []string{"/ip4/0.0.0.0/tcp/0", "/ip6/::1/tcp/0"}
}

gatewayListenAddresses := cfg.GatewayListenAddresses
if len(gatewayListenAddresses) == 0 {
gatewayListenAddresses = []string{"/ip4/0.0.0.0/tcp/0", "/ip6/::1/tcp/0"}
}

apiListenAddresses := cfg.APIListenAddresses
if len(apiListenAddresses) == 0 {
apiListenAddresses = []string{"/ip4/0.0.0.0/tcp/0", "/ip6/::1/tcp/0"}
}

profile := config.Profiles[profileName]
transformers := []config.Transformer{
withSwarmListenAddresses(cfg.SwarmListenAddresses...),
withGatewayListenAddresses(cfg.GatewayListenAddresses...),
withAPIListenAddresses(cfg.APIListenAddresses...),
withSwarmListenAddresses(swarmListenAddresses...),
withGatewayListenAddresses(gatewayListenAddresses...),
withAPIListenAddresses(apiListenAddresses...),
}

// If we're in local mode, then we need to manually change the config to
Expand Down

0 comments on commit a4152f1

Please sign in to comment.