This is an automated email from the ASF dual-hosted git repository.

shamrick pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new a1c3a2e5a2 Change t3c -M option to take a comma separated list (#7580)
a1c3a2e5a2 is described below

commit a1c3a2e5a2e58137e92c4a0a7b5bdca4bd463a72
Author: Evan Zelkowitz <[email protected]>
AuthorDate: Wed Jun 28 10:29:21 2023 -0600

    Change t3c -M option to take a comma separated list (#7580)
    
    * Add maxmind anonymous location, refactored checkmaxmind to check both 
fields
    
    * Added to docs
    
    * Removed anonymous DB option. Changed the -M to take a comma separated 
list of URLs of databases. So now it works through each URL in turn doing the 
304 check and unpack
    
    * Added printing of urls that failed
---
 cache-config/t3c-apply/README.md    |  3 ++-
 cache-config/t3c-apply/t3c-apply.go | 22 +++++++++++++++-------
 cache-config/t3c-apply/util/util.go | 20 ++++++++++----------
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/cache-config/t3c-apply/README.md b/cache-config/t3c-apply/README.md
index fbb7297849..65ec94fc3d 100644
--- a/cache-config/t3c-apply/README.md
+++ b/cache-config/t3c-apply/README.md
@@ -161,7 +161,8 @@ Typical usage is to install t3c on the cache machine, and 
then run it periodical
 -M, -\-maxmind-location=value
 
     URL of a maxmind gzipped database file, to be installed into
-    the trafficserver etc directory.
+    the trafficserver etc directory. Can also be a comma separated
+    list of URLs to get and un-gzip.
 
 -m, -\-run-mode=value
 
diff --git a/cache-config/t3c-apply/t3c-apply.go 
b/cache-config/t3c-apply/t3c-apply.go
index f4e7db2dba..1382da3529 100644
--- a/cache-config/t3c-apply/t3c-apply.go
+++ b/cache-config/t3c-apply/t3c-apply.go
@@ -26,6 +26,7 @@ import (
        "io/ioutil"
        "os"
        "path/filepath"
+       "strings"
        "time"
 
        "github.com/apache/trafficcontrol/cache-config/t3c-apply/config"
@@ -397,20 +398,27 @@ func CheckMaxmindUpdate(cfg config.Cfg) bool {
        // Check if we have a URL for a maxmind db
        // If we do, test if the file exists, do IMS based on disk time
        // and download and unpack as needed
-       result := false
+       retresult := false
        if cfg.MaxMindLocation != "" {
                // Check if the maxmind db needs to be updated before reload
-               result = util.UpdateMaxmind(cfg)
-               if result {
-                       log.Infoln("maxmind database was updated from " + 
cfg.MaxMindLocation)
-               } else {
-                       log.Infoln("maxmind database not updated. Either not 
needed or curl/gunzip failure")
+               MaxMindList := strings.Split(cfg.MaxMindLocation, ",")
+               for _, v := range MaxMindList {
+                       result := util.UpdateMaxmind(v, cfg.TsConfigDir, 
cfg.ReportOnly)
+                       if result {
+                               log.Infoln("maxmind database was updated from " 
+ v)
+                       } else {
+                               log.Infoln("maxmind database not updated. 
Either not needed or curl/gunzip failure: " + v)
+                       }
+                       if result {
+                               // If we've seen any database updates then 
return true to update ATS
+                               retresult = true
+                       }
                }
        } else {
                log.Infoln(("maxmindlocation is empty, not checking for DB 
update"))
        }
 
-       return result
+       return retresult
 }
 
 const MetaDataFileName = `t3c-apply-metadata.json`
diff --git a/cache-config/t3c-apply/util/util.go 
b/cache-config/t3c-apply/util/util.go
index 49d77d0748..bb63be4683 100644
--- a/cache-config/t3c-apply/util/util.go
+++ b/cache-config/t3c-apply/util/util.go
@@ -439,20 +439,20 @@ func Touch(fn string) error {
        return nil
 }
 
-func UpdateMaxmind(cfg config.Cfg) bool {
+func UpdateMaxmind(maxmindlocation string, tsconfigdir string, reportonly 
bool) bool {
 
-       if cfg.MaxMindLocation == "" {
+       if maxmindlocation == "" {
                return false
        }
 
        // Dont update for report mode
-       if cfg.ReportOnly {
-               log.Infof("Reporting: maxmind location '%v', reporting only and 
not modifying file\n", cfg.MaxMindLocation)
+       if reportonly {
+               log.Infof("Reporting: maxmind location '%v', reporting only and 
not modifying file\n", maxmindlocation)
                return false
        }
 
        // Split url, get filename
-       url, err := url.Parse(cfg.MaxMindLocation)
+       url, err := url.Parse(maxmindlocation)
        if err != nil {
                log.Errorf("error parsing maxmind url: %v", err)
                return false
@@ -466,7 +466,7 @@ func UpdateMaxmind(cfg config.Cfg) bool {
        }
 
        // Check if filename exists in ats etc
-       filePath := filepath.Join(cfg.TsConfigDir, "/", fileName)
+       filePath := filepath.Join(tsconfigdir, "/", fileName)
        stdOut, _, code := t3cutil.Do(`date`,
                "+%a, %d %b %Y %T %Z",
                "-u",
@@ -476,7 +476,7 @@ func UpdateMaxmind(cfg config.Cfg) bool {
        // Do a HEAD request to check for 200 or 304 depending on if we
        // have an existing file or not.
        client := &http.Client{}
-       req, err := http.NewRequest("HEAD", cfg.MaxMindLocation, nil)
+       req, err := http.NewRequest("HEAD", maxmindlocation, nil)
        if err != nil {
                log.Errorf("error creating head request %v", err)
                return false
@@ -492,7 +492,7 @@ func UpdateMaxmind(cfg config.Cfg) bool {
        }
 
        if resp.StatusCode != 304 && resp.StatusCode != 200 {
-               log.Errorf("error requesting %s, code: %d", 
cfg.MaxMindLocation, resp.StatusCode)
+               log.Errorf("error requesting %s, code: %d", maxmindlocation, 
resp.StatusCode)
                return false
        }
 
@@ -519,7 +519,7 @@ func UpdateMaxmind(cfg config.Cfg) bool {
        _, _, code = t3cutil.Do(`curl`,
                "-so",
                filePath,
-               cfg.MaxMindLocation)
+               maxmindlocation)
 
        if code != 0 {
                log.Errorf("Error downloading maxmind database")
@@ -539,6 +539,6 @@ func UpdateMaxmind(cfg config.Cfg) bool {
                return false
        }
 
-       log.Infof("Maxmind DB at %s successfully updated from %s", filePath, 
cfg.MaxMindLocation)
+       log.Infof("Maxmind DB at %s successfully updated from %s", filePath, 
maxmindlocation)
        return true
 }

Reply via email to