Beispiel #1
0
async def grant(root: Root, uri: str, user: str, permission: str) -> None:
    """
        Shares resource with another user.

        URI shared resource.

        USER username to share resource with.

        PERMISSION sharing access right: read, write, or manage.

        Examples:
        neuro acl grant storage:///sample_data/ alice manage
        neuro acl grant image:resnet50 bob read
        neuro acl grant job:///my_job_id alice write
    """
    try:
        uri_obj = parse_resource_for_sharing(uri, root)
        action_obj = parse_permission_action(permission)
        permission_obj = Permission(uri=uri_obj, action=action_obj)
        log.info(f"Using resource '{permission_obj.uri}'")

        await root.client.users.share(user, permission_obj)

    except ValueError as e:
        raise ValueError(f"Could not share resource '{uri}': {e}") from e
 async def test_correct_share(self, mocked_share_client: Client) -> None:
     ret = await mocked_share_client.users.share(
         user="******",
         permission=Permission(URL("storage://bob/resource"), Action.READ),
     )
     assert ret is None  # at this moment no result
 async def test_share_invalid_name(self, mocked_share_client: Client) -> None:
     with pytest.raises(ValueError):
         await mocked_share_client.users.share(
             user="******",
             permission=Permission(URL("storage://bob/resource"), Action.READ),
         )
 async def test_share_unknown_user(self, mocked_share_client: Client) -> None:
     with pytest.raises(ResourceNotFound):
         await mocked_share_client.users.share(
             user="******",
             permission=Permission(URL("storage://bob/resource"), Action.READ),
         )