dservercore.utils
Utility functions.
Functions
|
Return True if the base URI has been registered. |
Create an object adhering to the Dataset model from a dict-like object admin_metadata. |
|
|
Return True if the dataset info is valid. |
|
Return True if the dataset URI has been registered. |
|
Delete a base URI from dserver. |
|
Delete a dataset in the lookup server. |
Delete the admin metadata from the dataset SQL table. |
|
|
Delete a single user from the system. |
|
Delete a list of users in the system. |
|
Return dictionary with dataset info. |
Return the dataset SQL table row as dictionary. |
|
|
Return the annotations. |
|
Return SQLAlchemy BaseURI object. |
|
Return single dataset with matching uri if user has rights to see it. |
|
Return SQLAlchemy Dataset object. |
|
Return the manifest. |
|
Return the permissions on a base URI as a dictionary. |
|
Return the readme. |
|
Return tags. |
|
Return information about a user as a dictionary. |
|
Retrieve User object from username. |
|
Return list of dictionaries with admin metadata from dataset SQL table. |
List the base URIs in dserver. |
|
|
List the datasets the user has access to. |
Return list of users. |
|
|
Return list of dataset with matching uuid. |
|
Convert all-upper-case entries in dict-like object to dict and exclude certain keys. |
|
Convert all-upper-case keys in dict-like object to all-lower-case keys dict and exclude certain keys. |
|
Return query with appropriate base URIs. |
|
Register a base URI in dserver. |
|
Put-update a dataset in the lookup server. |
|
Update the admin metadata in the dataset SQL table by replacing a possibly existing dataset entry. |
|
Register or update permissions on base_uri. |
|
Register or update a single user in the system by replacing entry. |
|
Register a list of users in the system. |
|
Search the datasets the user has access to. |
|
Return summary information of datasets the user has access to. |
|
Update a list of users in the system. |
|
Translates a URI like |
|
Translates a URL suffix like |
|
Check whether user is registered in the system. |
Dumps installed components and their versions to dictionary, i.e. |
- dservercore.utils.obj_to_dict(obj, exclusions=[])
Convert all-upper-case entries in dict-like object to dict and exclude certain keys.
- dservercore.utils.obj_to_lowercase_key_dict(obj, exclusions=[])
Convert all-upper-case keys in dict-like object to all-lower-case keys dict and exclude certain keys.
- dservercore.utils.versions_to_dict()
Dumps installed components and their versions to dictionary, i.e.
- {
‘dservercore’: ‘0.17.2’, ‘dserver_retrieve_plugin_mongo’: ‘0.1.0’, ‘dserver_search_plugin_mongo’: ‘0.1.0’
}
- dservercore.utils.generate_dataset_info(dataset, base_uri)
Return dictionary with dataset info.
- dservercore.utils.user_exists(username)
Check whether user is registered in the system.
- dservercore.utils.get_user_obj(username)
Retrieve User object from username.
- dservercore.utils.register_user(username, data)
Register or update a single user in the system by replacing entry. Idempotent.
Example input structure:
{"is_admin": True},
If a user is missing in the system it is skipped. The
is_adminstatus defaults to False.
- dservercore.utils.register_users(users)
Register a list of users in the system.
Example input structure:
[ {"username": "magic.mirror", "is_admin": True}, {"username": "snow.white", "is_admin": False}, {"username": "dopey"}, {"username": "sleepy"}, ]
If a user is already registered in the system it is skipped. To change the
is_adminstatus of an existing user use theupdate_users`()function. Theis_adminstatus defaults to False.
- dservercore.utils.list_users()
Return list of users.
- dservercore.utils.delete_users(users)
Delete a list of users in the system.
Example input structure:
[ {"username": "magic.mirror", "is_admin": True}, {"username": "snow.white", "is_admin": False}, {"username": "dopey"}, {"username": "sleepy"}, ]
If a user is missing in the system it is skipped. Only the “username” key is used to identify a user, any other keys, such as “is_admin”, are ignored. The list of dictionary input argument is used to be consistent with the
list_users`()and theregister_users()functions.
- dservercore.utils.delete_user(username)
Delete a single user from the system.
- dservercore.utils.update_users(users)
Update a list of users in the system.
Example input structure:
[ {"username": "magic.mirror", "is_admin": True}, {"username": "snow.white", "is_admin": False}, {"username": "dopey"}, {"username": "sleepy"}, ]
If a user is missing in the system it is skipped. The
is_adminstatus defaults to False.
- dservercore.utils.get_user_info(username)
Return information about a user as a dictionary.
Return None if the user does not exist.
- dservercore.utils.list_datasets_by_user(username, pagination_parameters: PaginationParameters = None, sort_parameters: SortParameters = None)
List the datasets the user has access to.
- Parameters:
pagination_parameters – flask_smorest.pagination.PaginationParameters object, optional
sort_parameters – dservercore.sort.SortParameters object, optional
Returns list of dicts if user is valid and has access to datasets. Returns empty list if user is valid but has not got access to any datasets. Raises AuthenticationError if user is invalid.
- dservercore.utils.summary_of_datasets_by_user(username)
Return summary information of datasets the user has access to.
Return dictionary of summary information. Raises AuthenticationError if user is invalid.
- dservercore.utils.lookup_datasets_by_user_and_uuid(username, uuid, pagination_parameters: PaginationParameters = None, sort_parameters: SortParameters = None)
Return list of dataset with matching uuid.
Returns list of dicts if user is valid and has access to datasets. Returns empty list if user is valid but has not got access to any datasets. Raises AuthenticationError if user is invalid.
- dservercore.utils.get_dataset_by_user_and_uri(username, uri)
Return single dataset with matching uri if user has rights to see it.
Returns single Dataset if user is valid and has access to datasets. Returns None if user is valid but has not got access to the dataset. Raises AuthenticationError if user is invalid.
- dservercore.utils.preprocess_query_base_uris(username, query)
Return query with appropriate base URIs.
If no base URIs are in the query add all the allowed ones. If base URIs are provided only include the ones allowed.
- dservercore.utils.search_datasets_by_user(username, query, pagination_parameters: PaginationParameters = None, sort_parameters: SortParameters = None)
Search the datasets the user has access to.
Valid keys for the query are: creator_usernames, base_uris, free_text. If the query dictionary is empty all datasets, that a user has access to, are returned.
- Parameters:
username – username
query – dictionary specifying query
pagination_parameters – flask_smorest.pagination.PaginationParameters object, optional
sort_parameters – dservercore.sort.SortParameters object, optional
- Returns:
List of dicts if user is valid and has access to datasets. Empty list if user is valid but has not got access to any datasets.
- Raises:
AuthenticationError if user is invalid.
- dservercore.utils.url_suffix_to_uri(url_suffix)
Translates a URL suffix like
s3/bucket
to a valid URI, e.g.
s3://bucket
- dservercore.utils.uri_to_url_suffix(uri)
Translates a URI like
s3://bucket
to a URL suffix like
s3/bucket
- dservercore.utils.base_uri_exists(base_uri)
Return True if the base URI has been registered.
- dservercore.utils.get_base_uri_obj(base_uri)
Return SQLAlchemy BaseURI object.
- dservercore.utils.register_base_uri(base_uri)
Register a base URI in dserver.
- dservercore.utils.delete_base_uri(base_uri)
Delete a base URI from dserver.
- dservercore.utils.list_base_uris()
List the base URIs in dserver.
- dservercore.utils.get_permission_info(base_uri_str)
Return the permissions on a base URI as a dictionary.
- dservercore.utils.register_permissions(base_uri, permissions)
Register or update permissions on base_uri. Idempotent.
- dservercore.utils.dataset_uri_exists(uri)
Return True if the dataset URI has been registered.
- dservercore.utils.get_dataset_obj(uri)
Return SQLAlchemy Dataset object.
- dservercore.utils.dataset_info_is_valid(dataset_info)
Return True if the dataset info is valid.
- dservercore.utils.create_dataset_obj_from_admin_metadata(admin_metadata)
Create an object adhering to the Dataset model from a dict-like object admin_metadata.
- dservercore.utils.register_dataset_admin_metadata(admin_metadata)
Update the admin metadata in the dataset SQL table by replacing a possibly existing dataset entry.
- dservercore.utils.delete_dataset_admin_metadata(uri)
Delete the admin metadata from the dataset SQL table.
- Parameters:
uri – URI of dataset entry to delete.
- Returns:
URI of successfully deleted dataset entry
- dservercore.utils.register_dataset(dataset_info)
Put-update a dataset in the lookup server. Put is idempotent.
- dservercore.utils.delete_dataset(uri)
Delete a dataset in the lookup server. Idempotent.
- Parameters:
uri – URI of dataset entry to remove from dserver.
- Returns:
URI of successfully removed dataset entry.
- Raises:
ValidationError – if deletion fails within dserver core, or within search and retrieve plugin.
- dservercore.utils.get_admin_metadata_from_uri(uri)
Return the dataset SQL table row as dictionary.
- dservercore.utils.list_admin_metadata_in_base_uri(base_uri_str)
Return list of dictionaries with admin metadata from dataset SQL table.
- dservercore.utils.get_readme_from_uri_by_user(username, uri)
Return the readme.
- Parameters:
username – username
uri – dataset URI
- Returns:
dataset readme
- Raises:
AuthenticationError if user is invalid. AuthorizationError if the user has not got permissions to read content in the base URI UnknownBaseURIError if the base URI has not been registered. UnknownURIError if the URI is not available to the user.
- dservercore.utils.get_manifest_from_uri_by_user(username, uri)
Return the manifest.
- Parameters:
username – username
uri – dataset URI
- Returns:
dataset manifest
- Raises:
AuthenticationError if user is invalid. AuthorizationError if the user has not got permissions to read content in the base URI UnknownBaseURIError if the base URI has not been registered. UnknownURIError if the URI is not available to the user.
- dservercore.utils.get_tags_from_uri_by_user(username, uri)
Return tags.
- Parameters:
username – username
uri – dataset URI
- Returns:
dataset tags
- Raises:
AuthenticationError if user is invalid. AuthorizationError if the user has not got permissions to read content in the base URI UnknownBaseURIError if the base URI has not been registered. UnknownURIError if the URI is not available to the user.
- dservercore.utils.get_annotations_from_uri_by_user(username, uri)
Return the annotations.
- Parameters:
username – username
uri – dataset URI
- Returns:
dataset annotations
- Raises:
AuthenticationError if user is invalid. AuthorizationError if the user has not got permissions to read content in the base URI UnknownBaseURIError if the base URI has not been registered. UnknownURIError if the URI is not available to the user.