Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn users if deprecated parameters are being used #4080

Merged
merged 1 commit into from
Dec 25, 2024
Merged
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
4 changes: 4 additions & 0 deletions .github/DISCUSSION_TEMPLATE/questions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
body:
- type: markdown
attributes:
value: |
Please create a discussion FOR EACH question. Do not ask for multiple questions all at once, otherwise they'll probably never get all answered.

- type: textarea
attributes:
Expand Down
12 changes: 6 additions & 6 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (a *API) onConfigGlobalPatch(ctx *gin.Context) {

newConf.PatchGlobal(&c)

err = newConf.Validate()
err = newConf.Validate(nil)
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -367,7 +367,7 @@ func (a *API) onConfigPathDefaultsPatch(ctx *gin.Context) {

newConf.PatchPathDefaults(&p)

err = newConf.Validate()
err = newConf.Validate(nil)
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -448,7 +448,7 @@ func (a *API) onConfigPathsAdd(ctx *gin.Context) { //nolint:dupl
return
}

err = newConf.Validate()
err = newConf.Validate(nil)
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -489,7 +489,7 @@ func (a *API) onConfigPathsPatch(ctx *gin.Context) { //nolint:dupl
return
}

err = newConf.Validate()
err = newConf.Validate(nil)
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -530,7 +530,7 @@ func (a *API) onConfigPathsReplace(ctx *gin.Context) { //nolint:dupl
return
}

err = newConf.Validate()
err = newConf.Validate(nil)
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -564,7 +564,7 @@ func (a *API) onConfigPathsDelete(ctx *gin.Context) {
return
}

err = newConf.Validate()
err = newConf.Validate(nil)
if err != nil {
a.writeError(ctx, http.StatusBadRequest, err)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func tempConf(t *testing.T, cnt string) *conf.Conf {
require.NoError(t, err)
defer os.Remove(fi)

cnf, _, err := conf.Load(fi, nil)
cnf, _, err := conf.Load(fi, nil, nil)
require.NoError(t, err)

return cnf
Expand Down
54 changes: 50 additions & 4 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
}

// Load loads a Conf.
func Load(fpath string, defaultConfPaths []string) (*Conf, string, error) {
func Load(fpath string, defaultConfPaths []string, l logger.Writer) (*Conf, string, error) {
conf := &Conf{}

fpath, err := conf.loadFromFile(fpath, defaultConfPaths)
Expand All @@ -432,7 +432,7 @@
return nil, "", err
}

err = conf.Validate()
err = conf.Validate(l)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -495,8 +495,17 @@
return &dest
}

type nilLogger struct{}

func (nilLogger) Log(_ logger.Level, _ string, _ ...interface{}) {
}

// Validate checks the configuration for errors.
func (conf *Conf) Validate() error {
func (conf *Conf) Validate(l logger.Writer) error {
if l == nil {
l = &nilLogger{}
}

// General

if conf.ReadTimeout <= 0 {
Expand All @@ -506,6 +515,7 @@
return fmt.Errorf("'writeTimeout' must be greater than zero")
}
if conf.ReadBufferCount != nil {
l.Log(logger.Warn, "parameter 'readBufferCount' is deprecated and has been replaced with 'writeQueueSize'")

Check warning on line 518 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L518

Added line #L518 was not covered by tests
conf.WriteQueueSize = *conf.ReadBufferCount
}
if (conf.WriteQueueSize & (conf.WriteQueueSize - 1)) != 0 {
Expand All @@ -518,6 +528,8 @@
// Authentication

if conf.ExternalAuthenticationURL != nil {
l.Log(logger.Warn, "parameter 'externalAuthenticationURL' is deprecated "+
"and has been replaced with 'authMethod' and 'authHTTPAddress'")

Check warning on line 532 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L531-L532

Added lines #L531 - L532 were not covered by tests
conf.AuthMethod = AuthMethodHTTP
conf.AuthHTTPAddress = *conf.ExternalAuthenticationURL
}
Expand All @@ -533,6 +545,10 @@
}
deprecatedCredentialsMode := false
if anyPathHasDeprecatedCredentials(conf.PathDefaults, conf.OptionalPaths) {
l.Log(logger.Warn, "you are using one or more authentication-related deprecated parameters "+
"(publishUser, publishPass, publishIPs, readUser, readPass, readIPs). "+
"These have been replaced by 'authInternalUsers'")

if conf.AuthInternalUsers != nil && !reflect.DeepEqual(conf.AuthInternalUsers, defaultAuthInternalUsers) {
return fmt.Errorf("authInternalUsers and legacy credentials " +
"(publishUser, publishPass, publishIPs, readUser, readPass, readIPs) cannot be used together")
Expand Down Expand Up @@ -583,12 +599,15 @@
// RTSP

if conf.RTSPDisable != nil {
l.Log(logger.Warn, "parameter 'rtspDisabled' is deprecated and has been replaced with 'rtsp'")

Check warning on line 602 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L602

Added line #L602 was not covered by tests
conf.RTSP = !*conf.RTSPDisable
}
if conf.Protocols != nil {
l.Log(logger.Warn, "parameter 'protocols' is deprecated and has been replaced with 'rtspTransports'")
conf.RTSPTransports = *conf.Protocols
}
if conf.Encryption != nil {
l.Log(logger.Warn, "parameter 'encryption' is deprecated and has been replaced with 'rtspEncryption'")

Check warning on line 610 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L610

Added line #L610 was not covered by tests
conf.RTSPEncryption = *conf.Encryption
}
if conf.RTSPEncryption == EncryptionStrict {
Expand All @@ -600,6 +619,7 @@
}
}
if conf.AuthMethods != nil {
l.Log(logger.Warn, "parameter 'authMethods' is deprecated and has been replaced with 'rtspAuthMethods'")

Check warning on line 622 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L622

Added line #L622 was not covered by tests
conf.RTSPAuthMethods = *conf.AuthMethods
}
if contains(conf.RTSPAuthMethods, auth.ValidateMethodDigestMD5) {
Expand All @@ -613,39 +633,53 @@
}
}
if conf.ServerCert != nil {
l.Log(logger.Warn, "parameter 'serverCert' is deprecated and has been replaced with 'rtspServerCert'")

Check warning on line 636 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L636

Added line #L636 was not covered by tests
conf.RTSPServerCert = *conf.ServerCert
}
if conf.ServerKey != nil {
l.Log(logger.Warn, "parameter 'serverKey' is deprecated and has been replaced with 'rtspServerKey'")

Check warning on line 640 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L640

Added line #L640 was not covered by tests
conf.RTSPServerKey = *conf.ServerKey
}

// RTMP

if conf.RTMPDisable != nil {
l.Log(logger.Warn, "parameter 'rtmpDisabled' is deprecated and has been replaced with 'rtmp'")
conf.RTMP = !*conf.RTMPDisable
}

// HLS

if conf.HLSDisable != nil {
l.Log(logger.Warn, "parameter 'hlsDisable' is deprecated and has been replaced with 'hls'")

Check warning on line 654 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L654

Added line #L654 was not covered by tests
conf.HLS = !*conf.HLSDisable
}

// WebRTC

if conf.WebRTCDisable != nil {
l.Log(logger.Warn, "parameter 'webrtcDisable' is deprecated and has been replaced with 'webrtc'")

Check warning on line 661 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L661

Added line #L661 was not covered by tests
conf.WebRTC = !*conf.WebRTCDisable
}
if conf.WebRTCICEUDPMuxAddress != nil {
l.Log(logger.Warn, "parameter 'webrtcICEUDPMuxAdderss' is deprecated "+
"and has been replaced with 'webrtcLocalUDPAddress'")

Check warning on line 666 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L665-L666

Added lines #L665 - L666 were not covered by tests
conf.WebRTCLocalUDPAddress = *conf.WebRTCICEUDPMuxAddress
}
if conf.WebRTCICETCPMuxAddress != nil {
l.Log(logger.Warn, "parameter 'webrtcICETCPMuxAddress' is deprecated "+
"and has been replaced with 'webrtcLocalTCPAddress'")

Check warning on line 671 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L670-L671

Added lines #L670 - L671 were not covered by tests
conf.WebRTCLocalTCPAddress = *conf.WebRTCICETCPMuxAddress
}
if conf.WebRTCICEHostNAT1To1IPs != nil {
l.Log(logger.Warn, "parameter 'webrtcICEHostNAT1To1IPs' is deprecated "+
"and has been replaced with 'webrtcAdditionalHosts'")

Check warning on line 676 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L675-L676

Added lines #L675 - L676 were not covered by tests
conf.WebRTCAdditionalHosts = *conf.WebRTCICEHostNAT1To1IPs
}
if conf.WebRTCICEServers != nil {
l.Log(logger.Warn, "parameter 'webrtcICEServers' is deprecated "+
"and has been replaced with 'webrtcICEServers2'")

for _, server := range *conf.WebRTCICEServers {
parts := strings.Split(server, ":")
if len(parts) == 5 {
Expand Down Expand Up @@ -683,21 +717,33 @@
// Record (deprecated)

if conf.Record != nil {
l.Log(logger.Warn, "parameter 'record' is deprecated "+
"and has been replaced with 'pathDefaults.record'")

Check warning on line 721 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L720-L721

Added lines #L720 - L721 were not covered by tests
conf.PathDefaults.Record = *conf.Record
}
if conf.RecordPath != nil {
l.Log(logger.Warn, "parameter 'recordPath' is deprecated "+
"and has been replaced with 'pathDefaults.recordPath'")

Check warning on line 726 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L725-L726

Added lines #L725 - L726 were not covered by tests
conf.PathDefaults.RecordPath = *conf.RecordPath
}
if conf.RecordFormat != nil {
l.Log(logger.Warn, "parameter 'recordFormat' is deprecated "+
"and has been replaced with 'pathDefaults.recordFormat'")

Check warning on line 731 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L730-L731

Added lines #L730 - L731 were not covered by tests
conf.PathDefaults.RecordFormat = *conf.RecordFormat
}
if conf.RecordPartDuration != nil {
l.Log(logger.Warn, "parameter 'recordPartDuration' is deprecated "+
"and has been replaced with 'pathDefaults.recordPartDuration'")

Check warning on line 736 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L735-L736

Added lines #L735 - L736 were not covered by tests
conf.PathDefaults.RecordPartDuration = *conf.RecordPartDuration
}
if conf.RecordSegmentDuration != nil {
l.Log(logger.Warn, "parameter 'recordSegmentDuration' is deprecated "+
"and has been replaced with 'pathDefaults.recordSegmentDuration'")

Check warning on line 741 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L740-L741

Added lines #L740 - L741 were not covered by tests
conf.PathDefaults.RecordSegmentDuration = *conf.RecordSegmentDuration
}
if conf.RecordDeleteAfter != nil {
l.Log(logger.Warn, "parameter 'recordDeleteAfter' is deprecated "+
"and has been replaced with 'pathDefaults.recordDeleteAfter'")

Check warning on line 746 in internal/conf/conf.go

View check run for this annotation

Codecov / codecov/patch

internal/conf/conf.go#L745-L746

Added lines #L745 - L746 were not covered by tests
conf.PathDefaults.RecordDeleteAfter = *conf.RecordDeleteAfter
}

Expand Down Expand Up @@ -727,7 +773,7 @@
}

for _, name := range sortedKeys(conf.OptionalPaths) {
err := conf.Paths[name].validate(conf, name, deprecatedCredentialsMode)
err := conf.Paths[name].validate(conf, name, deprecatedCredentialsMode, l)
if err != nil {
return err
}
Expand Down
28 changes: 14 additions & 14 deletions internal/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestConfFromFile(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

conf, confPath, err := Load(tmpf, nil)
conf, confPath, err := Load(tmpf, nil, nil)
require.NoError(t, err)
require.Equal(t, tmpf, confPath)

Expand Down Expand Up @@ -88,7 +88,7 @@ func TestConfFromFile(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

_, _, err = Load(tmpf, nil)
_, _, err = Load(tmpf, nil, nil)
require.NoError(t, err)
}()

Expand All @@ -97,7 +97,7 @@ func TestConfFromFile(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

_, _, err = Load(tmpf, nil)
_, _, err = Load(tmpf, nil, nil)
require.NoError(t, err)
}()

Expand All @@ -108,7 +108,7 @@ func TestConfFromFile(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

_, _, err = Load(tmpf, nil)
_, _, err = Load(tmpf, nil, nil)
require.NoError(t, err)
}()
}
Expand All @@ -130,7 +130,7 @@ func TestConfFromFileAndEnv(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

conf, confPath, err := Load(tmpf, nil)
conf, confPath, err := Load(tmpf, nil, nil)
require.NoError(t, err)
require.Equal(t, tmpf, confPath)

Expand All @@ -149,7 +149,7 @@ func TestConfFromFileAndEnv(t *testing.T) {
func TestConfFromEnvOnly(t *testing.T) {
t.Setenv("MTX_PATHS_CAM1_SOURCE", "rtsp://testing")

conf, confPath, err := Load("", nil)
conf, confPath, err := Load("", nil, nil)
require.NoError(t, err)
require.Equal(t, "", confPath)

Expand Down Expand Up @@ -182,7 +182,7 @@ func TestConfEncryption(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

conf, confPath, err := Load(tmpf, nil)
conf, confPath, err := Load(tmpf, nil, nil)
require.NoError(t, err)
require.Equal(t, tmpf, confPath)

Expand All @@ -202,7 +202,7 @@ func TestConfDeprecatedAuth(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

conf, _, err := Load(tmpf, nil)
conf, _, err := Load(tmpf, nil, nil)
require.NoError(t, err)

require.Equal(t, AuthInternalUsers{
Expand Down Expand Up @@ -380,37 +380,37 @@ func TestConfErrors(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

_, _, err = Load(tmpf, nil)
_, _, err = Load(tmpf, nil, nil)
require.EqualError(t, err, ca.err)
})
}
}

func TestSampleConfFile(t *testing.T) {
func() {
conf1, confPath1, err := Load("../../mediamtx.yml", nil)
conf1, confPath1, err := Load("../../mediamtx.yml", nil, nil)
require.NoError(t, err)
require.Equal(t, "../../mediamtx.yml", confPath1)
conf1.Paths = make(map[string]*Path)
conf1.OptionalPaths = nil

conf2, confPath2, err := Load("", nil)
conf2, confPath2, err := Load("", nil, nil)
require.NoError(t, err)
require.Equal(t, "", confPath2)

require.Equal(t, conf1, conf2)
}()

func() {
conf1, confPath1, err := Load("../../mediamtx.yml", nil)
conf1, confPath1, err := Load("../../mediamtx.yml", nil, nil)
require.NoError(t, err)
require.Equal(t, "../../mediamtx.yml", confPath1)

tmpf, err := createTempFile([]byte("paths:\n all_others:"))
require.NoError(t, err)
defer os.Remove(tmpf)

conf2, confPath2, err := Load(tmpf, nil)
conf2, confPath2, err := Load(tmpf, nil, nil)
require.NoError(t, err)
require.Equal(t, tmpf, confPath2)

Expand All @@ -429,7 +429,7 @@ func TestConfOverrideDefaultSlices(t *testing.T) {
require.NoError(t, err)
defer os.Remove(tmpf)

conf, _, err := Load(tmpf, nil)
conf, _, err := Load(tmpf, nil, nil)
require.NoError(t, err)

require.Equal(t, AuthInternalUsers{
Expand Down
Loading
Loading