Insert or update the record in the database as needed.
(cert, source, ct_collection, cert_zones)
| 335 | |
| 336 | |
| 337 | def insert_certificate(cert, source, ct_collection, cert_zones): |
| 338 | """ |
| 339 | Insert or update the record in the database as needed. |
| 340 | """ |
| 341 | |
| 342 | if ( |
| 343 | ct_collection.count_documents( |
| 344 | {"fingerprint_sha256": cert["fingerprint_sha256"]} |
| 345 | ) |
| 346 | == 0 |
| 347 | ): |
| 348 | ct_collection.insert_one(cert) |
| 349 | else: |
| 350 | ct_collection.update_many( |
| 351 | {"fingerprint_sha256": cert["fingerprint_sha256"]}, |
| 352 | { |
| 353 | "$set": { |
| 354 | source + "_id": cert[source + "_id"], |
| 355 | "ct_log_type": cert["ct_log_type"], |
| 356 | "zones": cert_zones, |
| 357 | "marinus_updated": datetime.now(), |
| 358 | }, |
| 359 | "$addToSet": {"sources": source}, |
| 360 | }, |
| 361 | ) |
| 362 | |
| 363 | |
| 364 | def write_file(logger, storage_manager, cert, save_location, save_type, source): |