From 2f2e48304fd02b99083f2abee95d2705a8496b90 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 29 Aug 2023 22:49:37 +0800 Subject: [PATCH 1/2] feat: add s3-compatible-api configure --- config.go | 35 ++++++++++++++++++----------------- init.go | 11 ++++++++++- migrations.go | 11 +++++++++++ s3_compatible_api.go | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 s3_compatible_api.go diff --git a/config.go b/config.go index d38bd98..d7016c5 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/init.go b/init.go index 449c909..e81f379 100644 --- a/init.go +++ b/init.go @@ -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"), @@ -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{ diff --git a/migrations.go b/migrations.go index 8f2c6c6..1fd09d0 100644 --- a/migrations.go +++ b/migrations.go @@ -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 @@ -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 } diff --git a/s3_compatible_api.go b/s3_compatible_api.go new file mode 100644 index 0000000..1bb9838 --- /dev/null +++ b/s3_compatible_api.go @@ -0,0 +1,33 @@ +package config + +const ( + LastModified = "Last-Modified" + Date = "Date" + ETag = "ETag" + ContentType = "Content-Type" + ContentMD5 = "Content-Md5" + ContentEncoding = "Content-Encoding" + Expires = "Expires" + ContentLength = "Content-Length" + ContentLanguage = "Content-Language" + ContentRange = "Content-Range" + Connection = "Connection" + AcceptRanges = "Accept-Ranges" + AmzBucketRegion = "X-Amz-Bucket-Region" + ServerInfo = "Server" + RetryAfter = "Retry-After" + Location = "Location" + CacheControl = "Cache-Control" + ContentDisposition = "Content-Disposition" + Authorization = "Authorization" + Action = "Action" + XRequestWith = "X-Requested-With" + Range = "Range" + UserAgent = "User-Agent" +) + +type S3CompatibleAPI struct { + Enable bool + Address string + HTTPHeaders map[string][]string // HTTP headers to return with the gateway, Note: AWS Headers with same key here will be covered +} From 16001c938b27b53a43bedf8aa2558a06401ab724 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 30 Aug 2023 00:07:52 +0800 Subject: [PATCH 2/2] chore: remove used consts and optmize comment --- s3_compatible_api.go | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/s3_compatible_api.go b/s3_compatible_api.go index 1bb9838..bf69abd 100644 --- a/s3_compatible_api.go +++ b/s3_compatible_api.go @@ -1,33 +1,7 @@ package config -const ( - LastModified = "Last-Modified" - Date = "Date" - ETag = "ETag" - ContentType = "Content-Type" - ContentMD5 = "Content-Md5" - ContentEncoding = "Content-Encoding" - Expires = "Expires" - ContentLength = "Content-Length" - ContentLanguage = "Content-Language" - ContentRange = "Content-Range" - Connection = "Connection" - AcceptRanges = "Accept-Ranges" - AmzBucketRegion = "X-Amz-Bucket-Region" - ServerInfo = "Server" - RetryAfter = "Retry-After" - Location = "Location" - CacheControl = "Cache-Control" - ContentDisposition = "Content-Disposition" - Authorization = "Authorization" - Action = "Action" - XRequestWith = "X-Requested-With" - Range = "Range" - UserAgent = "User-Agent" -) - type S3CompatibleAPI struct { Enable bool Address string - HTTPHeaders map[string][]string // HTTP headers to return with the gateway, Note: AWS Headers with same key here will be covered + HTTPHeaders map[string][]string // Leave nil for default headers }