Пример #1
0
def validate_sources(source_strings):
    sources = []
    if not source_strings:
        table = []
        for source in source_service.get_all():
            table.append([source.label, source.active, source.description])

        print("No source specified choose from below:")
        print(tabulate(table, headers=['Label', 'Active', 'Description']))
        sys.exit(1)

    if 'all' in source_strings:
        sources = source_service.get_all()
    else:
        for source_str in source_strings:
            source = source_service.get_by_label(source_str)

            if not source:
                print("Unable to find specified source with label: {0}".format(source_str))
                sys.exit(1)

            sources.append(source)
    return sources
Пример #2
0
def sync(labels):
    """
    Attempts to run several methods Certificate discovery. This is
    run on a periodic basis and updates the Lemur datastore with the
    information it discovers.
    """
    if not labels:
        sys.stdout.write("Active\tLabel\tDescription\n")
        for source in source_service.get_all():
            sys.stdout.write(
                "{active}\t{label}\t{description}!\n".format(
                    label=source.label,
                    description=source.description,
                    active=source.active
                )
            )
    else:
        start_time = time.time()
        lock_file = "/tmp/.lemur_lock"
        sync_lock = LockFile(lock_file)

        while not sync_lock.i_am_locking():
            try:
                sync_lock.acquire(timeout=10)    # wait up to 10 seconds

                sys.stdout.write("[+] Staring to sync sources: {labels}!\n".format(labels=labels))
                labels = labels.split(",")

                if labels[0] == 'all':
                    source_sync()
                else:
                    source_sync(labels=labels)

                sys.stdout.write(
                    "[+] Finished syncing sources. Run Time: {time}\n".format(
                        time=(time.time() - start_time)
                    )
                )
            except LockTimeout:
                sys.stderr.write(
                    "[!] Unable to acquire file lock on {file}, is there another sync running?\n".format(
                        file=lock_file
                    )
                )
                sync_lock.break_lock()
                sync_lock.acquire()
                sync_lock.release()

        sync_lock.release()
Пример #3
0
def sync_sources(labels):
    """
    Attempts to run several methods Certificate discovery. This is
    run on a periodic basis and updates the Lemur datastore with the
    information it discovers.
    """
    if not labels:
        sys.stdout.write("Active\tLabel\tDescription\n")
        for source in source_service.get_all():
            sys.stdout.write("{active}\t{label}\t{description}!\n".format(
                label=source.label,
                description=source.description,
                active=source.active))
    else:
        start_time = time.time()
        lock_file = "/tmp/.lemur_lock"
        sync_lock = LockFile(lock_file)

        while not sync_lock.i_am_locking():
            try:
                sync_lock.acquire(timeout=10)  # wait up to 10 seconds

                sys.stdout.write(
                    "[+] Staring to sync sources: {labels}!\n".format(
                        labels=labels))
                labels = labels.split(",")

                if labels[0] == 'all':
                    sync()
                else:
                    sync(labels=labels)

                sys.stdout.write(
                    "[+] Finished syncing sources. Run Time: {time}\n".format(
                        time=(time.time() - start_time)))
            except LockTimeout:
                sys.stderr.write(
                    "[!] Unable to acquire file lock on {file}, is there another sync running?\n"
                    .format(file=lock_file))
                sync_lock.break_lock()
                sync_lock.acquire()
                sync_lock.release()

        sync_lock.release()
Пример #4
0
    def run(self, sources, action):
        if not sources:
            table = []
            for source in source_service.get_all():
                table.append([source.label, source.active, source.description])

            sys.stdout.write(tabulate(table, headers=['Label', 'Active', 'Description']))
            sys.exit(1)

        for label in sources:
            source = source_service.get_by_label(label)

            if not source:
                sys.stderr.write("Unable to find specified source with label: {0}".format(label))

            if action == 'sync':
                self.sync(source)

            if action == 'clean':
                self.clean(source)
Пример #5
0
    def run(self, sources, action):
        if not sources:
            table = []
            for source in source_service.get_all():
                table.append([source.label, source.active, source.description])

            sys.stdout.write(
                tabulate(table, headers=['Label', 'Active', 'Description']))
            sys.exit(1)

        for label in sources:
            source = source_service.get_by_label(label)

            if not source:
                sys.stderr.write(
                    "Unable to find specified source with label: {0}".format(
                        label))

            if action == 'sync':
                self.sync(source)

            if action == 'clean':
                self.clean(source)