rename 'all' path configuration into 'all_others' (#2443)

This commit is contained in:
Alessandro Ros 2023-10-09 18:13:44 +02:00 committed by GitHub
parent 8a633d2b79
commit 6c727b4472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 75 additions and 52 deletions

View File

@ -15,7 +15,7 @@ CONF="${CONF}rtspAddress: :8555\n"
CONF="${CONF}rtpAddress: :8002\n"
CONF="${CONF}rtcpAddress: :8003\n"
CONF="${CONF}paths:\n"
CONF="${CONF} all:\n"
CONF="${CONF} all_others:\n"
echo -e "$CONF" > /source.conf
/mediamtx /source.conf &

View File

@ -9,7 +9,7 @@ PUBLISHER_PROTOCOL=tcp
CONF=""
CONF="${CONF}pprof: yes\n"
CONF="${CONF}paths:\n"
CONF="${CONF} all:\n"
CONF="${CONF} all_others:\n"
echo -e "$CONF" > /source.conf
/mediamtx /source.conf &

View File

@ -9,7 +9,7 @@ READER_PROTOCOL=tcp
CONF=""
CONF="${CONF}pprof: yes\n"
CONF="${CONF}paths:\n"
CONF="${CONF} all:\n"
CONF="${CONF} all_others:\n"
echo -e "$CONF" > /source.conf
/mediamtx /source.conf &

View File

@ -426,6 +426,16 @@ func (conf *Conf) Check() error {
conf.PathDefaults.RecordDeleteAfter = *conf.RecordDeleteAfter
}
hasAllOthers := false
for name := range conf.OptionalPaths {
if name == "all" || name == "all_others" || name == "~^.*$" {
if hasAllOthers {
return fmt.Errorf("all_others, all and '~^.*$' are aliases")
}
hasAllOthers = true
}
}
conf.Paths = make(map[string]*Path)
for _, name := range sortedKeys(conf.OptionalPaths) {

View File

@ -282,6 +282,20 @@ func TestConfErrors(t *testing.T) {
" srtReadPassphrase: a\n",
`invalid 'readRTPassphrase': must be between 10 and 79 characters`,
},
{
"all_others aliases",
"paths:\n" +
" all:\n" +
" all_others:\n",
`all_others, all and '~^.*$' are aliases`,
},
{
"all_others aliases",
"paths:\n" +
" all_others:\n" +
" ~^.*$:\n",
`all_others, all and '~^.*$' are aliases`,
},
} {
t.Run(ca.name, func(t *testing.T) {
tmpf, err := writeTempFile([]byte(ca.conf))
@ -314,7 +328,7 @@ func TestSampleConfFile(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "../../mediamtx.yml", confPath1)
tmpf, err := writeTempFile([]byte("paths:\n all:"))
tmpf, err := writeTempFile([]byte("paths:\n all_others:"))
require.NoError(t, err)
defer os.Remove(tmpf)

View File

@ -209,7 +209,7 @@ func (pconf Path) Clone() *Path {
func (pconf *Path) check(conf *Conf, name string) error {
switch {
case name == "all":
case name == "all_others", name == "all":
pconf.Regexp = regexp.MustCompile("^.*$")
case name == "" || name[0] != '~': // normal path

View File

@ -592,7 +592,7 @@ func TestAPIPathsList(t *testing.T) {
func TestAPIPathsGet(t *testing.T) {
p, ok := newInstance("api: yes\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
@ -687,7 +687,7 @@ func TestAPIProtocolList(t *testing.T) {
}
conf += "paths:\n" +
" all:\n"
" all_others:\n"
p, ok := newInstance(conf)
require.Equal(t, true, ok)
@ -973,7 +973,7 @@ func TestAPIProtocolGet(t *testing.T) {
}
conf += "paths:\n" +
" all:\n"
" all_others:\n"
p, ok := newInstance(conf)
require.Equal(t, true, ok)
@ -1262,7 +1262,7 @@ func TestAPIProtocolGetNotFound(t *testing.T) {
}
conf += "paths:\n" +
" all:\n"
" all_others:\n"
p, ok := newInstance(conf)
require.Equal(t, true, ok)
@ -1340,7 +1340,7 @@ func TestAPIProtocolKick(t *testing.T) {
}
conf += "paths:\n" +
" all:\n"
" all_others:\n"
p, ok := newInstance(conf)
require.Equal(t, true, ok)
@ -1475,7 +1475,7 @@ func TestAPIProtocolKickNotFound(t *testing.T) {
}
conf += "paths:\n" +
" all:\n"
" all_others:\n"
p, ok := newInstance(conf)
require.Equal(t, true, ok)

View File

@ -114,7 +114,7 @@ func TestHLSReadNotFound(t *testing.T) {
func TestHLSRead(t *testing.T) {
p, ok := newInstance("hlsAlwaysRemux: yes\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()

View File

@ -34,7 +34,7 @@ func TestMetrics(t *testing.T) {
"serverCert: " + serverCertFpath + "\n" +
"serverKey: " + serverKeyFpath + "\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()

View File

@ -15,7 +15,7 @@ func TestPathAutoDeletion(t *testing.T) {
for _, ca := range []string{"describe", "setup"} {
t.Run(ca, func(t *testing.T) {
p, ok := newInstance("paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()

View File

@ -374,7 +374,7 @@ func TestPathRunOnRead(t *testing.T) {
func TestPathMaxReaders(t *testing.T) {
p, ok := newInstance("paths:\n" +
" all:\n" +
" all_others:\n" +
" maxReaders: 1\n")
require.Equal(t, true, ok)
defer p.Close()
@ -420,7 +420,7 @@ func TestPathRecord(t *testing.T) {
"record: yes\n" +
"recordPath: " + filepath.Join(dir, "%path/%Y-%m-%d_%H-%M-%S-%f") + "\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" record: yes\n")
require.Equal(t, true, ok)
defer p.Close()
@ -455,13 +455,13 @@ func TestPathRecord(t *testing.T) {
hc := &http.Client{Transport: &http.Transport{}}
httpRequest(t, hc, http.MethodPatch, "http://localhost:9997/v3/config/paths/patch/all", map[string]interface{}{
httpRequest(t, hc, http.MethodPatch, "http://localhost:9997/v3/config/paths/patch/all_others", map[string]interface{}{
"record": false,
}, nil)
time.Sleep(500 * time.Millisecond)
httpRequest(t, hc, http.MethodPatch, "http://localhost:9997/v3/config/paths/patch/all", map[string]interface{}{
httpRequest(t, hc, http.MethodPatch, "http://localhost:9997/v3/config/paths/patch/all_others", map[string]interface{}{
"record": true,
}, nil)

View File

@ -56,11 +56,11 @@ func TestRTMPServer(t *testing.T) {
switch auth {
case "none":
conf += "paths:\n" +
" all:\n"
" all_others:\n"
case "internal":
conf += "paths:\n" +
" all:\n" +
" all_others:\n" +
" publishUser: testpublisher\n" +
" publishPass: testpass\n" +
" publishIPs: [127.0.0.0/16]\n" +
@ -71,7 +71,7 @@ func TestRTMPServer(t *testing.T) {
case "external":
conf += "externalAuthenticationURL: http://localhost:9120/auth\n" +
"paths:\n" +
" all:\n"
" all_others:\n"
}
p, ok := newInstance(conf)
@ -193,7 +193,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" publishUser: testuser2\n" +
" publishPass: testpass\n")
require.Equal(t, true, ok)
@ -244,7 +244,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
t.Run("publish_external", func(t *testing.T) {
p, ok := newInstance("externalAuthenticationURL: http://localhost:9120/auth\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
@ -298,7 +298,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" readUser: testuser2\n" +
" readPass: testpass\n")
require.Equal(t, true, ok)

View File

@ -22,14 +22,14 @@ func TestRTSPServer(t *testing.T) {
switch auth {
case "none":
conf = "paths:\n" +
" all:\n"
" all_others:\n"
case "internal":
conf = "rtmp: no\n" +
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" publishUser: testpublisher\n" +
" publishPass: testpass\n" +
" publishIPs: [127.0.0.0/16]\n" +
@ -40,7 +40,7 @@ func TestRTSPServer(t *testing.T) {
case "external":
conf = "externalAuthenticationURL: http://localhost:9120/auth\n" +
"paths:\n" +
" all:\n"
" all_others:\n"
}
p, ok := newInstance(conf)
@ -95,7 +95,7 @@ func TestRTSPServerAuthHashed(t *testing.T) {
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" publishUser: sha256:rl3rgi4NcZkpAEcacZnQ2VuOfJ0FxAqCRaKB/SwdZoQ=\n" +
" publishPass: sha256:E9JJ8stBJ7QM+nV4ZoUCeHk/gU3tPFh/5YieiJp6n2w=\n")
require.Equal(t, true, ok)
@ -139,7 +139,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" publishUser: testuser\n" +
" publishPass: testpass\n")
require.Equal(t, true, ok)
@ -183,7 +183,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" readUser: testuser\n" +
" readPass: testpass\n")
require.Equal(t, true, ok)
@ -208,7 +208,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
"hls: no\n" +
"webrtc: no\n" +
"paths:\n" +
" all:\n" +
" all_others:\n" +
" publishIPs: [128.0.0.1/32]\n")
require.Equal(t, true, ok)
defer p.Close()
@ -227,7 +227,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
t.Run("external", func(t *testing.T) {
p, ok := newInstance("externalAuthenticationURL: http://localhost:9120/auth\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
@ -254,7 +254,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) {
t.Run(ca, func(t *testing.T) {
conf := "rtmp: no\n" +
"paths:\n" +
" all:\n"
" all_others:\n"
if ca == "disabled" {
conf += " overridePublisher: no\n"

View File

@ -18,7 +18,7 @@ func TestSRTServer(t *testing.T) {
} {
t.Run(ca, func(t *testing.T) {
conf := "paths:\n" +
" all:\n"
" all_others:\n"
switch ca {
case "publish passphrase":

View File

@ -170,18 +170,18 @@ func TestWebRTCRead(t *testing.T) {
switch auth {
case "none":
conf = "paths:\n" +
" all:\n"
" all_others:\n"
case "internal":
conf = "paths:\n" +
" all:\n" +
" all_others:\n" +
" readUser: myuser\n" +
" readPass: mypass\n"
case "external":
conf = "externalAuthenticationURL: http://localhost:9120/auth\n" +
"paths:\n" +
" all:\n"
" all_others:\n"
}
p, ok := newInstance(conf)
@ -278,7 +278,7 @@ func TestWebRTCRead(t *testing.T) {
func TestWebRTCReadNotFound(t *testing.T) {
p, ok := newInstance("paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
@ -323,18 +323,18 @@ func TestWebRTCPublish(t *testing.T) {
switch auth {
case "none":
conf = "paths:\n" +
" all:\n"
" all_others:\n"
case "internal":
conf = "paths:\n" +
" all:\n" +
" all_others:\n" +
" publishUser: myuser\n" +
" publishPass: mypass\n"
case "external":
conf = "externalAuthenticationURL: http://localhost:9120/auth\n" +
"paths:\n" +
" all:\n"
" all_others:\n"
}
p, ok := newInstance(conf)

View File

@ -13,7 +13,7 @@ import (
func TestHLSServerRead(t *testing.T) {
p, ok := newInstance("paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
@ -48,7 +48,7 @@ func TestHLSServerAuth(t *testing.T) {
} {
t.Run(result, func(t *testing.T) {
conf := "paths:\n" +
" all:\n" +
" all_others:\n" +
" readUser: testreader\n" +
" readPass: testpass\n" +
" readIPs: [127.0.0.0/16]\n"

View File

@ -47,7 +47,7 @@ func TestRTSPServerPublishRead(t *testing.T) {
"webrtc: no\n" +
"readTimeout: 20s\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
} else {
@ -71,7 +71,7 @@ func TestRTSPServerPublishRead(t *testing.T) {
"serverCert: " + serverCertFpath + "\n" +
"serverKey: " + serverKeyFpath + "\n" +
"paths:\n" +
" all:\n")
" all_others:\n")
require.Equal(t, true, ok)
defer p.Close()
}

View File

@ -531,16 +531,15 @@ pathDefaults:
# Path settings
# Settings in "paths" are applied to specific paths, and the map key
# is the name of the path.
# is the name of the path. Any setting in "pathDefaults" can be overridden.
# It's possible to use regular expressions by using a tilde as prefix,
# for example "~^(test1|test2)$" will match both "test1" and "test2",
# for example "~^prefix" will match all paths that start with "prefix".
# Settings under path "all" are applied to all paths that do not match
# another entry.
paths:
all:
# any setting in "pathDefaults" can be overridden here.
# for instance:
# example:
# my_camera:
# source: rtsp://my_camera
# Settings under path "all_others" are applied to all paths that
# do not match another entry.
all_others: