]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Require datetime values written to the DB to end with a 'Z'
authorRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 09:36:54 +0000 (10:36 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 09:36:54 +0000 (10:36 +0100)
All datetime values in the DB need to be UTC dates, and are required to ISO 8601 formatted with a trailing 'Z' to indicate they are UTC. The XenAPI did not have any functions that allow users to write datetimes directly to the DB... until recently (e.g. VMPP.set_archive_last_run_time)! It is therefore now necessary to enforce that the datetime values in the parameters of such 'set' functions have the correct form.

For backwards compatibility, XenAPI functions such as message.get_since still allow dates without 'Z', and will assume these are UTC dates.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
ocaml/idl/ocaml_backend/exnHelper.ml
ocaml/idl/ocaml_backend/gen_db_actions.ml

index 8535e41e070a8026e173f8ca357f18d183b1bb6e..54e3bd2a29c87cf244238654db69b412de9efaef 100644 (file)
@@ -47,10 +47,10 @@ let error_of_exn e =
     | Db_cache.Read_missing_uuid (tbl,ref,uuid) ->
        uuid_invalid, [ tbl; uuid ]
          
-    | Db_actions.DM_to_String.StringEnumTypeError s ->
-       invalid_value, [ s ]
+    | Db_actions.DM_to_String.StringEnumTypeError s
+    | Db_actions.DM_to_String.DateTimeError s
     | Db_actions.String_to_DM.StringEnumTypeError s ->
-       invalid_value, [ s ]
+        invalid_value, [ s ]
          
 (* These are the two catch-all patterns. If ever an Errors.Server_error exception   *)
 (* is raised, this is assumed to be an API error, and passed straight on. Any other *)
index ffe6623a4c6661ace6f52b04cffbd497b3bd8fc9..68f623fb9f46d82ab324748dcf1a16470ba37399 100644 (file)
@@ -52,7 +52,7 @@ let dm_to_string tys : O.Module.t =
   let ty_fun ty =
     let body = match ty with
       | DT.Bool -> "string_of_bool"
-      | DT.DateTime -> "fun x -> Date.to_string x"
+      | DT.DateTime -> "fun x -> (try Date.assert_utc x with Invalid_argument s -> raise (DateTimeError s)); Date.to_string x"
       | DT.Enum(name, cs) ->
           let aux (c, _) = (OU.constructor_of c)^" -> \""^c^"\"" in
           "\n    fun v -> match v with\n      "^
@@ -80,6 +80,7 @@ let dm_to_string tys : O.Module.t =
   O.Module.make
     ~name:_dm_to_string
     ~preamble: [ "exception StringEnumTypeError of string";
+                 "exception DateTimeError of string";
                  "open String_marshall_helper" ]
     ~letrec:true
     ~elements:(List.map (fun ty -> O.Module.Let (ty_fun ty)) tys) ()