File: __init__.py

package info (click to toggle)
python-bioblend 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: python: 7,596; sh: 219; makefile: 158
file content (108 lines) | stat: -rw-r--r-- 3,027 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
Contains possible interactions with the Galaxy Roles
"""
from typing import (
    Any,
    Dict,
    List,
    Optional,
    TYPE_CHECKING,
)

from bioblend.galaxy.client import Client

if TYPE_CHECKING:
    from bioblend.galaxy import GalaxyInstance


class RolesClient(Client):
    module = "roles"

    def __init__(self, galaxy_instance: "GalaxyInstance") -> None:
        super().__init__(galaxy_instance)

    def get_roles(self) -> List[Dict[str, Any]]:
        """
        Displays a collection (list) of roles.

        :rtype: list
        :return: A list of dicts with details on individual roles.
          For example::

            [{"id": "f2db41e1fa331b3e",
              "model_class": "Role",
              "name": "Foo",
              "url": "/api/roles/f2db41e1fa331b3e"},
             {"id": "f597429621d6eb2b",
              "model_class": "Role",
              "name": "Bar",
              "url": "/api/roles/f597429621d6eb2b"}]
        """
        return self._get()

    def show_role(self, role_id: str) -> Dict[str, Any]:
        """
        Display information on a single role

        :type role_id: str
        :param role_id: Encoded role ID

        :rtype: dict
        :return: Details of the given role.
          For example::

            {"description": "Private Role for Foo",
             "id": "f2db41e1fa331b3e",
             "model_class": "Role",
             "name": "Foo",
             "type": "private",
             "url": "/api/roles/f2db41e1fa331b3e"}
        """
        return self._get(id=role_id)

    def create_role(
        self,
        role_name: str,
        description: str,
        user_ids: Optional[List[str]] = None,
        group_ids: Optional[List[str]] = None,
    ) -> Dict[str, Any]:
        """
        Create a new role.

        :type role_name: str
        :param role_name: A name for the new role

        :type description: str
        :param description: Description for the new role

        :type user_ids: list
        :param user_ids: A list of encoded user IDs to add to the new role

        :type group_ids: list
        :param group_ids: A list of encoded group IDs to add to the new role

        :rtype: dict
        :return: Details of the newly created role.
          For example::

            {'description': 'desc',
             'url': '/api/roles/ebfb8f50c6abde6d',
             'model_class': 'Role',
             'type': 'admin',
             'id': 'ebfb8f50c6abde6d',
             'name': 'Foo'}

        .. versionchanged:: 0.15.0
            Changed the return value from a 1-element list to a dict.
        """
        if user_ids is None:
            user_ids = []
        if group_ids is None:
            group_ids = []
        payload = {"name": role_name, "description": description, "user_ids": user_ids, "group_ids": group_ids}
        ret = self._post(payload)
        if isinstance(ret, list):
            # Galaxy release_20.09 and earlier returned a 1-element list
            ret = ret[0]
        return ret