mirror of
https://github.com/khairul169/garage-webui.git
synced 2025-04-28 14:59:31 +07:00
fix: make s3_region configurable to support values other than "garage"
This commit is contained in:
parent
c1619276c0
commit
37027396ca
@ -16,7 +16,7 @@ func main() {
|
|||||||
utils.InitCacheManager()
|
utils.InitCacheManager()
|
||||||
|
|
||||||
if err := utils.Garage.LoadConfig(); err != nil {
|
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()))
|
http.Handle("/api/", http.StripPrefix("/api", router.HandleApiRouter()))
|
||||||
|
@ -300,7 +300,7 @@ func getS3Client(bucket string) (*s3.Client, error) {
|
|||||||
|
|
||||||
awsConfig := aws.Config{
|
awsConfig := aws.Config{
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
Region: "garage",
|
Region: utils.Garage.GetS3Region(),
|
||||||
BaseEndpoint: aws.String(utils.Garage.GetS3Endpoint()),
|
BaseEndpoint: aws.String(utils.Garage.GetS3Endpoint()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"khairul169/garage-webui/schema"
|
"khairul169/garage-webui/schema"
|
||||||
@ -73,6 +74,17 @@ func (g *garage) GetS3Endpoint() string {
|
|||||||
return endpoint
|
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 {
|
func (g *garage) GetAdminKey() string {
|
||||||
key := os.Getenv("API_ADMIN_KEY")
|
key := os.Getenv("API_ADMIN_KEY")
|
||||||
if len(key) > 0 {
|
if len(key) > 0 {
|
||||||
@ -153,7 +165,7 @@ func (g *garage) Fetch(url string, options *FetchOptions) ([]byte, error) {
|
|||||||
message = fmt.Sprintf("%v", data["message"])
|
message = fmt.Sprintf("%v", data["message"])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf(message)
|
return nil, errors.New(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := io.ReadAll(res.Body)
|
body, err := io.ReadAll(res.Body)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user