Skip to content

Commit

Permalink
config: fix bindings backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Feb 6, 2021
1 parent 8de7a81 commit 05ae0ea
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
tags: 'v*'

env:
GO_VERSION: 1.15.5
GO_VERSION: 1.15.8

jobs:
create-release:
Expand Down
16 changes: 8 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func checkCommonParamsCompatibility() {
}

func checkSFTPDBindingsCompatibility() {
if len(globalConf.SFTPD.Bindings) > 0 {
if globalConf.SFTPD.BindPort == 0 { //nolint:staticcheck
return
}

Expand All @@ -495,11 +495,11 @@ func checkSFTPDBindingsCompatibility() {
binding.Address = globalConf.SFTPD.BindAddress //nolint:staticcheck
}

globalConf.SFTPD.Bindings = append(globalConf.SFTPD.Bindings, binding)
globalConf.SFTPD.Bindings = []sftpd.Binding{binding}
}

func checkFTPDBindingCompatibility() {
if len(globalConf.FTPD.Bindings) > 0 {
if globalConf.FTPD.BindPort == 0 { //nolint:staticcheck
return
}

Expand All @@ -520,11 +520,11 @@ func checkFTPDBindingCompatibility() {
binding.ForcePassiveIP = globalConf.FTPD.ForcePassiveIP //nolint:staticcheck
}

globalConf.FTPD.Bindings = append(globalConf.FTPD.Bindings, binding)
globalConf.FTPD.Bindings = []ftpd.Binding{binding}
}

func checkWebDAVDBindingCompatibility() {
if len(globalConf.WebDAVD.Bindings) > 0 {
if globalConf.WebDAVD.BindPort == 0 { //nolint:staticcheck
return
}

Expand All @@ -539,11 +539,11 @@ func checkWebDAVDBindingCompatibility() {
binding.Address = globalConf.WebDAVD.BindAddress //nolint:staticcheck
}

globalConf.WebDAVD.Bindings = append(globalConf.WebDAVD.Bindings, binding)
globalConf.WebDAVD.Bindings = []webdavd.Binding{binding}
}

func checkHTTPDBindingCompatibility() {
if len(globalConf.HTTPDConfig.Bindings) > 0 {
if globalConf.HTTPDConfig.BindPort == 0 { //nolint:staticcheck
return
}

Expand All @@ -559,7 +559,7 @@ func checkHTTPDBindingCompatibility() {
binding.Address = globalConf.HTTPDConfig.BindAddress //nolint:staticcheck
}

globalConf.HTTPDConfig.Bindings = append(globalConf.HTTPDConfig.Bindings, binding)
globalConf.HTTPDConfig.Bindings = []httpd.Binding{binding}
}

func loadBindingsFromEnv() {
Expand Down
77 changes: 6 additions & 71 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func TestServiceToStart(t *testing.T) {
assert.True(t, config.HasServicesToStart())
}

//nolint:dupl
func TestSFTPDBindingsCompatibility(t *testing.T) {
reset()

Expand All @@ -385,20 +384,11 @@ func TestSFTPDBindingsCompatibility(t *testing.T) {
err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
sftpdConf = config.GetSFTPDConfig()
// even if there is no binding configuration in sftpd conf we load the default
// the default binding should be replaced with the deprecated configuration
require.Len(t, sftpdConf.Bindings, 1)
require.Equal(t, 2022, sftpdConf.Bindings[0].Port)
require.Empty(t, sftpdConf.Bindings[0].Address)
require.Equal(t, 9022, sftpdConf.Bindings[0].Port)
require.Equal(t, "127.0.0.1", sftpdConf.Bindings[0].Address)
require.True(t, sftpdConf.Bindings[0].ApplyProxyConfig)
// now set the global value to nil and reload the configuration
// this time we should get the values setted using the deprecated configuration
sftpdConf.Bindings = nil
sftpdConf.BindPort = 2022 //nolint:staticcheck
sftpdConf.BindAddress = "" //nolint:staticcheck
config.SetSFTPDConfig(sftpdConf)
require.Nil(t, config.GetSFTPDConfig().Bindings)
require.Equal(t, 2022, config.GetSFTPDConfig().BindPort) //nolint:staticcheck
require.Empty(t, config.GetSFTPDConfig().BindAddress) //nolint:staticcheck

err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
Expand All @@ -411,7 +401,6 @@ func TestSFTPDBindingsCompatibility(t *testing.T) {
assert.NoError(t, err)
}

//nolint:dupl
func TestFTPDBindingsCompatibility(t *testing.T) {
reset()

Expand All @@ -436,24 +425,7 @@ func TestFTPDBindingsCompatibility(t *testing.T) {
err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
ftpdConf = config.GetFTPDConfig()
// even if there is no binding configuration in ftpd conf we load the default
require.Len(t, ftpdConf.Bindings, 1)
require.Equal(t, 0, ftpdConf.Bindings[0].Port)
require.Empty(t, ftpdConf.Bindings[0].Address)
require.True(t, ftpdConf.Bindings[0].ApplyProxyConfig)
// now set the global value to nil and reload the configuration
// this time we should get the values setted using the deprecated configuration
ftpdConf.Bindings = nil
ftpdConf.BindPort = 0 //nolint:staticcheck
ftpdConf.BindAddress = "" //nolint:staticcheck
config.SetFTPDConfig(ftpdConf)
require.Nil(t, config.GetFTPDConfig().Bindings)
require.Equal(t, 0, config.GetFTPDConfig().BindPort) //nolint:staticcheck
require.Empty(t, config.GetFTPDConfig().BindAddress) //nolint:staticcheck

err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
ftpdConf = config.GetFTPDConfig()
// the default binding should be replaced with the deprecated configuration
require.Len(t, ftpdConf.Bindings, 1)
require.Equal(t, 9022, ftpdConf.Bindings[0].Port)
require.Equal(t, "127.1.0.1", ftpdConf.Bindings[0].Address)
Expand All @@ -464,7 +436,6 @@ func TestFTPDBindingsCompatibility(t *testing.T) {
assert.NoError(t, err)
}

//nolint:dupl
func TestWebDAVDBindingsCompatibility(t *testing.T) {
reset()

Expand All @@ -487,24 +458,7 @@ func TestWebDAVDBindingsCompatibility(t *testing.T) {
err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
webdavConf = config.GetWebDAVDConfig()
// even if there is no binding configuration in webdav conf we load the default
require.Len(t, webdavConf.Bindings, 1)
require.Equal(t, 0, webdavConf.Bindings[0].Port)
require.Empty(t, webdavConf.Bindings[0].Address)
require.False(t, webdavConf.Bindings[0].EnableHTTPS)
// now set the global value to nil and reload the configuration
// this time we should get the values setted using the deprecated configuration
webdavConf.Bindings = nil
webdavConf.BindPort = 10080 //nolint:staticcheck
webdavConf.BindAddress = "" //nolint:staticcheck
config.SetWebDAVDConfig(webdavConf)
require.Nil(t, config.GetWebDAVDConfig().Bindings)
require.Equal(t, 10080, config.GetWebDAVDConfig().BindPort) //nolint:staticcheck
require.Empty(t, config.GetWebDAVDConfig().BindAddress) //nolint:staticcheck

err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
webdavConf = config.GetWebDAVDConfig()
// the default binding should be replaced with the deprecated configuration
require.Len(t, webdavConf.Bindings, 1)
require.Equal(t, 9080, webdavConf.Bindings[0].Port)
require.Equal(t, "127.0.0.1", webdavConf.Bindings[0].Address)
Expand All @@ -513,7 +467,6 @@ func TestWebDAVDBindingsCompatibility(t *testing.T) {
assert.NoError(t, err)
}

//nolint:dupl
func TestHTTPDBindingsCompatibility(t *testing.T) {
reset()

Expand All @@ -536,25 +489,7 @@ func TestHTTPDBindingsCompatibility(t *testing.T) {
err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
httpdConf = config.GetHTTPDConfig()
// even if there is no binding configuration in httpd conf we load the default
require.Len(t, httpdConf.Bindings, 1)
require.Equal(t, 8080, httpdConf.Bindings[0].Port)
require.Equal(t, "127.0.0.1", httpdConf.Bindings[0].Address)
require.False(t, httpdConf.Bindings[0].EnableHTTPS)
require.True(t, httpdConf.Bindings[0].EnableWebAdmin)
// now set the global value to nil and reload the configuration
// this time we should get the values setted using the deprecated configuration
httpdConf.Bindings = nil
httpdConf.BindPort = 10080 //nolint:staticcheck
httpdConf.BindAddress = "" //nolint:staticcheck
config.SetHTTPDConfig(httpdConf)
require.Nil(t, config.GetHTTPDConfig().Bindings)
require.Equal(t, 10080, config.GetHTTPDConfig().BindPort) //nolint:staticcheck
require.Empty(t, config.GetHTTPDConfig().BindAddress) //nolint:staticcheck

err = config.LoadConfig(configDir, confName)
assert.NoError(t, err)
httpdConf = config.GetHTTPDConfig()
// the default binding should be replaced with the deprecated configuration
require.Len(t, httpdConf.Bindings, 1)
require.Equal(t, 9080, httpdConf.Bindings[0].Port)
require.Equal(t, "127.1.1.1", httpdConf.Bindings[0].Address)
Expand Down
8 changes: 4 additions & 4 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ SFTPGo provides an official Docker image, it is available on both [Docker Hub](h

## Supported tags and respective Dockerfile links

- [v1.2.2, v1.2, v1, latest](https://github.com/drakkan/sftpgo/blob/v1.2.2/Dockerfile.full)
- [v1.2.2-alpine, v1.2-alpine, v1-alpine, alpine](https://github.com/drakkan/sftpgo/blob/v1.2.2/Dockerfile.full.alpine)
- [v1.2.2-slim, v1.2-slim, v1-slim, slim](https://github.com/drakkan/sftpgo/blob/v1.2.2/Dockerfile)
- [v1.2.2-alpine-slim, v1.2-alpine-slim, v1-alpine-slim, alpine-slim](https://github.com/drakkan/sftpgo/blob/v1.2.2/Dockerfile.alpine)
- [v2.0.0, v2.0, v2, latest](https://github.com/drakkan/sftpgo/blob/v2.0.0/Dockerfile.full)
- [v2.0.0-alpine, v2.0-alpine, v2-alpine, alpine](https://github.com/drakkan/sftpgo/blob/v2.0.0/Dockerfile.full.alpine)
- [v2.0.0-slim, v2.0-slim, v2-slim, slim](https://github.com/drakkan/sftpgo/blob/v2.0.0/Dockerfile)
- [v2.0.0-alpine-slim, v2.0-alpine-slim, v2-alpine-slim, alpine-slim](https://github.com/drakkan/sftpgo/blob/v2.0.0/Dockerfile.alpine)
- [edge](../Dockerfile.full)
- [edge-alpine](../Dockerfile.full.alpine)
- [edge-slim](../Dockerfile)
Expand Down
20 changes: 11 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ go 1.15

require (
cloud.google.com/go v0.76.0 // indirect
cloud.google.com/go/storage v1.12.0
cloud.google.com/go/storage v1.13.0
github.com/Azure/azure-storage-blob-go v0.13.0
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962
github.com/alexedwards/argon2id v0.0.0-20201228115903-cf543ebc1f7b
github.com/aws/aws-sdk-go v1.37.2
github.com/aws/aws-sdk-go v1.37.6
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/eikenb/pipeat v0.0.0-20200430215831-470df5986b6d
github.com/fclairamb/ftpserverlib v0.12.0
github.com/frankban/quicktest v1.11.2 // indirect
github.com/frankban/quicktest v1.11.3 // indirect
github.com/go-chi/chi v1.5.1
github.com/go-chi/jwtauth v1.2.0
github.com/go-chi/render v1.0.1
Expand All @@ -22,8 +22,9 @@ require (
github.com/google/uuid v1.2.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/grandcat/zeroconf v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/jlaffaye/ftp v0.0.0-20201112195030-9aae4d151126
github.com/lestrrat-go/jwx v1.1.0
github.com/lestrrat-go/jwx v1.1.1
github.com/lib/pq v1.9.0
github.com/magiconair/properties v1.8.4 // indirect
github.com/mattn/go-sqlite3 v1.14.6
Expand All @@ -36,7 +37,7 @@ require (
github.com/pires/go-proxyproto v0.4.2
github.com/pkg/sftp v1.12.1-0.20201128220914-b5b6f3393fe9
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/procfs v0.3.0 // indirect
github.com/prometheus/procfs v0.4.0 // indirect
github.com/rs/cors v1.7.1-0.20200626170627-8b4a00bd362b
github.com/rs/xid v1.2.1
github.com/rs/zerolog v1.20.0
Expand All @@ -48,19 +49,20 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/studio-b12/gowebdav v0.0.0-20200929080739-bdacfab94796
github.com/studio-b12/gowebdav v0.0.0-20210203212356-8244b5a5f51a
github.com/yl2chen/cidranger v1.0.2
go.etcd.io/bbolt v1.3.5
go.opencensus.io v0.22.6 // indirect
go.uber.org/automaxprocs v1.4.0
gocloud.dev v0.21.0
gocloud.dev/secrets/hashivault v0.21.0
gocloud.dev v0.22.0
gocloud.dev/secrets/hashivault v0.22.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/oauth2 v0.0.0-20210201163806-010130855d6c // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
google.golang.org/api v0.38.0
google.golang.org/api v0.39.0
google.golang.org/genproto v0.0.0-20210204154452-deb828366460 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 05ae0ea

Please sign in to comment.