Skip to content

Commit e8cfd92

Browse files
committed
Check if already exists when installing a certificate
Signed-off-by: Ming Lu <ming.lu@cloud.com>
1 parent ab9f725 commit e8cfd92

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ocaml/xapi/certificates.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,15 @@ end = struct
341341
in
342342
let fingerprint_sha256 = pp_fingerprint ~hash_type:`SHA256 certificate in
343343
let fingerprint_sha1 = pp_fingerprint ~hash_type:`SHA1 certificate in
344+
let expr =
345+
let open Xapi_database.Db_filter_types in
346+
let type' = Record_util.certificate_type_to_string _type in
347+
let type' = Eq (Field "type", Literal type') in
348+
let fingerprint_sha256 = Eq (Field "type", Literal fingerprint_sha256) in
349+
And (type', fingerprint_sha256)
350+
in
351+
if Db.Certificate.get_refs_where ~__context ~expr <> [] then
352+
raise_server_error [name] certificate_already_exists ;
344353
let uuid = Uuidx.(to_string (make ())) in
345354
let ref' = Ref.make () in
346355
Db.Certificate.create ~__context ~ref:ref' ~uuid ~host ~not_before

0 commit comments

Comments
 (0)