[ARVADOS] updated: 2.1.0-217-g0aec42cb5
Git user
git at public.arvados.org
Wed Dec 16 22:02:36 UTC 2020
Summary of changes:
lib/controller/router/response.go | 71 +++++++++------------------------------
1 file changed, 15 insertions(+), 56 deletions(-)
via 0aec42cb5f4ad6d9593388f3ea5e887ff8b70006 (commit)
from 3764a1e0d2a31333344982478a9d6b861bc179a6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 0aec42cb5f4ad6d9593388f3ea5e887ff8b70006
Author: Tom Clegg <tom at curii.com>
Date: Wed Dec 16 16:56:31 2020 -0500
17014: Remove redundant copy of timestamp/zero-value munging code.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/lib/controller/router/response.go b/lib/controller/router/response.go
index df5a40c9f..d554ab930 100644
--- a/lib/controller/router/response.go
+++ b/lib/controller/router/response.go
@@ -109,45 +109,6 @@ func (rtr *router) sendResponse(w http.ResponseWriter, req *http.Request, resp i
rtr.mungeItemFields(tmp)
}
- for k, v := range tmp {
- if strings.HasSuffix(k, "_at") {
- // Format non-nil timestamps as
- // rfc3339NanoFixed (by default they will have
- // been encoded to time.RFC3339Nano, which
- // omits trailing zeroes).
- switch tv := v.(type) {
- case *time.Time:
- if tv == nil {
- break
- }
- tmp[k] = tv.Format(rfc3339NanoFixed)
- case time.Time:
- if tv.IsZero() {
- tmp[k] = nil
- } else {
- tmp[k] = tv.Format(rfc3339NanoFixed)
- }
- case string:
- t, err := time.Parse(time.RFC3339Nano, tv)
- if err != nil {
- break
- }
- tmp[k] = t.Format(rfc3339NanoFixed)
- }
- }
- switch k {
- // in all this cases, RoR returns nil instead the Zero value for the type.
- // Maytbe, this should all go away when RoR is out of the picture.
- case "output_uuid", "output_name", "log_uuid", "modified_by_client_uuid", "description", "requesting_container_uuid", "expires_at":
- if v == "" {
- tmp[k] = nil
- }
- case "container_count_max":
- if v == float64(0) {
- tmp[k] = nil
- }
- }
- }
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
@@ -184,14 +145,16 @@ func (rtr *router) mungeItemFields(tmp map[string]interface{}) {
for k, v := range tmp {
if strings.HasSuffix(k, "_at") {
// Format non-nil timestamps as
- // rfc3339NanoFixed (otherwise they
- // would use the default time encoding).
+ // rfc3339NanoFixed (otherwise they would use
+ // the default time encoding, which omits
+ // trailing zeroes).
switch tv := v.(type) {
case *time.Time:
- if tv == nil {
- break
+ if tv == nil || tv.IsZero() {
+ tmp[k] = nil
+ } else {
+ tmp[k] = tv.Format(rfc3339NanoFixed)
}
- tmp[k] = tv.Format(rfc3339NanoFixed)
case time.Time:
if tv.IsZero() {
tmp[k] = nil
@@ -199,25 +162,21 @@ func (rtr *router) mungeItemFields(tmp map[string]interface{}) {
tmp[k] = tv.Format(rfc3339NanoFixed)
}
case string:
- t, err := time.Parse(time.RFC3339Nano, tv)
- if err != nil {
- break
- }
- if t.IsZero() {
+ if tv == "" {
+ tmp[k] = nil
+ } else if t, err := time.Parse(time.RFC3339Nano, tv); err != nil {
+ // pass through an invalid time value (?)
+ } else if t.IsZero() {
tmp[k] = nil
} else {
tmp[k] = t.Format(rfc3339NanoFixed)
}
}
}
+ // Arvados API spec says when these fields are empty
+ // they appear in responses as null, rather than a
+ // zero value.
switch k {
- // lib/controller/handler_test.go:TestGetObjects tries to test if we break
- // RoR compatibility. The main reason that we keep this transformations is to comply
- // with that test.
- // In some cases the Arvados specification doesn't mention how to treat "" or nil values,
- // as a first step, we'll just try to return the same that railsapi. In the future,
- // when railsapi is not used anymore, this could all be changed to return whatever we define
- // in the specification.
case "output_uuid", "output_name", "log_uuid", "description", "requesting_container_uuid", "container_uuid":
if v == "" {
tmp[k] = nil
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list