@@ -196,14 +196,78 @@ func objectStoreStarTramEnabled(conf structs.SysConfig) bool {
196196 return conf .WgRegistered && conf .WgOn
197197}
198198
199+ func normalizedObjectStoreCustomDomain (domain string ) string {
200+ domain = strings .TrimSpace (domain )
201+ if strings .EqualFold (domain , "null" ) {
202+ return ""
203+ }
204+ return domain
205+ }
206+
207+ func ObjectStoreUsesRemoteDomain (conf structs.SysConfig , shipConf structs.UrbitDocker ) bool {
208+ return objectStoreStarTramEnabled (conf ) &&
209+ shipConf .Network == "wireguard" &&
210+ strings .TrimSpace (shipConf .WgURL ) != ""
211+ }
212+
213+ func ObjectStoreCustomDomainMode (conf structs.SysConfig , shipConf structs.UrbitDocker ) string {
214+ if ObjectStoreUsesRemoteDomain (conf , shipConf ) {
215+ return "remote"
216+ }
217+ return "local"
218+ }
219+
220+ func objectStoreCustomDomainForMode (shipConf structs.UrbitDocker , mode string ) string {
221+ switch mode {
222+ case "remote" :
223+ if domain := normalizedObjectStoreCustomDomain (shipConf .CustomS3WebRemote ); domain != "" {
224+ return domain
225+ }
226+ default :
227+ if domain := normalizedObjectStoreCustomDomain (shipConf .CustomS3WebLocal ); domain != "" {
228+ return domain
229+ }
230+ }
231+ return normalizedObjectStoreCustomDomain (shipConf .CustomS3Web )
232+ }
233+
234+ func ObjectStoreCustomDomain (conf structs.SysConfig , shipConf structs.UrbitDocker ) string {
235+ return objectStoreCustomDomainForMode (shipConf , ObjectStoreCustomDomainMode (conf , shipConf ))
236+ }
237+
238+ func ObjectStoreCustomDomains (shipConf structs.UrbitDocker ) []string {
239+ domains := []string {}
240+ for _ , candidate := range []string {
241+ normalizedObjectStoreCustomDomain (shipConf .CustomS3WebLocal ),
242+ normalizedObjectStoreCustomDomain (shipConf .CustomS3WebRemote ),
243+ normalizedObjectStoreCustomDomain (shipConf .CustomS3Web ),
244+ } {
245+ if candidate != "" && ! contains (domains , candidate ) {
246+ domains = append (domains , candidate )
247+ }
248+ }
249+ return domains
250+ }
251+
252+ func SetObjectStoreCustomDomain (conf structs.SysConfig , shipConf * structs.UrbitDocker , domain string ) {
253+ domain = normalizedObjectStoreCustomDomain (domain )
254+ switch ObjectStoreCustomDomainMode (conf , * shipConf ) {
255+ case "remote" :
256+ shipConf .CustomS3WebRemote = domain
257+ default :
258+ shipConf .CustomS3WebLocal = domain
259+ }
260+ structs .SyncCustomS3Domains (shipConf )
261+ }
262+
199263func objectStoreOfflineHostPorts (shipConf structs.UrbitDocker ) (int , int ) {
200264 consolePort := shipConf .HTTPPort + offlineRustFSConsoleOffset
201265 s3Port := shipConf .HTTPPort + offlineRustFSS3Offset
202266 return s3Port , consolePort
203267}
204268
205269func objectStorePorts (conf structs.SysConfig , shipConf structs.UrbitDocker ) objectStorePortConfig {
206- if objectStoreStarTramEnabled (conf ) {
270+ if ObjectStoreUsesRemoteDomain (conf , shipConf ) {
207271 return objectStorePortConfig {
208272 useWireguard : true ,
209273 listenS3Port : shipConf .WgS3Port ,
@@ -231,10 +295,10 @@ func objectStoreAdminEndpoint(conf structs.SysConfig, patp string, shipConf stru
231295}
232296
233297func objectStoreLinkEndpoint (conf structs.SysConfig , shipConf structs.UrbitDocker ) string {
234- if endpoint := strings .TrimSpace (shipConf . CustomS3Web ); endpoint != "" {
298+ if endpoint := strings .TrimSpace (ObjectStoreCustomDomain ( conf , shipConf ) ); endpoint != "" {
235299 return endpoint
236300 }
237- if objectStoreStarTramEnabled (conf ) && strings . TrimSpace ( shipConf . WgURL ) != "" {
301+ if ObjectStoreUsesRemoteDomain (conf , shipConf ) {
238302 return fmt .Sprintf ("s3.%s" , shipConf .WgURL )
239303 }
240304 hostS3Port , _ := objectStoreOfflineHostPorts (shipConf )
@@ -249,7 +313,7 @@ func GetObjectStoreLinkEndpoint(patp string) (string, error) {
249313}
250314
251315func ObjectStoreConsoleURL (hostName string , conf structs.SysConfig , shipConf structs.UrbitDocker ) string {
252- if objectStoreStarTramEnabled (conf ) && strings . TrimSpace ( shipConf . WgURL ) != "" {
316+ if ObjectStoreUsesRemoteDomain (conf , shipConf ) {
253317 return fmt .Sprintf ("https://console.s3.%s/rustfs/console/index.html" , shipConf .WgURL )
254318 }
255319 _ , hostConsolePort := objectStoreOfflineHostPorts (shipConf )
@@ -399,7 +463,7 @@ func minioContainerConf(containerName string) (container.Config, container.HostC
399463 return containerConfig , hostConfig , fmt .Errorf ("invalid offline RustFS host ports for %s" , shipName )
400464 }
401465
402- serverDomains := objectStoreServerDomains (shipConf )
466+ serverDomains := objectStoreServerDomains (conf , shipConf )
403467 environment := []string {
404468 fmt .Sprintf ("RUSTFS_ACCESS_KEY=%s" , shipName ),
405469 fmt .Sprintf ("RUSTFS_SECRET_KEY=%s" , storePwd ),
@@ -500,18 +564,20 @@ func normalizeObjectStoreDomain(domain string) string {
500564 return strings .TrimSpace (strings .Trim (domain , "/" ))
501565}
502566
503- func objectStoreServerDomains (shipConf structs.UrbitDocker ) string {
567+ func objectStoreServerDomains (conf structs. SysConfig , shipConf structs.UrbitDocker ) string {
504568 var domains []string
505569 baseDomain := strings .TrimSpace (shipConf .WgURL )
506- if baseDomain != "" {
570+ if ObjectStoreUsesRemoteDomain ( conf , shipConf ) && baseDomain != "" {
507571 defaultDomain := normalizeObjectStoreDomain (fmt .Sprintf ("s3.%s" , baseDomain ))
508572 if defaultDomain != "" {
509573 domains = append (domains , defaultDomain )
510574 }
511575 }
512- customDomain := normalizeObjectStoreDomain (shipConf .CustomS3Web )
513- if customDomain != "" && ! contains (domains , customDomain ) {
514- domains = append (domains , customDomain )
576+ for _ , customDomain := range ObjectStoreCustomDomains (shipConf ) {
577+ normalized := normalizeObjectStoreDomain (customDomain )
578+ if normalized != "" && ! contains (domains , normalized ) {
579+ domains = append (domains , normalized )
580+ }
515581 }
516582 return strings .Join (domains , "," )
517583}
0 commit comments