@@ -550,8 +550,10 @@ func (cli *ZSHttpClient) getAccessKeyHeader(url, method string) (http.Header, er
550550
551551 //loc, _ := time.LoadLocation("Asia/Shanghai")
552552 //date := time.Now().In(loc).Format("Mon, 02 Jan 2006 15:04:05 MST")
553+ //date := time.Now().In(time.UTC).Format("Mon, 02 Jan 2006 15:04:05 MST")
554+ //date := time.Now().Local().Format("Mon, 02 Jan 2006 15:04:05 MST")
553555
554- date := time .Now ().Local (). Format ( "Mon, 02 Jan 2006 15:04:05 MST" )
556+ date := formatDateForZStack ( time .Now ().Local ())
555557
556558 contextPath := fmt .Sprintf ("/%s" , cli .contextPath )
557559 uri := url [strings .Index (url , contextPath )+ len (contextPath ):]
@@ -592,7 +594,19 @@ func (cli *ZSHttpClient) Wait(location, responseKey string, retVal interface{})
592594}
593595
594596func (cli * ZSHttpClient ) httpWait (header http.Header , action string , requestURL string , params jsonutils.JSONObject , location string ) (http.Header , jsonutils.JSONObject , error ) {
597+
598+ configHost := fmt .Sprintf ("%s:%d" , cli .hostname , cli .port )
599+ if ! strings .Contains (location , configHost ) {
600+ splitRegex := "/zstack/v1/api-jobs"
601+ parts := strings .Split (location , splitRegex )
602+ if len (parts ) > 1 {
603+ location = fmt .Sprintf ("http://%s%s%s" , configHost , splitRegex , parts [1 ])
604+ golog .Debugf ("Replaced callback URL from %s to %s" , location , location )
605+ }
606+ }
607+
595608 return retryCallback (func () (http.Header , jsonutils.JSONObject , error ) {
609+
596610 resp , err := httputils .Request (cli .httpClient , context .TODO (), httputils .GET , location , header , nil , cli .debug )
597611 if err != nil {
598612 return nil , nil , errors .Wrap (err , fmt .Sprintf ("wait location %s" , location ))
@@ -647,3 +661,22 @@ func retryCallback(fn func() (http.Header, jsonutils.JSONObject, error), action,
647661func jsonMarshal (params interface {}) jsonutils.JSONObject {
648662 return jsonutils .Marshal (params )
649663}
664+
665+ var offsetToAbbr = map [int ]string {
666+ 6 * 3600 + 30 * 60 : "MMT" , // +0630 Myanmar Time
667+ 7 * 3600 : "ICT" , // +0700 Indochina Time
668+ }
669+
670+ func formatDateForZStack (t time.Time ) string {
671+ loc := t .Location ()
672+ zoneName , zoneOffset := t .Zone ()
673+
674+ if (strings .HasPrefix (zoneName , "+" ) || strings .HasPrefix (zoneName , "-" )) && len (zoneName ) == 5 {
675+ if abbr , ok := offsetToAbbr [zoneOffset ]; ok {
676+ loc = time .FixedZone (abbr , zoneOffset )
677+ }
678+ }
679+
680+ t = t .In (loc )
681+ return t .Format ("Mon, 02 Jan 2006 15:04:05 MST" )
682+ }
0 commit comments