rob05c commented on a change in pull request #3875: Add TO Go ATS CDN configs
URL: https://github.com/apache/trafficcontrol/pull/3875#discussion_r319182815
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/ats/atscdn/atscdn.go
 ##########
 @@ -0,0 +1,152 @@
+package atscdn
+
+/*
+ * 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 (
+       "database/sql"
+       "errors"
+       "net/http"
+       "strconv"
+       "strings"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/ats"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/config"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+)
+
+// GenericProfileConfig generates a generic profile config text, from the 
profile's parameters with the given config file name.
+// This does not include a header comment, because a generic config may not 
use a number sign as a comment.
+// If you need a header comment, it can be added manually via 
ats.HeaderComment, or automatically with WithProfileDataHdr.
+func GenericProfileConfig(tx *sql.Tx, profile ats.ProfileData, fileName 
string, separator string) (string, error) {
+       profileParamData, err := ats.GetProfileParamData(tx, profile.ID, 
fileName)
+       if err != nil {
+               return "", errors.New("getting profile param data: " + 
err.Error())
+       }
+       text := ""
+       for name, val := range profileParamData {
+               name = trimParamUnderscoreNumSuffix(name)
+               text += name + separator + val + "\n"
+       }
+       return text, nil
+}
+
+// trimParamUnderscoreNumSuffix removes any trailing "__[0-9]+" and returns 
the trimmed string.
+func trimParamUnderscoreNumSuffix(paramName string) string {
+       underscorePos := strings.LastIndex(paramName, `__`)
+       if underscorePos == -1 {
+               return paramName
+       }
+       if _, err := strconv.ParseFloat(paramName[underscorePos+2:], 64); err 
!= nil {
 
 Review comment:
   It is moved in https://github.com/apache/trafficcontrol/pull/3762
   Moving it here as well will make painful merge conflicts.

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