fix: make s3_region configurable to support values other than "garage"

This commit is contained in:
Khairul Hidayat 2024-10-13 22:54:47 +00:00
parent c1619276c0
commit 37027396ca
3 changed files with 15 additions and 3 deletions

View File

@ -16,7 +16,7 @@ func main() {
utils.InitCacheManager()
if err := utils.Garage.LoadConfig(); err != nil {
log.Fatal("Failed to load config! ", err)
log.Println("Cannot load garage config!", err)
}
http.Handle("/api/", http.StripPrefix("/api", router.HandleApiRouter()))

View File

@ -300,7 +300,7 @@ func getS3Client(bucket string) (*s3.Client, error) {
awsConfig := aws.Config{
Credentials: creds,
Region: "garage",
Region: utils.Garage.GetS3Region(),
BaseEndpoint: aws.String(utils.Garage.GetS3Endpoint()),
}

View File

@ -3,6 +3,7 @@ package utils
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"khairul169/garage-webui/schema"
@ -73,6 +74,17 @@ func (g *garage) GetS3Endpoint() string {
return endpoint
}
func (g *garage) GetS3Region() string {
endpoint := os.Getenv("S3_REGION")
if len(endpoint) > 0 {
return endpoint
}
if len(g.Config.S3API.S3Region) == 0 {
return "garage"
}
return g.Config.S3API.S3Region
}
func (g *garage) GetAdminKey() string {
key := os.Getenv("API_ADMIN_KEY")
if len(key) > 0 {
@ -153,7 +165,7 @@ func (g *garage) Fetch(url string, options *FetchOptions) ([]byte, error) {
message = fmt.Sprintf("%v", data["message"])
}
return nil, fmt.Errorf(message)
return nil, errors.New(message)
}
body, err := io.ReadAll(res.Body)