Skip to content

Commit

Permalink
rename 'all' path configuration into 'all_others' (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Oct 9, 2023
1 parent 8a633d2 commit 6c727b4
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 52 deletions.
2 changes: 1 addition & 1 deletion bench/proxy/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
2 changes: 1 addition & 1 deletion bench/publish/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
2 changes: 1 addition & 1 deletion bench/read/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
10 changes: 10 additions & 0 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 15 additions & 1 deletion internal/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/conf/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions internal/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/core/hls_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion internal/core/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion internal/core/path_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions internal/core/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions internal/core/rtmp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions internal/core/rtsp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/core/srt_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
14 changes: 7 additions & 7 deletions internal/core/webrtc_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 6c727b4

Please sign in to comment.