Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add s3-compatible-api configure #8

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}