Browse Source

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

pull/2607/head v1.2.1
Alessandro Ros 2 years ago committed by GitHub
parent
commit
4b4d57f18e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      apidocs/openapi.yaml
  2. 1
      internal/conf/conf_test.go
  3. 5
      internal/conf/path.go
  4. 3
      internal/core/api_test.go

3
apidocs/openapi.yaml

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

1
internal/conf/conf_test.go

@ -48,6 +48,7 @@ func TestConfFromFile(t *testing.T) { @@ -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),

5
internal/conf/path.go

@ -49,7 +49,8 @@ func srtCheckPassphrase(passphrase string) error { @@ -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 { @@ -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("^.*$")

3
internal/core/api_test.go

@ -255,8 +255,10 @@ func TestAPIConfigPathsList(t *testing.T) { @@ -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) { @@ -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"])
}

Loading…
Cancel
Save