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/02 00:16:29 UTC

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

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

 ##########
 File path: lib/go-atscfg/meta.go
 ##########
 @@ -0,0 +1,195 @@
+package atscfg
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"strings"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+	"github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+type ConfigProfileParams struct {
+	FileNameOnDisk string
+	Location       string
+	URL            string
+	APIURI         string
+}
+
+func MakeMetaConfig(
+	serverHostName tc.CacheName,
+	server *ServerInfo,
+	tmURL string, // global tm.url Parameter
+	tmReverseProxyURL string, // global tm.rev_proxy.url Parameter
+	locationParams map[string]ConfigProfileParams, // map[configFile]params; 'location' and 'URL' Parameters on serverHostName's Profile
+	uriSignedDSes []tc.DeliveryServiceName,
+	scopeParams map[string]string, // map[configFileName]scopeParam
+) string {
+	if tmURL == "" {
+		log.Errorln("ats.GetConfigMetadata: global tm.url parameter missing or empty! Setting empty in meta config!")
+	}
+
+	atsData := tc.ATSConfigMetaData{
+		Info: tc.ATSConfigMetaDataInfo{
+			ProfileID:         int(server.ProfileID),
+			TOReverseProxyURL: tmReverseProxyURL,
+			TOURL:             tmURL,
+			ServerIPv4:        server.IP,
+			ServerPort:        server.Port,
+			ServerName:        server.HostName,
+			CDNID:             server.CDNID,
+			CDNName:           string(server.CDN),
+			ServerID:          server.ID,
+			ProfileName:       server.ProfileName,
+		},
+		ConfigFiles: []tc.ATSConfigMetaDataConfigFile{},
+	}
+
+	if locationParams["remap.config"].Location != "" {
+		configLocation := locationParams["remap.config"].Location
+		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
+				locationParams[cfgName] = p
+			}
+		}
+	}
+
+	for cfgFile, cfgParams := range locationParams {
+		atsCfg := tc.ATSConfigMetaDataConfigFile{
+			FileNameOnDisk: cfgParams.FileNameOnDisk,
+			Location:       cfgParams.Location,
+		}
+
+		scope := getServerScope(cfgFile, server.Type, scopeParams)
+
+		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
 
 Review comment:
   The config generator doesn't actually care what this number is. Unfortunately, the only place it's really defined is in the client, and we don't want this library to depend on that.
   I changed it to a const.

----------------------------------------------------------------
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