This is an automated email from the ASF dual-hosted git repository.
rob 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 5808d26 T3c Change they way the cookie file is written (#6614)
5808d26 is described below
commit 5808d26f328110d2e0ce677b85ab59e3622a06da
Author: Joe Pappano <[email protected]>
AuthorDate: Fri Mar 4 11:34:05 2022 -0500
T3c Change they way the cookie file is written (#6614)
* Added constant for time and date layout
* More descriptive error when certificate parsing occurs and date format
uses constant variable.
* added check for empty cookie which can occur when jason is valid but
doesn't match the struct
* Cookie file is written to .tmp file, then copied into place.
* Cookie file is written to .tmp file, then copied into place.
---
cache-config/t3cutil/toreq/clientfuncs.go | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/cache-config/t3cutil/toreq/clientfuncs.go
b/cache-config/t3cutil/toreq/clientfuncs.go
index 10fbeb3..c65b384 100644
--- a/cache-config/t3cutil/toreq/clientfuncs.go
+++ b/cache-config/t3cutil/toreq/clientfuncs.go
@@ -26,6 +26,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
+ "os"
"strconv"
"strings"
@@ -66,6 +67,7 @@ func (cl *TOClient) GetProfileByName(profileName string,
reqHdr http.Header) (tc
}
func (cl *TOClient) WriteFsCookie(fileName string) {
+ tmpFileName := fileName + ".tmp"
cookie := torequtil.FsCookie{}
u, err := url.Parse(cl.c.URL)
if err != nil {
@@ -84,12 +86,16 @@ func (cl *TOClient) WriteFsCookie(fileName string) {
log.Warnln("Error creating JSON cookie file: ", err)
return
}
- err = ioutil.WriteFile(fileName, fsCookie, 0600)
+ log.Infof("Writing temp file '%s'", tmpFileName)
+ err = ioutil.WriteFile(tmpFileName, fsCookie, 0600)
if err != nil {
log.Warnln("Error writing cooking file: ", err)
return
}
- log.Infoln("Wrote new auth cookie to filesystem")
+ if err := os.Rename(tmpFileName, fileName); err != nil {
+ log.Warnln("Error moving cookie file: ", err)
+ }
+ log.Infof("Copying temp file '%s' to real '%s'", tmpFileName, fileName)
}
func (cl *TOClient) GetGlobalParameters(reqHdr http.Header) ([]tc.Parameter,
toclientlib.ReqInf, error) {