in lib/validator/policy_builder.go [83:134]
func expandSources(visaType string, src string, sources map[string]*pb.TrustedSource) (map[string]bool, error) {
from, err := expandField(src)
if err != nil {
return nil, err
}
out := make(map[string]bool)
for _, f := range from {
if strutil.IsURL(f) {
out[f] = true
continue
}
source, ok := sources[f]
if !ok {
return nil, fmt.Errorf("from %q name is not a valid source name", f)
}
for _, src := range source.Sources {
out[src] = true
}
}
if len(from) == 0 {
for sname, source := range sources {
incl := false
if len(source.VisaTypes) == 0 {
incl = true
} else {
for vidx, v := range source.VisaTypes {
if len(v) > 1 && v[0] == '^' {
// Regexp
re, err := regexp.Compile(v)
if err != nil {
return nil, fmt.Errorf("source %q visa %d invalid regular expression %q: %v", sname, vidx, v, err)
}
if re.Match([]byte(visaType)) {
incl = true
break
}
} else if v == visaType {
incl = true
break
}
}
}
if !incl {
continue
}
for _, src := range source.Sources {
out[src] = true
}
}
}
return out, nil
}