ocket8888 commented on a change in pull request #5247:
URL: https://github.com/apache/trafficcontrol/pull/5247#discussion_r525524113



##########
File path: lib/go-atscfg/meta.go
##########
@@ -20,102 +20,148 @@ package atscfg
  */
 
 import (
-       "encoding/json"
        "errors"
        "path/filepath"
        "strings"
 
-       "github.com/apache/trafficcontrol/lib/go-log"
        "github.com/apache/trafficcontrol/lib/go-tc"
 )
 
-type ConfigProfileParams struct {
-       FileNameOnDisk string
-       Location       string
-       URL            string
+type CfgMeta struct {
+       Name string
+       Path string
 }
 
-// APIVersion is the Traffic Ops API version for config fiels.
-// This is used to generate the meta config, which has API paths.
-// Note the version in the meta config is not used by the atstccfg generator, 
which isn't actually an API.
-// TODO change the config system to not use old API paths, and remove this.
-const APIVersion = "2.0"
+// MakeMetaObj returns the list of config files, any warnings, and any errors.
+func MakeConfigFilesList(
+       configDir string,
+       server *Server,
+       serverParams []tc.Parameter,
+       deliveryServices []DeliveryService,
+       deliveryServiceServers []tc.DeliveryServiceServer,
+       globalParams []tc.Parameter,
+       cacheGroupArr []tc.CacheGroupNullable,
+       topologies []tc.Topology,
+) ([]CfgMeta, []string, error) {
+       warnings := []string{}
 
-// requiredFiles is a constant (because Go doesn't allow const slices).
-// Note these are not exhaustive. This is only used to error if these are 
missing.
-// The presence of these is no guarantee the location Parameters are complete 
and correct.
-func requiredFiles() []string {
-       return []string{
-               "cache.config",
-               "hosting.config",
-               "ip_allow.config",
-               "parent.config",
-               "plugin.config",
-               "records.config",
-               "remap.config",
-               "storage.config",
-               "volume.config",
+       if server.Cachegroup == nil {
+               return nil, warnings, errors.New("this server missing 
Cachegroup")
+       } else if server.CachegroupID == nil {
+               return nil, warnings, errors.New("this server missing 
CachegroupID")
+       } else if server.ProfileID == nil {
+               return nil, warnings, errors.New("server missing ProfileID")
+       } else if server.TCPPort == nil {
+               return nil, warnings, errors.New("server missing TCPPort")
+       } else if server.HostName == nil {
+               return nil, warnings, errors.New("server missing HostName")
+       } else if server.CDNID == nil {
+               return nil, warnings, errors.New("server missing CDNID")
+       } else if server.CDNName == nil {
+               return nil, warnings, errors.New("server missing CDNName")
+       } else if server.ID == nil {
+               return nil, warnings, errors.New("server missing ID")
+       } else if server.Profile == nil {
+               return nil, warnings, errors.New("server missing Profile")
        }
-}
 
-func MakeMetaConfig(
-       server *tc.ServerNullable,
-       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
-       dses map[tc.DeliveryServiceName]tc.DeliveryServiceNullableV30,
-       cacheGroupArr []tc.CacheGroupNullable,
-       topologies []tc.Topology,
-) string {
-       configDir := "" // this should only be used for Traffic Ops, which 
doesn't have a local ATS install config directory (and thus will fail if any 
location Parameters are missing or relative).
-       return MetaObjToMetaConfig(MakeMetaObj(server, tmURL, 
tmReverseProxyURL, locationParams, uriSignedDSes, scopeParams, dses, 
cacheGroupArr, topologies, configDir))
-}
+       tmURL, tmReverseProxyURL := getTOURLAndReverseProxy(globalParams)
+       if tmURL == "" {
+               warnings = append(warnings, "global tm.url parameter missing or 
empty! Setting empty in meta config!")
+       }
 
-func MetaObjToMetaConfig(atsData tc.ATSConfigMetaData, err error) string {
-       if err != nil {
-               return "error creating meta config: " + err.Error()
+       dses, dsWarns := filterConfigFileDSes(server, deliveryServices, 
deliveryServiceServers)
+       warnings = append(warnings, dsWarns...)
+
+       locationParams := getLocationParams(serverParams)
+
+       uriSignedDSes, signDSWarns := getURISignedDSes(dses)
+       warnings = append(warnings, signDSWarns...)
+
+       configFiles := []CfgMeta{}
+
+       if locationParams["remap.config"].Path != "" {
+               configLocation := locationParams["remap.config"].Path
+               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.Name = cfgName
+                               p.Path = configLocation
+                               locationParams[cfgName] = p
+                       }
+               }
        }
-       bts, err := json.Marshal(atsData)
-       if err != nil {
-               // should never happen
-               log.Errorln("marshalling meta config: " + err.Error())
-               bts = []byte("error encoding to json, see log for details")
+
+locationParamsFor:

Review comment:
       oh, I see.




----------------------------------------------------------------
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:
[email protected]


Reply via email to