async def get_user_info(request: Request): user = user_info(request) groups = get_all_individual_groups(user["memberof"]) groups = [Group(id=private_group_id(user), path="private")] + \ [Group(id=str(to_group_id(g)), path=g) for g in groups if g] return User(name=user['preferred_username'], groups=groups)
async def get_groups(request: Request): user = user_info(request) groups = get_all_individual_groups(user["memberof"]) groups = [Group(id=private_group_id(user), path="private")] + \ [Group(id=str(to_group_id(g)), path=g) for g in groups if g] return GroupsResponse(groups=groups)
def to_asset_meta(body: Dict[str, Any]): group_id = body['groupId'] if 'groupId' in body else to_group_id( body['scope']) return AssetMeta(name=body['name'], description=body['description'], kind=body['kind'], groupId=group_id, tags=body['tags'])
async def get_records( request: Request, body: GetRecordsBody, configuration: Configuration = Depends(get_configuration)): items_db, folders_db, drives_db = configuration.doc_dbs.items_db, configuration.doc_dbs.folders_db, \ configuration.doc_dbs.drives_db drives, folders = await asyncio.gather( ensure_query_permission(request=request, docdb=drives_db, key="drive_id", value=body.folderId, max_count=1, configuration=configuration), ensure_query_permission(request=request, docdb=folders_db, key="folder_id", value=body.folderId, max_count=1, configuration=configuration)) if len(drives) + len(folders) == 0: raise HTTPException(status_code=404, detail="Item not found") entities = await get_items_rec(request=request, folder_id=body.folderId, configuration=configuration) table_items = RecordsTable(id=items_db.table_name, primaryKey=items_db.table_body.partition_key[0], values=entities[0]) table_folders = RecordsTable( id=folders_db.table_name, primaryKey=folders_db.table_body.partition_key[0], values=entities[1]) group_id = to_group_id(configuration.public_owner) keyspace = RecordsKeyspace(id=items_db.keyspace_name, groupId=group_id, tables=[table_items, table_folders]) response = RecordsResponse(docdb=RecordsDocDb(keyspaces=[keyspace]), storage=RecordsStorage(buckets=[])) return response
async def records( body: GetRecordsBody, configuration: Configuration = Depends(get_configuration) ): doc_db = configuration.doc_db storage = configuration.storage def get_paths(project_id): base = Path('projects')/project_id return [base / name for name in ['builderRendering.json', 'description.json', 'requirements.json', 'runnerRendering.json', 'workflow.json']] paths = [get_paths(project_id) for project_id in body.ids] paths = list(flatten(paths)) group_id = to_group_id(configuration.default_owner) table = RecordsTable( id=doc_db.table_name, primaryKey=doc_db.table_body.partition_key[0], values=body.ids ) keyspace = RecordsKeyspace( id=doc_db.keyspace_name, groupId=group_id, tables=[table] ) bucket = RecordsBucket( id=storage.bucket_name, groupId=group_id, paths=[str(p) for p in paths] ) response = RecordsResponse( docdb=RecordsDocDb(keyspaces=[keyspace]), storage=RecordsStorage(buckets=[bucket]) ) return response
def to_asset_resp( asset, permissions=None) -> Union[AssetResponse, AssetWithPermissionResponse]: group_id = asset['groupId'] if 'groupId' in asset else to_group_id( asset['scope']) if permissions: return AssetWithPermissionResponse( **{ **asset, **{ "rawId": asset["relatedId"], "groupId": group_id, "permissions": permissions } }) return AssetResponse(**{ **asset, **{ "rawId": asset["relatedId"], "groupId": group_id } })