1
0
Fork 0
forked from External/mediamtx

api: add path name to config/paths/list and config/paths/get (#2535) (#2596)

This commit is contained in:
Alessandro Ros 2023-10-28 15:06:06 +02:00 committed by GitHub
parent 6e7a6fe71a
commit 4b4d57f18e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 1 deletions

View file

@ -204,6 +204,9 @@ components:
PathConf:
type: object
properties:
name:
type: string
# General
source:
type: string

View file

@ -48,6 +48,7 @@ func TestConfFromFile(t *testing.T) {
pa, ok := conf.Paths["cam1"]
require.Equal(t, true, ok)
require.Equal(t, &Path{
Name: "cam1",
Source: "publisher",
SourceOnDemandStartTimeout: 10 * StringDuration(time.Second),
SourceOnDemandCloseAfter: 10 * StringDuration(time.Second),

View file

@ -49,7 +49,8 @@ func srtCheckPassphrase(passphrase string) error {
// Path is a path configuration.
type Path struct {
Regexp *regexp.Regexp `json:"-"` // filled by Check()
Regexp *regexp.Regexp `json:"-"` // filled by Check()
Name string `json:"name"` // filled by Check()
// General
Source string `json:"source"`
@ -209,6 +210,8 @@ func (pconf Path) Clone() *Path {
}
func (pconf *Path) check(conf *Conf, name string) error {
pconf.Name = name
switch {
case name == "all_others", name == "all":
pconf.Regexp = regexp.MustCompile("^.*$")

View file

@ -255,8 +255,10 @@ func TestAPIConfigPathsList(t *testing.T) {
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/config/paths/list", nil, &out)
require.Equal(t, 2, out.ItemCount)
require.Equal(t, 1, out.PageCount)
require.Equal(t, "path1", out.Items[0]["name"])
require.Equal(t, "myuser1", out.Items[0]["readUser"])
require.Equal(t, "mypass1", out.Items[0]["readPass"])
require.Equal(t, "path2", out.Items[1]["name"])
require.Equal(t, "myuser2", out.Items[1]["readUser"])
require.Equal(t, "mypass2", out.Items[1]["readPass"])
}
@ -274,6 +276,7 @@ func TestAPIConfigPathsGet(t *testing.T) {
var out map[string]interface{}
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/config/paths/get/my/path", nil, &out)
require.Equal(t, "my/path", out["name"])
require.Equal(t, "myuser", out["readUser"])
}