[XAPID-1002] add validate iso8601 time
diff --git a/api.go b/api.go index c1c7643..9e3d5ab 100644 --- a/api.go +++ b/api.go
@@ -56,7 +56,7 @@ const ( sqlTimeFormat = "2006-01-02 15:04:05.999 -0700 MST" - iso8601 = "2 mnn006-01-02T15:04:05.999Z07:00" + iso8601 = "2006-01-02T15:04:05.999Z07:00" sqliteTimeFormat = "2006-01-02 15:04:05.999-07:00" changeTimeFormat = "2006-01-02 15:04:05.999" ) @@ -100,12 +100,6 @@ ApiDeploymentsResponse []ApiDeploymentDetails `json:"contents"` } -type PutConfigStatusResponse struct { - Kind string - Self string - //Contents [] -} - //TODO add support for block and subscriber type apiManagerInterface interface { InitAPI() @@ -449,7 +443,7 @@ return } reported := r.Header.Get("reportedTime") - if reported == "" { + if reported == "" || !isIso8601(reported) { a.writeError(w, http.StatusBadRequest, API_ERR_INVALID_PARAMETERS, "Bad/Missing reportedTime") return } @@ -547,6 +541,18 @@ return r.MatchString(uuid) } +func isIso8601(t string) bool { + + if _, err := time.Parse(iso8601, t); err == nil { + return true + } + if _, err := time.Parse(time.RFC3339, t); err == nil { + return true + } + + return false +} + type registerBody struct { Uuid string `json:"uuid"` Pod string `json:"pod"` @@ -562,7 +568,7 @@ return false, "UUID in path mismatch UUID in body" case !isValidUuid(body.Uuid): return false, "Bad/Missing gateway UUID" - case body.ReportedTime == "": + case body.ReportedTime == "" || !isIso8601(body.ReportedTime): return false, "Bad/Missing gateway ReportedTimeService" } return true, ""
diff --git a/clients.go b/clients.go index 6e47829..d2876f5 100644 --- a/clients.go +++ b/clients.go
@@ -14,7 +14,6 @@ trackerConfigStatusEndpoint = "/serviceconfigstatus" trackerHeartbeatEndpoint = "/serviceheartbeat/{uuid}" trackerRegisterEndpoint = "/serviceregister/{uuid}" - ApigeeSyncTokenSelector = "ApigeeSyncToken" ) type trackerClientInterface interface {