Skip to content

role

role

DomoRole dataclass

DomoRole(
    auth: DomoAuth,
    id: str,
    raw: dict,
    name: str | None = None,
    description: str | None = None,
    is_system_role: bool | None = None,
    is_default_role: bool | None = None,
    grants: list[Any] = list(),
    membership: list = list(),
)

Bases: DomoEntity

add_user async

add_user(
    auth: DomoAuth,
    user_id: str | None = None,
    user: DomoUser | None = None,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
async def add_user(
    self,
    auth: DomoAuth,
    user_id: str | None = None,
    user: DomoUser | None = None,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=False,
        **context_kwargs,
    )

    if user_id is None:
        if isinstance(user, DomoUser):
            user_id = user.id
        else:
            raise ValueError("must either provide a user_id or user : DomoUser")

    res = await role_routes.role_membership_add_users(
        auth=auth,
        role_id=self.id,
        user_ids=[user_id],
        context=context,
    )

    self.membership.append(user_id)

    return res

create async classmethod

create(
    auth: DomoAuth,
    name: str,
    description,
    grants: list[DomoGrant],
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
@classmethod
async def create(
    cls,
    auth: DomoAuth,
    name: str,
    description,
    grants: list[DomoGrant],
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    return_raw: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = await role_routes.create_role(
        auth=auth,
        name=name,
        description=description,
        context=context,
    )

    if return_raw:
        return res

    domo_role = cls.from_dict(obj=res.response, auth=auth)

    if grants:
        await domo_role.set_grants(grants=grants, context=context)

    return domo_role

delete async

delete(
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
async def delete(
    self,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    return await role_routes.delete_role(
        role_id=self.id,
        auth=self.auth,
        context=context,
    )

get_by_id async classmethod

get_by_id(
    auth: DomoAuth,
    role_id: str,
    session: AsyncClient | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@classmethod
async def get_by_id(
    cls,
    auth: DomoAuth,
    role_id: str,
    session: httpx.AsyncClient | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = await role_routes.get_role_by_id(
        auth=auth,
        role_id=role_id,
        context=context,
    )

    return cls.from_dict(obj=res.response, auth=auth)

get_grants async

get_grants(
    auth: DomoAuth,
    role_id: str | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoGrant]

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
async def get_grants(
    self,
    auth: DomoAuth,
    role_id: str | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoGrant]:
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    res = await role_routes.get_role_grants(
        auth=auth,
        role_id=role_id or self.id,
        context=context,
    )

    self.grants = [DomoGrant(obj) for obj in res.response]

    return self.grants

get_membership async

get_membership(
    role_id=None,
    auth: DomoAuth | None = None,
    return_raw: bool = False,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
async def get_membership(
    self,
    role_id=None,
    auth: DomoAuth | None = None,
    return_raw: bool = False,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    from .. import DomoUser

    auth = auth or self.auth
    role_id = role_id or self.id

    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = await role_routes.get_role_membership(
        auth=auth,
        role_id=role_id,
        context=context,
    )

    if return_raw:
        return res.response

    self.membership = [
        DomoUser.from_dict(obj=obj, auth=auth) for obj in res.response
    ]
    return self.membership

set_as_default_role async

set_as_default_role(
    debug_api: bool = False,
    session: AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
async def set_as_default_role(
    self,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    return await role_routes.set_default_role(
        auth=self.auth,
        role_id=self.id,
        context=context,
    )

set_grants async

set_grants(
    grants: list[DomoGrant],
    role_id: str | None = None,
    is_replace: bool = True,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
async def set_grants(
    self,
    grants: list[DomoGrant],
    role_id: str | None = None,
    is_replace: bool = True,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=False,
        **context_kwargs,
    )

    all_grants = await self.get_grants(
        role_id=role_id or self.id,
        auth=self.auth,
        context=context,
    )

    all_grants_str = [g.id for g in all_grants]

    missing_grants = [g for g in grants if g.id not in all_grants_str]

    if missing_grants:
        raise SetRoleGrants_MissingGrants(
            cls_instance=self, missing_grants=[g.id for g in missing_grants]
        )

    # `is_replace` is forwarded explicitly. It used to reach the route via
    # **context_kwargs, where it was dropped without a warning, so
    # `is_replace=False` silently REPLACED. The route now refuses False
    # rather than doing the opposite of what was asked.
    res = await role_routes.set_role_grants(
        auth=self.auth,
        role_id=role_id or self.id,
        grants=[g.id for g in grants],
        is_replace=is_replace,
        context=context,
    )

    return res  # noqa: RET504

update async

update(
    name=None,
    description: str | None = None,
    grants: list[DomoGrant] | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    return_raw: bool = False,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
async def update(
    self,
    name=None,
    description: str | None = None,
    grants: list["DomoGrant"] | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    return_raw: bool = False,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    name = name or self.name
    description = description or self.description

    res = await role_routes.update_role_metadata(
        role_id=self.id,
        role_name=name,
        role_description=description,
        auth=self.auth,
        context=context,
    )

    self.name = name
    self.description = description

    if grants:
        await self.set_grants(grants=grants, context=context)

    if return_raw:
        return res

    return self

DomoRoles dataclass

DomoRoles(
    auth: DomoAuth,
    default_role: DomoRole | None = None,
    roles: list[DomoRole] | None = None,
)

Bases: DomoManager

get async

get(
    session: AsyncClient | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoRole]

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
async def get(
    self,
    session: httpx.AsyncClient | None = None,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> list[DomoRole]:
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    res = await role_routes.get_roles(
        auth=self.auth,
        context=context,
    )

    self.roles = [
        DomoRole.from_dict(obj=obj, auth=self.auth) for obj in res.response
    ]
    return self.roles

get_default_role async

get_default_role(
    debug_api=False,
    session=None,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoInstanceConfig/role.py
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
async def get_default_role(
    self,
    debug_api=False,
    session=None,
    debug_num_stacks_to_drop=2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop,
        **context_kwargs,
    )

    # First get the default role ID
    res = await role_routes.get_default_role(
        auth=self.auth,
        context=context,
    )

    # res.response is the role ID, now get the full role details
    default_role_id = res.response

    # Get the full role object by ID
    self.default_role = await DomoRole.get_by_id(
        auth=self.auth,
        role_id=default_role_id,
        context=context,
    )

    return self.default_role