Skip to content
Snippets Groups Projects
Commit 8c05fe43 authored by Ophestra's avatar Ophestra
Browse files

return error properly after reading metadata, add TrustedProxies as a configuration entry

parent 9e1d5a05
No related branches found
No related tags found
No related merge requests found
...@@ -398,8 +398,11 @@ func (s *Store) ImageSnowflakeHash(flake string) (string, error) { ...@@ -398,8 +398,11 @@ func (s *Store) ImageSnowflakeHash(flake string) (string, error) {
} }
if !s.Compat { if !s.Compat {
img, err := s.imageMetadataRead(s.ImageSnowflakePath(flake) + "/" + infoJson) if img, err := s.imageMetadataRead(s.ImageSnowflakePath(flake) + "/" + infoJson); err != nil {
return img.Hash, err return "", err
} else {
return img.Hash, nil
}
} else { } else {
if path, err := os.ReadFile(s.ImageSnowflakePath(flake)); err != nil { if path, err := os.ReadFile(s.ImageSnowflakePath(flake)); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
...@@ -408,8 +411,11 @@ func (s *Store) ImageSnowflakeHash(flake string) (string, error) { ...@@ -408,8 +411,11 @@ func (s *Store) ImageSnowflakeHash(flake string) (string, error) {
return "", err return "", err
} else { } else {
var img *store.Image var img *store.Image
img, err = s.imageMetadataRead(string(path) + "/" + infoJson) if img, err = s.imageMetadataRead(string(path) + "/" + infoJson); err != nil {
return img.Hash, err return "", err
} else {
return img.Hash, nil
}
} }
} }
} }
......
...@@ -14,10 +14,11 @@ type conf struct { ...@@ -14,10 +14,11 @@ type conf struct {
} }
type serverConf struct { type serverConf struct {
Host string `toml:"host"` Host string `toml:"host"`
Unix bool `toml:"unix"` Unix bool `toml:"unix"`
Port uint16 `toml:"port"` Port uint16 `toml:"port"`
Proxy bool `toml:"proxy"` Proxy bool `toml:"proxy"`
TrustedProxies []string `toml:"trusted_proxies"`
} }
type systemConf struct { type systemConf struct {
...@@ -79,5 +80,10 @@ var defConf = conf{ ...@@ -79,5 +80,10 @@ var defConf = conf{
Unix: false, Unix: false,
Port: 7777, Port: 7777,
Proxy: true, Proxy: true,
TrustedProxies: []string{
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
},
}, },
} }
...@@ -27,10 +27,13 @@ func webSetup() { ...@@ -27,10 +27,13 @@ func webSetup() {
} }
router = gin.New() router = gin.New()
router.Use(recovery())
router.ForwardedByClientIP = config.Server.Proxy router.ForwardedByClientIP = config.Server.Proxy
router.TrustedProxies = config.Server.TrustedProxies
if config.System.Verbose { if config.System.Verbose {
router.Use(gin.Logger()) router.Use(gin.Logger())
router.Use(gin.Recovery())
} else {
router.Use(recovery())
} }
router.NoRoute(func(context *gin.Context) { router.NoRoute(func(context *gin.Context) {
context.Redirect(http.StatusTemporaryRedirect, "/web") context.Redirect(http.StatusTemporaryRedirect, "/web")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment