Пример #1
0
def conservator(empty_db):
    """
    Provides a Conservator connection to be used for testing.

    The Conservator's database will be empty except for users and organizations. This
    instance will have admin permissions, integration suites do not (currently) test
    permissions. It's assumed we can do anything.
    """
    # TODO: Initialize an organization, groups.
    organization = empty_db.organizations.find_one({})
    assert organization is not None, "Make sure conservator is initialized"
    if "TEST_API_KEY" in os.environ:
        api_key = os.environ["TEST_API_KEY"]
    else:
        api_key = secrets.token_urlsafe(16)
    if "TEST_ADMIN_EMAIL" in os.environ:
        admin_email = os.environ["TEST_ADMIN_EMAIL"]
    else:
        admin_email = "*****@*****.**"

    empty_db.users.insert_one({
        "_id": Conservator.generate_id(),
        "role": ADMIN_ROLE,
        "name": "admin user",
        "email": admin_email,
        "apiKey": api_key,
        "organizationId": organization["_id"],
    })
    config = Config(CONSERVATOR_API_KEY=api_key,
                    CONSERVATOR_URL=test_settings.conservator_url)
    print(
        f"Using key={api_key[0]}***{api_key[-1]}, email={admin_email} url={test_settings.conservator_url}"
    )
    yield Conservator(config)
Пример #2
0
 def wrapper(*args, **kwargs):
     ctx_obj = get_current_context().obj
     path = ctx_obj["cvc_local_path"]
     conservator = Conservator.create(ctx_obj["config_name"])
     # raises InvalidLocalDatasetPath if the path does not point to a
     # valid LocalDataset (defined as a directory containing index.json).
     local_dataset = LocalDataset(conservator, path)
     return func(local_dataset, *args, **kwargs)
Пример #3
0
 def upload(localpath, remote_collection, remote_name,
            create_collections):
     ctx_obj = click.get_current_context().obj
     conservator = Conservator.create(ctx_obj["config_name"])
     if create_collections:
         collection = conservator.collections.from_remote_path(
             path=remote_collection, make_if_no_exist=True, fields="id")
     else:
         collection = conservator.collections.from_string(
             remote_collection, fields="id")
     conservator.media.upload(localpath,
                              collection=collection,
                              remote_name=remote_name)
     return True
Пример #4
0
def interactive():
    global conservator
    ctx_obj = click.get_current_context().obj
    conservator = Conservator.create(ctx_obj["config_name"])

    click.secho(
        """This is an interactive conservator "shell" that simulates the directory\n"""
        """structure of Conservator's collections. Type "help" to see available commands.""",
        fg="cyan",
    )

    domain = conservator.get_domain()

    click.secho(f"Loading identity from {domain}...", fg="yellow")
    username = conservator.get_user().name
    get_root_collections()

    while True:
        user = click.style(f"{username}@{domain}:", fg="magenta", bold=True)
        path = click.style(f"{pwd}", fg="blue", bold=True)
        end = click.unstyle("$ ")
        command = input(user + path + end)
        run_shell_command(command)
Пример #5
0
from FLIR.conservator.conservator import Conservator

conservator = Conservator.default()

project_name = "ADAS"

# The "name" field is searched by default, but we need to add a filter
# to make sure that the name is an exact match. Searches only check for
# substring containment, so searching "ADAS" would match "ADAS"
# and also something like "ADAS External".

# With filtered_by, we make sure to only return projects where the name is
# an exact match.
print("Normal search:")
results = conservator.projects.search(
    project_name, fields="name").filtered_by(name=project_name)
for project in results:
    assert project.name == project_name
    print(project)

# We could also slightly speed up the query using Conservator's Advanced
# Search syntax. We can specify which field to search in the search text:
print()
print("Search by name field only:")
results = conservator.projects.search(
    f'name:"{project_name}"', fields="name").filtered_by(name=project_name)
for project in results:
    assert project.name == project_name
    print(project)

# The above is a common pattern, so it's been added as a function on
Пример #6
0
def view(name):
    config = Config.from_name(name)
    conservator = Conservator(config)
    click.echo(config)
    click.echo(f"Corresponds to email: {conservator.get_email()}")
Пример #7
0
def whoami():
    ctx_obj = click.get_current_context().obj
    conservator = Conservator.create(ctx_obj["config_name"])
    user = conservator.get_user()
    click.echo(to_clean_string(user))
Пример #8
0
 def get_instance():
     ctx_obj = click.get_current_context().obj
     conservator = Conservator.create(ctx_obj["config_name"])
     return type_manager(conservator)
Пример #9
0
def clone(ctx, identifier, path, checkout):
    conservator = Conservator.create(ctx.obj["config_name"])
    dataset = conservator.datasets.from_string(identifier)
    cloned = LocalDataset.clone(dataset, path)
    if checkout is not None:
        cloned.checkout(checkout)