alficles commented on a change in pull request #3688: Add TO Go remap.config
URL: https://github.com/apache/trafficcontrol/pull/3688#discussion_r321573672
 
 

 ##########
 File path: lib/go-atscfg/remapdotconfig.go
 ##########
 @@ -0,0 +1,369 @@
+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 (
+       "errors"
+       "sort"
+       "strconv"
+       "strings"
+
+       "github.com/apache/trafficcontrol/lib/go-log"
+       "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+type RemapConfigDSData struct {
+       ID                       int
+       Type                     tc.DSType
+       OriginFQDN               *string
+       MidHeaderRewrite         *string
+       CacheURL                 *string
+       RangeRequestHandling     *int
+       CacheKeyConfigParams     map[string]string
+       RemapText                *string
+       EdgeHeaderRewrite        *string
+       SigningAlgorithm         *string
+       Name                     string
+       QStringIgnore            *int
+       RegexRemap               *string
+       FQPacingRate             *int
+       DSCP                     int
+       RoutingName              *string
+       MultiSiteOrigin          *string
+       Pattern                  *string
+       RegexType                *string
+       Domain                   *string
+       RegexSetNumber           *string
+       OriginShield             *string
+       ProfileID                *int
+       Protocol                 *int
+       AnonymousBlockingEnabled *bool
+       Active                   bool
+}
+
+func MakeRemapDotConfig(
+       serverName tc.CacheName,
+       toToolName string, // tm.toolname global parameter (TODO: cache itself?)
+       toURL string, // tm.url global parameter (TODO: cache itself?)
+       atsMajorVersion int,
+       cacheURLConfigParams map[string]string, // map[name]value for this 
server's profile and config file 'cacheurl.config'
+       dsProfilesCacheKeyConfigParams map[int]map[string]string, // 
map[profileID][paramName]paramVal for this server's profile, config file 
'cachekey.config'
+       serverPackageParamData map[string]string, // map[paramName]paramVal for 
this server, config file 'package'
+       serverInfo *ServerInfo, // ServerInfo for this server
+       remapDSData []RemapConfigDSData,
+) string {
+       hdr := GenericHeaderComment(string(serverName), toToolName, toURL)
+       text := ""
+       if tc.CacheTypeFromString(serverInfo.Type) == tc.CacheTypeMid {
+               text = GetServerConfigRemapDotConfigForMid(atsMajorVersion, 
dsProfilesCacheKeyConfigParams, serverInfo, remapDSData, hdr)
+       } else {
+               text = 
GetServerConfigRemapDotConfigForEdge(cacheURLConfigParams, 
dsProfilesCacheKeyConfigParams, serverPackageParamData, serverInfo, 
remapDSData, atsMajorVersion, hdr)
+       }
+       return text
+}
+
+func GetServerConfigRemapDotConfigForMid(
+       atsMajorVersion int,
+       profilesCacheKeyConfigParams map[int]map[string]string,
+       server *ServerInfo,
+       dses []RemapConfigDSData,
+       header string,
+) string {
+       midRemaps := map[string]string{}
+       for _, ds := range dses {
+               if ds.Type.IsLive() && !ds.Type.IsNational() {
+                       continue // Live local delivery services skip mids
+               }
+
+               if ds.OriginFQDN == nil || *ds.OriginFQDN == "" {
+                       log.Warnf("GetServerConfigRemapDotConfigForMid ds '" + 
ds.Name + "' has no origin fqdn, skipping!") // TODO confirm - Perl uses 
without checking!
+                       continue
+               }
+
+               if midRemaps[*ds.OriginFQDN] != "" {
+                       continue // skip remap rules from extra HOST_REGEXP 
entries
+               }
+
+               midRemap := ""
+               if ds.MidHeaderRewrite != nil && *ds.MidHeaderRewrite != "" {
+                       midRemap += ` @plugin=header_rewrite.so @pparam=` + 
MidHeaderRewriteConfigFileName(ds.Name)
+               }
+               if ds.QStringIgnore != nil && *ds.QStringIgnore == 
tc.QueryStringIgnoreIgnoreInCacheKeyAndPassUp {
+                       midRemap += GetQStringIgnoreRemap(atsMajorVersion)
+               }
+               if ds.CacheURL != nil && *ds.CacheURL != "" {
+                       midRemap += ` @plugin=cacheurl.so @pparam=` + 
CacheURLConfigFileName(ds.Name)
+               }
 
 Review comment:
   Right now, multiple uses of `cacheurl` do not do what one might expect. It's 
probably worth actually enhancing this to make these duplications findable. We 
should probably fix `cacheurl` as well, but it's basically never right to have 
two of these on a line at the same time.
   
   It looks like we handle it for the edge case, but it is just as problematic 
at the mid.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to