Skip to content

Commit

Permalink
api: add path name to config/paths/list and config/paths/get (#2535) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Oct 28, 2023
1 parent 6e7a6fe commit 4b4d57f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ components:
PathConf:
type: object
properties:
name:
type: string

# General
source:
type: string
Expand Down
1 change: 1 addition & 0 deletions internal/conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion internal/conf/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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("^.*$")
Expand Down
3 changes: 3 additions & 0 deletions internal/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
Expand All @@ -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"])
}

Expand Down

0 comments on commit 4b4d57f

Please sign in to comment.