in src/go/configgenerator/filtergen/path_rewrite.go [138:178]
func GenTranslationInfoFromOPConfig(serviceConfig *confpb.Service, opts options.ConfigGeneratorOptions) (map[string]TranslationInfo, error) {
if opts.EnableBackendAddressOverride {
glog.Infof("Skipping create path rewrite translation info because backend address override is enabled.")
return nil, nil
}
infoBySelector := make(map[string]TranslationInfo)
for _, rule := range serviceConfig.GetBackend().GetRules() {
if util.ShouldSkipOPDiscoveryAPI(rule.GetSelector(), opts.AllowDiscoveryAPIs) {
glog.Warningf("Skip backend rule %q because discovery API is not supported.", rule.GetSelector())
continue
}
if rule.GetAddress() == "" {
glog.Infof("Skip backend rule %q because it does not have dynamic routing address.", rule.GetSelector())
continue
}
_, _, _, path, err := util.ParseURI(rule.GetAddress())
if err != nil {
return nil, fmt.Errorf("error parsing remote backend rule's address for operation %q: %v", rule.GetAddress(), err)
}
// For CONSTANT_ADDRESS, an empty uri will generate an empty path header.
// It is an invalid Http header if path is empty.
if path == "" && rule.GetPathTranslation() == confpb.BackendRule_CONSTANT_ADDRESS {
path = "/"
}
if path == "" || rule.GetPathTranslation() == confpb.BackendRule_PATH_TRANSLATION_UNSPECIFIED {
continue
}
infoBySelector[rule.GetSelector()] = TranslationInfo{
TranslationType: rule.GetPathTranslation(),
Path: path,
}
}
return infoBySelector, nil
}