Skip to content

Commit

Permalink
Merge pull request #8 from bittorrent/feat/s3-compatible-api
Browse files Browse the repository at this point in the history
feat: add s3-compatible-api configure
  • Loading branch information
Shawn-Huang-Tron authored May 23, 2024
2 parents d71617d + 16001c9 commit 9badb8e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
35 changes: 18 additions & 17 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@ import (

// Config is used to load ipfs config files.
type Config struct {
ChainInfo ChainInfo // local node's chain info
Identity Identity // local node's peer identity
Datastore Datastore // local node's storage
Addresses Addresses // local node's addresses
Mounts Mounts // local node's mount points
Discovery Discovery // local node's discovery mechanisms
Routing Routing // local node's routing settings
Ipns Ipns // Ipns settings
Bootstrap []string // local nodes's bootstrap peer addresses
Gateway Gateway // local node's gateway server options
API API // local node's API settings
Swarm SwarmConfig
AutoNAT AutoNATConfig
Pubsub PubsubConfig
Peering Peering
DNS DNS
Services Services // External service domains and info
ChainInfo ChainInfo // local node's chain info
Identity Identity // local node's peer identity
Datastore Datastore // local node's storage
Addresses Addresses // local node's addresses
Mounts Mounts // local node's mount points
Discovery Discovery // local node's discovery mechanisms
Routing Routing // local node's routing settings
Ipns Ipns // Ipns settings
Bootstrap []string // local nodes's bootstrap peer addresses
Gateway Gateway // local node's gateway server options
API API // local node's API settings
S3CompatibleAPI S3CompatibleAPI //s3-compatible-api settings
Swarm SwarmConfig
AutoNAT AutoNATConfig
Pubsub PubsubConfig
Peering Peering
DNS DNS
Services Services // External service domains and info

Provider Provider
Reprovider Reprovider
Expand Down
11 changes: 10 additions & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func Init(out io.Writer, nBitsForKeypair int, keyType string, importKey string,
},
APICommands: []string{},
},
Services: DefaultServicesConfig(),
S3CompatibleAPI: DefaultS3CompatibleAPIConfig(),
Services: DefaultServicesConfig(),
Reprovider: Reprovider{
Interval: NewOptionalDuration(time.Hour * 12),
Strategy: NewOptionalString("all"),
Expand Down Expand Up @@ -213,6 +214,14 @@ func flatfsSpec() map[string]interface{} {
}
}

func DefaultS3CompatibleAPIConfig() S3CompatibleAPI {
return S3CompatibleAPI{
Address: "127.0.0.1:6001",
Enable: false,
HTTPHeaders: nil,
}
}

// DefaultServicesConfig returns the default set of configs for external services.
func DefaultServicesConfig() Services {
return Services{
Expand Down
11 changes: 11 additions & 0 deletions migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ func migrate_17_Sync_Hosts(cfg *Config) bool {
return false
}

func migrate_18_S3CompatibleAPI(cfg *Config) bool {
if len(cfg.S3CompatibleAPI.Address) == 0 {
cfg.S3CompatibleAPI.Enable = false
cfg.S3CompatibleAPI.Address = "127.0.0.1:6001"
cfg.S3CompatibleAPI.HTTPHeaders = nil
return true
}
return false
}

// MigrateConfig migrates config options to the latest known version
// It may correct incompatible configs as well
// inited = just initialized in the same call
Expand All @@ -283,5 +293,6 @@ func MigrateConfig(cfg *Config, inited, hasHval bool) bool {
updated = migrate_15_MissingRemoteAPI(cfg) || updated
updated = migrate_16_TrongridDomain(cfg) || updated
updated = migrate_17_Sync_Hosts(cfg) || updated
updated = migrate_18_S3CompatibleAPI(cfg) || updated
return updated
}
7 changes: 7 additions & 0 deletions s3_compatible_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package config

type S3CompatibleAPI struct {
Enable bool
Address string
HTTPHeaders map[string][]string // Leave nil for default headers
}

0 comments on commit 9badb8e

Please sign in to comment.