Exemple #1
0
def sync(labels=None):
    new, updated = 0, 0
    c_certificates = cert_service.get_all_certs()

    for source in database.get_all(Source, True, field='active'):
        # we should be able to specify, individual sources to sync
        if labels:
            if source.label not in labels:
                continue

        current_app.logger.debug("Retrieving certificates from {0}".format(source.label))
        s = plugins.get(source.plugin_name)
        certificates = s.get_certificates(source.options)

        for certificate in certificates:
            exists = cert_service.find_duplicates(certificate['body'])

            if not exists:
                sync_create(certificate, source)
                new += 1

            # check to make sure that existing certificates have the current source associated with it
            elif len(exists) == 1:
                sync_update(exists[0], source)
                updated += 1
            else:
                current_app.logger.warning(
                    "Multiple certificates found, attempt to deduplicate the following certificates: {0}".format(
                        ",".join([x.name for x in exists])
                    )
                )

        # we need to try and find the absent of certificates so we can properly disassociate them when they are deleted
        _disassociate_certs_from_source(c_certificates, certificates, source)
Exemple #2
0
def get_by_name(policy_name):
    """
    Retrieves policy by its name.
    :param policy_name:
    :return:
    """
    return database.get_all(RotationPolicy, policy_name, field='name').all()
Exemple #3
0
def get_by_name(policy_name):
    """
    Retrieves policy by its name.
    :param policy_name:
    :return:
    """
    return database.get_all(RotationPolicy, policy_name, field='name').all()
Exemple #4
0
def sync(labels=None):
    new, updated = 0, 0
    c_certificates = cert_service.get_all_certs()

    for source in database.get_all(Source, True, field='active'):
        # we should be able to specify, individual sources to sync
        if labels:
            if source.label not in labels:
                continue

        current_app.logger.debug("Retrieving certificates from {0}".format(
            source.label))
        s = plugins.get(source.plugin_name)
        certificates = s.get_certificates(source.options)

        for certificate in certificates:
            exists = cert_service.find_duplicates(
                certificate['public_certificate'])

            if not exists:
                sync_create(certificate, source)
                new += 1

            # check to make sure that existing certificates have the current source associated with it
            elif len(exists) == 1:
                sync_update(exists[0], source)
                updated += 1
            else:
                current_app.logger.warning(
                    "Multiple certificates found, attempt to deduplicate the following certificates: {0}"
                    .format(",".join([x.name for x in exists])))

        # we need to try and find the absent of certificates so we can properly disassociate them when they are deleted
        _disassociate_certs_from_source(c_certificates, certificates, source)
Exemple #5
0
def get_by_name(name):
    """
    Fetches domain by its name

    :param name:
    :return:
    """
    return database.get_all(Domain, name, field="name").all()
Exemple #6
0
def get_by_name(name):
    """
    Fetches domain by its name

    :param name:
    :return:
    """
    return database.get_all(Domain, name, field="name").all()
Exemple #7
0
def sync(labels=None, type=None):
    for source in database.get_all(Source, True, field='active'):
        # we should be able to specify, individual sources to sync
        if labels:
            if source.label not in labels:
                continue

        if type == 'endpoints':
            sync_endpoints(source)
        elif type == 'certificates':
            sync_certificates(source)
        else:
            sync_certificates(source)
            sync_endpoints(source)

        source.last_run = datetime.datetime.utcnow()
        database.update(source)