Exemplo n.º 1
0
def delete_content_blocks():

    parser = argparse.ArgumentParser(
        description=("Delete content blocks from specified collections "
                     "with timestamp labels matching defined time window"),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-c",
                        "--collection",
                        action="append",
                        dest="collection",
                        help="Collection to remove content blocks from",
                        required=True)

    parser.add_argument(
        "--begin",
        dest="begin",
        help="exclusive beginning of time window as ISO8601 formatted date",
        required=True)

    parser.add_argument(
        "--end",
        dest="end",
        help="inclusive ending of time window as ISO8601 formatted date")

    args = parser.parse_args()

    with app.app_context():

        start_time = args.begin
        end_time = args.end

        for collection in args.collection:
            app.taxii_server.persistence.delete_content_blocks(
                collection, start_time=start_time, end_time=end_time)
Exemplo n.º 2
0
def delete_content_blocks():

    parser = argparse.ArgumentParser(
        description=(
            "Delete content blocks from specified collections "
            "with timestamp labels matching defined time window"),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument(
        "-c", "--collection", action="append", dest="collection",
        help="Collection to remove content blocks from", required=True)

    parser.add_argument(
        "--begin", dest="begin",
        help="exclusive beginning of time window as ISO8601 formatted date",
        required=True)

    parser.add_argument(
        "--end", dest="end",
        help="inclusive ending of time window as ISO8601 formatted date")

    args = parser.parse_args()

    with app.app_context():

        start_time = args.begin
        end_time = args.end

        for collection in args.collection:
            app.taxii_server.persistence.delete_content_blocks(
                collection, start_time=start_time, end_time=end_time)
Exemplo n.º 3
0
def update_account(argv=None):
    parser = argparse.ArgumentParser(
        description="Update Account via OpenTAXII Auth API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    fields = ("password", "admin")
    parser.add_argument("-u", "--username", required=True)
    parser.add_argument("-f", "--field", choices=fields, required=True)
    parser.add_argument("-v", "--value", required=True)

    if argv is None:
        argv = sys.argv[1:]
    args = parser.parse_args(argv)

    with app.app_context():
        accounts = app.taxii_server.auth.get_accounts()
        for account in accounts:
            if account.username != args.username:
                continue
            if args.field == 'password':
                app.taxii_server.auth.update_account(account, password=args.value)
                print('password has been changed')
                return
            if args.field == 'admin':
                account.is_admin = is_truely(args.value)
                app.taxii_server.auth.update_account(account)
                if account.is_admin:
                    print('now user is admin')
                else:
                    print('now user is mortal')
                return
    print('cannot find account with given username')
Exemplo n.º 4
0
def create_account():

    parser = argparse.ArgumentParser(
        description="Create Account via OpenTAXII Auth API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-u",
                        "--username",
                        dest="username",
                        help="Username for the new account",
                        required=True)

    parser.add_argument("-p",
                        "--password",
                        dest="password",
                        help="Password for the new account",
                        required=True)

    args = parser.parse_args()

    with app.app_context():

        account = app.taxii_server.auth.create_account(args.username,
                                                       args.password)

        token = app.taxii_server.auth.authenticate(account.username,
                                                   args.password)

        log.info("account.token", token=token, username=account.username)
Exemplo n.º 5
0
def create_services():

    parser = argparse.ArgumentParser(
        description="Create services using OpenTAXII Persistence API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument(
        "-c", "--services-config", dest="config",
        help="YAML file with services configuration", required=True)

    args = parser.parse_args()
    services_config = anyconfig.load(args.config, forced_type="yaml")

    with app.app_context():

        app.taxii_server.persistence.create_services_from_object(
            services_config)
Exemplo n.º 6
0
def create_collections():

    parser = argparse.ArgumentParser(
        description="Create collections using OpenTAXII Persistence API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument(
        "-c", "--collections-config", dest="config",
        help="YAML file with collections configuration", required=True)

    args = parser.parse_args()
    collections_config = anyconfig.load(args.config, forced_type="yaml")

    with app.app_context():

        created = 0
        for collection in collections_config:

            service_ids = collection.pop('service_ids')
            existing = None

            for service_id in service_ids:
                existing = app.taxii_server.persistence.get_collection(
                    collection['name'],
                    service_id)
                if existing:
                    break

            if existing:
                log.warning(
                    "collection.skipped.already_exists",
                    collection_name=collection['name'],
                    existing_id=existing.id)
                continue

            c = app.taxii_server.persistence.create_collection(
                CollectionEntity(**collection))

            app.taxii_server.persistence.attach_collection_to_services(
                c.id, service_ids=service_ids)

            created += 1
Exemplo n.º 7
0
def create_services():

    parser = argparse.ArgumentParser(
        description="Create services using OpenTAXII Persistence API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-c",
                        "--services-config",
                        dest="config",
                        help="YAML file with services configuration",
                        required=True)

    args = parser.parse_args()
    services_config = anyconfig.load(args.config, forced_type="yaml")

    with app.app_context():

        app.taxii_server.persistence.create_services_from_object(
            services_config)
Exemplo n.º 8
0
def create_collections():

    parser = argparse.ArgumentParser(
        description="Create collections using OpenTAXII Persistence API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-c",
                        "--collections-config",
                        dest="config",
                        help="YAML file with collections configuration",
                        required=True)

    args = parser.parse_args()
    collections_config = anyconfig.load(args.config, forced_type="yaml")
    collections = collections_config.get('collections', [])

    with app.app_context():

        created = 0
        for collection in collections:

            service_ids = collection.pop('service_ids')
            existing = None

            for service_id in service_ids:
                existing = app.taxii_server.persistence.get_collection(
                    collection['name'], service_id)
                if existing:
                    break

            if existing:
                log.warning("collection.skipped.already_exists",
                            collection_name=collection['name'],
                            existing_id=existing.id)
                continue

            c = app.taxii_server.persistence.create_collection(
                CollectionEntity(**collection))

            app.taxii_server.persistence.attach_collection_to_services(
                c.id, service_ids=service_ids)

            created += 1
Exemplo n.º 9
0
def sync_data_configuration():
    parser = argparse.ArgumentParser(
        description="Create services/collections/accounts",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "config", help="YAML file with data configuration")
    parser.add_argument(
        "-f", "--force-delete", dest="force_deletion",
        action="store_true",
        help=("force deletion of collections and their content blocks "
              "if collection is not defined in configuration file"),
        required=False)
    args = parser.parse_args()
    config = anyconfig.load(args.config, forced_type="yaml")

    with app.app_context():
        # run as admin with full access
        context.account = local_admin
        sync_conf_dict_into_db(
            app.taxii_server,
            config,
            force_collection_deletion=args.force_deletion)
Exemplo n.º 10
0
def sync_data_configuration():
    parser = argparse.ArgumentParser(
        description="Create services/collections/accounts",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "config", help="YAML file with data configuration")
    parser.add_argument(
        "-f", "--force-delete", dest="force_deletion",
        action="store_true",
        help=("force deletion of collections and their content blocks "
              "if collection is not defined in configuration file"),
        required=False)
    args = parser.parse_args()
    config = anyconfig.load(args.config, forced_type="yaml")

    with app.app_context():
        # run as admin with full access
        context.account = local_admin
        sync_conf_dict_into_db(
            app.taxii_server,
            config,
            force_collection_deletion=args.force_deletion)
Exemplo n.º 11
0
def create_account(argv=None):
    parser = argparse.ArgumentParser(
        description="Create Account via OpenTAXII Auth API",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser.add_argument("-u", "--username", required=True)
    parser.add_argument("-p", "--password", required=True)
    parser.add_argument("-a", "--admin", action="store_true", help="grant admin access")

    if argv is None:
        argv = sys.argv[1:]
    args = parser.parse_args(argv)

    with app.app_context():
        account = app.taxii_server.auth.api.create_account(
            username=args.username,
            password=args.password,
        )
        token = app.taxii_server.auth.authenticate(
            username=account.username,
            password=args.password,
        )
        print('token: {}'.format(token))