api: allow to edit properties of path config "all" (#2067) (#2075)

This commit is contained in:
Alessandro Ros 2023-07-19 13:33:05 +02:00 committed by GitHub
parent 048280f4e2
commit 37586b2300
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 67 deletions

View file

@ -77,6 +77,15 @@ func loadFromFile(fpath string, conf *Conf) (bool, error) {
return true, nil
}
func contains(list []headers.AuthMethod, item headers.AuthMethod) bool {
for _, i := range list {
if i == item {
return true
}
}
return false
}
// Conf is a configuration.
type Conf struct {
// general
@ -197,15 +206,6 @@ func (conf Conf) Clone() *Conf {
return &dest
}
func contains(list []headers.AuthMethod, item headers.AuthMethod) bool {
for _, i := range list {
if i == item {
return true
}
}
return false
}
// Check checks the configuration for errors.
func (conf *Conf) Check() error {
// general
@ -266,12 +266,6 @@ func (conf *Conf) Check() error {
conf.Paths = make(map[string]*PathConf)
}
// "all" is an alias for "~^.*$"
if _, ok := conf.Paths["all"]; ok {
conf.Paths["~^.*$"] = conf.Paths["all"]
delete(conf.Paths, "all")
}
for _, name := range getSortedKeys(conf.Paths) {
pconf := conf.Paths[name]
if pconf == nil {

View file

@ -119,15 +119,17 @@ type PathConf struct {
}
func (pconf *PathConf) check(conf *Conf, name string) error {
// normal path
if name == "" || name[0] != '~' {
switch {
case name == "all":
pconf.Regexp = regexp.MustCompile("^.*$")
case name == "" || name[0] != '~': // normal path
err := IsValidPathName(name)
if err != nil {
return fmt.Errorf("invalid path name '%s': %s", name, err)
}
// regular expression path
} else {
default: // regular expression-based path
pathRegexp, err := regexp.Compile(name[1:])
if err != nil {
return fmt.Errorf("invalid regular expression: %s", name[1:])