def validate_destinations(destination_strings): if not destination_strings: table = [] for dest in dest_service.get_all(): table.append([dest.label, dest.description]) print("No destination specified choose from below:") print(tabulate(table, headers=["Label", "Description"])) sys.exit(1) if "all" in destination_strings: return dest_service.get_all() destinations = [] for label in destination_strings: dest = dest_service.get_by_label(label) if not dest: print( "Unable to find specified destination with label: {0}".format( label)) sys.exit(1) destinations.append(dest) return destinations
def sync_update_destination(certificate, source): dest = destination_service.get_by_label(source.label) if dest: for d in certificate.destinations: if d.label == source.label: break else: certificate.destinations.append(dest)
def sync_certificates(source, user): new, updated, updated_by_hash, unlinked = 0, 0, 0, 0 current_app.logger.debug("Retrieving certificates from {0}".format( source.label)) s = plugins.get(source.plugin_name) certificates = s.get_certificates(source.options) # emitting the count of certificates on the source metrics.send("sync_certificates_count", "gauge", len(certificates), metric_tags={"source": source.label}) existing_certificates_with_source_by_id = {} for e in certificate_service.get_all_valid_certificates_with_source( source.id): existing_certificates_with_source_by_id[e.id] = e for certificate in certificates: exists, updated_by_hash = find_cert(certificate) if not certificate.get("owner"): certificate["owner"] = user.email certificate["creator"] = user if not exists: certificate_create(certificate, source) new += 1 else: for e in exists: if certificate.get("external_id"): e.external_id = certificate["external_id"] if certificate.get("authority_id"): e.authority_id = certificate["authority_id"] certificate_update(e, source) if e.id in existing_certificates_with_source_by_id: del existing_certificates_with_source_by_id[e.id] updated += 1 # remove source from any certificates no longer being reported by it destination = destination_service.get_by_label(source.label) for certificate in existing_certificates_with_source_by_id.values(): certificate_service.remove_source_association(certificate, source) current_app.logger.warning( f"Removed source {source.label} for {certificate.name} during source sync" ) if destination in certificate.destinations: certificate_service.remove_destination_association(certificate, destination, clean=False) current_app.logger.warning( f"Removed destination {source.label} for {certificate.name} during source sync" ) updated += 1 unlinked += 1 metrics.send("sync_certificates_unlinked", "gauge", unlinked, metric_tags={"source": source.label}) return new, updated, updated_by_hash