elsloo closed pull request #2280: Fix TO CRconfig changelog
URL: https://github.com/apache/incubator-trafficcontrol/pull/2280
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/traffic_ops/traffic_ops_golang/api/change_log.go 
b/traffic_ops/traffic_ops_golang/api/change_log.go
index 17c54a784..f2fb18f5c 100644
--- a/traffic_ops/traffic_ops_golang/api/change_log.go
+++ b/traffic_ops/traffic_ops_golang/api/change_log.go
@@ -20,11 +20,13 @@ package api
  */
 
 import (
+       "database/sql"
        "fmt"
 
        "github.com/apache/incubator-trafficcontrol/lib/go-log"
        "github.com/apache/incubator-trafficcontrol/lib/go-tc"
        
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
+
        "github.com/jmoiron/sqlx"
 )
 
@@ -76,3 +78,10 @@ func CreateChangeLog(level string, action string, i 
Identifier, user auth.Curren
        }
        return nil
 }
+
+func CreateChangeLogRaw(level string, message string, user auth.CurrentUser, 
db *sql.DB) error {
+       if _, err := db.Exec(`INSERT INTO log (level, message, tm_user) VALUES 
($1, $2, $3)`, level, message, user.ID); err != nil {
+               return fmt.Errorf("inserting change log level '%v' message '%v' 
user '%v': %v", level, message, user.ID, err)
+       }
+       return nil
+}
diff --git a/traffic_ops/traffic_ops_golang/crconfig/handler.go 
b/traffic_ops/traffic_ops_golang/crconfig/handler.go
index 0c4453c93..6822b60c9 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/handler.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/handler.go
@@ -189,9 +189,13 @@ func SnapshotHandler(db *sqlx.DB, cfg config.Config) 
http.HandlerFunc {
                }
 
                if err := Snapshot(db.DB, crConfig); err != nil {
+                       log.Errorln(r.RemoteAddr + " snaphsotting CRConfig: " + 
err.Error())
                        handleErrs(http.StatusInternalServerError, err)
                        return
                }
+               if err := api.CreateChangeLogRaw(api.ApiChange, "Snapshot of 
CRConfig performed for "+cdn, *user, db.DB); err != nil {
+                       log.Errorln("creating CRConfig snapshot changelog: " + 
err.Error())
+               }
                w.WriteHeader(http.StatusOK) // TODO change to 204 No Content 
in new version
        }
 }
@@ -236,7 +240,9 @@ func SnapshotOldGUIHandler(db *sqlx.DB, cfg config.Config) 
http.HandlerFunc {
                        writePerlHTMLErr(w, r, err)
                        return
                }
-
+               if err := api.CreateChangeLogRaw(api.ApiChange, "Snapshot of 
CRConfig performed for "+cdn, *user, db.DB); err != nil {
+                       log.Errorln("creating CRConfig snapshot changelog: " + 
err.Error())
+               }
                http.Redirect(w, r, 
"/tools/flash_and_close/"+url.PathEscape("Successfully wrote the 
CRConfig.json!"), http.StatusFound)
        }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to