You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/11/01 23:58:15 UTC

[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #4063: Add atstccfg meta config

rawlinp commented on a change in pull request #4063: Add atstccfg meta config
URL: https://github.com/apache/trafficcontrol/pull/4063#discussion_r341785740
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/ats/atsserver/meta.go
 ##########
 @@ -85,136 +70,14 @@ func GetConfigMetaData(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	if locationParams["remap.config"].Location != "" {
-		configLocation := locationParams["remap.config"].Location
-		uriSignedDSes, err := ats.GetServerURISignedDSes(inf.Tx.Tx, server.HostName, server.Port)
-		if err != nil {
-			api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("GetConfigMetaData getting server uri-signed dses: "+err.Error()))
-			return
-		}
-		for _, ds := range uriSignedDSes {
-			cfgName := "uri_signing_" + string(ds) + ".config"
-			// If there's already a parameter for it, don't clobber it. The user may wish to override the location.
-			if _, ok := locationParams[cfgName]; !ok {
-				p := locationParams[cfgName]
-				p.FileNameOnDisk = cfgName
-				p.Location = configLocation
-			}
-		}
-	}
-
-	for cfgFile, cfgParams := range locationParams {
-		atsCfg := tc.ATSConfigMetaDataConfigFile{
-			FileNameOnDisk: cfgParams.FileNameOnDisk,
-			Location:       cfgParams.Location,
-		}
-
-		scope, err := getServerScope(inf.Tx.Tx, cfgFile, server.Type)
-		if err != nil {
-			api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("GetConfigMetaData getting scope: "+err.Error()))
-			return
-		}
-
-		if cfgParams.URL != "" {
-			scope = tc.ATSConfigMetaDataConfigFileScopeCDNs
-			atsCfg.URL = cfgParams.URL
-		} else {
-			scopeID := ""
-			if scope == tc.ATSConfigMetaDataConfigFileScopeCDNs {
-				scopeID = string(server.CDN)
-			} else if scope == tc.ATSConfigMetaDataConfigFileScopeProfiles {
-				scopeID = server.ProfileName
-			} else { // ATSConfigMetaDataConfigFileScopeServers
-				scopeID = server.HostName
-			}
-			atsCfg.APIURI = "/api/1.2/" + string(scope) + "/" + scopeID + "/configfiles/ats/" + cfgFile
-		}
-
-		atsCfg.Scope = string(scope)
-
-		atsData.ConfigFiles = append(atsData.ConfigFiles, atsCfg)
-	}
-
-	api.WriteRespRaw(w, r, atsData)
-}
-
-func getServerScope(tx *sql.Tx, cfgFile string, serverType string) (tc.ATSConfigMetaDataConfigFileScope, error) {
-	switch {
-	case cfgFile == "cache.config" && tc.CacheTypeFromString(serverType) == tc.CacheTypeMid:
-		return tc.ATSConfigMetaDataConfigFileScopeServers, nil
-	default:
-		return getScope(tx, cfgFile)
-	}
-}
-
-// getScope returns the ATSConfigMetaDataConfigFileScope for the given config file, and potentially the given server. If the config is not a Server scope, i.e. was part of an endpoint which does not include a server name or id, the server may be nil.
-func getScope(tx *sql.Tx, cfgFile string) (tc.ATSConfigMetaDataConfigFileScope, error) {
-	switch {
-	case cfgFile == "ip_allow.config":
-		fallthrough
-	case cfgFile == "parent.config":
-		fallthrough
-	case cfgFile == "hosting.config":
-		fallthrough
-	case cfgFile == "packages":
-		fallthrough
-	case cfgFile == "chkconfig":
-		fallthrough
-	case cfgFile == "remap.config":
-		fallthrough
-	case strings.HasPrefix(cfgFile, "to_ext_") && strings.HasSuffix(cfgFile, ".config"):
-		return tc.ATSConfigMetaDataConfigFileScopeServers, nil
-	case cfgFile == "12M_facts":
-		fallthrough
-	case cfgFile == "50-ats.rules":
-		fallthrough
-	case cfgFile == "astats.config":
-		fallthrough
-	case cfgFile == "cache.config":
-		fallthrough
-	case cfgFile == "drop_qstring.config":
-		fallthrough
-	case cfgFile == "logs_xml.config":
-		fallthrough
-	case cfgFile == "logging.config":
-		fallthrough
-	case cfgFile == "plugin.config":
-		fallthrough
-	case cfgFile == "records.config":
-		fallthrough
-	case cfgFile == "storage.config":
-		fallthrough
-	case cfgFile == "volume.config":
-		fallthrough
-	case cfgFile == "sysctl.conf":
-		fallthrough
-	case strings.HasPrefix(cfgFile, "url_sig_") && strings.HasSuffix(cfgFile, ".config"):
-		fallthrough
-	case strings.HasPrefix(cfgFile, "uri_signing_") && strings.HasSuffix(cfgFile, ".config"):
-		return tc.ATSConfigMetaDataConfigFileScopeProfiles, nil
-
-	case cfgFile == "bg_fetch.config":
-		fallthrough
-	case cfgFile == "regex_revalidate.config":
-		fallthrough
-	case cfgFile == "ssl_multicert.config":
-		fallthrough
-	case strings.HasPrefix(cfgFile, "cacheurl") && strings.HasSuffix(cfgFile, ".config"):
-		fallthrough
-	case strings.HasPrefix(cfgFile, "hdr_rw_") && strings.HasSuffix(cfgFile, ".config"):
-		fallthrough
-	case strings.HasPrefix(cfgFile, "regex_remap_") && strings.HasSuffix(cfgFile, ".config"):
-		fallthrough
-	case strings.HasPrefix(cfgFile, "set_dscp_") && strings.HasSuffix(cfgFile, ".config"):
-		return tc.ATSConfigMetaDataConfigFileScopeCDNs, nil
-	}
-
-	scope, ok, err := ats.GetFirstScopeParameter(tx, cfgFile)
+	uriSignedDSes, err := ats.GetServerURISignedDSes(inf.Tx.Tx, server.HostName, server.Port)
 	if err != nil {
-		return tc.ATSConfigMetaDataConfigFileScopeInvalid, errors.New("getting scope parameter: " + err.Error())
-	}
-	if !ok {
-		scope = string(tc.ATSConfigMetaDataConfigFileScopeServers)
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("GetConfigMetaData getting server uri-signed dses: "+err.Error()))
+		return
 	}
-	return tc.ATSConfigMetaDataConfigFileScope(scope), nil
+
+	txt := atscfg.MakeMetaConfig(serverName, server, tmParams.URL, tmParams.ReverseProxyURL, locationParams, uriSignedDSes, scopeParams)
+	w.Header().Set(tc.ContentType, tc.ApplicationJson)
+	w.Write([]byte(txt))
+	api.WriteRespRaw(w, r, txt)
 
 Review comment:
   I know `atstccfg` isn't using this API, but I'm pretty sure this line should be removed since we're calling `w.Write` just above it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services