Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions cmd/lfsd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/cockroachdb/errors"
"gopkg.in/ini.v1"
"unknwon.dev/ini/v2"

"unknwon.dev/git-lfs-server/internal/database"
"unknwon.dev/git-lfs-server/internal/embed"
Expand Down Expand Up @@ -34,13 +34,8 @@ type LogConfig struct {
Level string `ini:"LEVEL"`
}

const (
storageSectionPrefix = `storage "`
forgeSectionPrefix = `forge "`
)

func loadConfig(customPath string) (*Config, error) {
f, err := ini.Load(embed.Config)
f, err := ini.Load(embed.Config, ini.ValueMapping(os.ExpandEnv))
if err != nil {
return nil, errors.Wrap(err, "load embedded config")
}
Expand All @@ -49,7 +44,6 @@ func loadConfig(customPath string) (*Config, error) {
return nil, errors.Wrapf(err, "load custom config %q", customPath)
}
}
f.ValueMapper = os.ExpandEnv

var c Config

Expand All @@ -64,15 +58,7 @@ func loadConfig(customPath string) (*Config, error) {
}

backendsByName := make(map[string]storage.Backend)
for _, s := range f.Sections() {
rest, ok := strings.CutPrefix(s.Name(), storageSectionPrefix)
if !ok {
continue
}
name, ok := strings.CutSuffix(rest, `"`)
if !ok {
return nil, errors.Newf("malformed storage section name %q", s.Name())
}
for name, s := range f.Subsections("storage") {
if _, dup := backendsByName[name]; dup {
return nil, errors.Newf("duplicate storage configuration for name %q", name)
}
Expand Down Expand Up @@ -110,15 +96,7 @@ func loadConfig(customPath string) (*Config, error) {

c.Forges = make(map[string]forge.Provider)
c.Storages = make(map[string]storage.Backend)
for _, s := range f.Sections() {
rest, ok := strings.CutPrefix(s.Name(), forgeSectionPrefix)
if !ok {
continue
}
host, ok := strings.CutSuffix(rest, `"`)
if !ok {
return nil, errors.Newf("malformed forge section name %q", s.Name())
}
for host, s := range f.Subsections("forge") {
host = strings.ToLower(host)
if _, dup := c.Forges[host]; dup {
return nil, errors.Newf("duplicate forge configuration for host %q", host)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
github.com/sourcegraph/run v0.12.0
github.com/stretchr/testify v1.11.1
go.bobheadxi.dev/streamline v1.3.2
gopkg.in/ini.v1 v1.67.2
gorm.io/driver/postgres v1.6.0
gorm.io/gorm v1.31.1
unknwon.dev/ini/v2 v2.0.0-beta.4
)

require (
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,8 @@ github.com/sourcegraph/run v0.12.0/go.mod h1:PwaP936BTnAJC1cqR5rSbG5kOs/EWStTK3l
github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M=
github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
Expand Down Expand Up @@ -236,8 +230,6 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.2 h1:JtOSMb9OuaCZKr7h5D/h6iii14sK0hLbplTc6frx4Ss=
gopkg.in/ini.v1 v1.67.2/go.mod h1:x/cyOwCgZqOkJoDIJ3c1KNHMo10+nLGAhh+kn3Zizss=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand All @@ -249,3 +241,5 @@ gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
mvdan.cc/gofumpt v0.5.0 h1:0EQ+Z56k8tXjj/6TQD25BFNKQXpCvT0rnansIc7Ug5E=
mvdan.cc/gofumpt v0.5.0/go.mod h1:HBeVDtMKRZpXyxFciAirzdKklDlGu8aAy1wEbH5Y9js=
unknwon.dev/ini/v2 v2.0.0-beta.4 h1:W1mOu7vP8QCdq1b6rDFzYmzZs/vQ4FCIRbQVgZ82z3U=
unknwon.dev/ini/v2 v2.0.0-beta.4/go.mod h1:pEeiEmFhx52IIFUwFqZcepgj8i3AFkxt9yDO4xHK45w=
Loading