Skip to content

core

core

DomoAccount dataclass

DomoAccount(
    auth: DomoAuth,
    id: int,
    raw: dict,
    name: str = None,
    display_name: str = None,
    data_provider_type: str = None,
    created_dt: datetime = None,
    modified_dt: datetime = None,
    owners: list[Any] = None,
    is_admin_summary: bool = True,
    dataset_count: int = None,
    Config: DomoAccount_Config = None,
)

Bases: DomoAccount_Default

A Domo account (the stored credentials a connector or integration uses).

from_dict classmethod

from_dict(
    auth: DomoAuth,
    obj: dict[str, Any],
    is_admin_summary: bool = True,
    is_use_default_class: bool = False,
    new_cls: Any = None,
    **kwargs,
)

converts data_v1_accounts API response into an accounts class object

Source code in src/crew_dcs/classes/DomoAccount/core.py
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
@classmethod
def from_dict(
    cls,
    auth: DomoAuth,
    obj: dict[str, Any],
    is_admin_summary: bool = True,
    is_use_default_class: bool = False,
    new_cls: Any = None,  # Keep for compatibility with parent signature
    **kwargs,
):
    """converts data_v1_accounts API response into an accounts class object"""

    # If new_cls is explicitly provided, use it; otherwise determine from is_use_default_class
    if new_cls is None:
        if is_use_default_class:
            new_cls = cls
        elif obj.get("credentialsType") == "oauth":
            new_cls = DomoAccount_OAuth
        else:
            new_cls = DomoAccountCredential

    return super().from_dict(
        auth=auth,
        obj=obj,
        is_admin_summary=is_admin_summary,
        new_cls=new_cls,
        **kwargs,
    )

DomoAccounts dataclass

DomoAccounts(
    auth: DomoAuth,
    accounts: list[DomoAccount] = None,
    oauths: list[DomoAccount_OAuth] = None,
)

Bases: DomoManager

Manager for listing and searching the accounts and OAuth accounts in an instance.

get_accounts_accountsapi async

get_accounts_accountsapi(
    debug_api: bool = False,
    session: AsyncClient = None,
    return_raw: bool = False,
    is_use_default_account_class: bool = True,
    debug_num_stacks_to_drop: int = 2,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

Calls route

Source code in src/crew_dcs/classes/DomoAccount/core.py
 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
async def get_accounts_accountsapi(
    self,
    debug_api: bool = False,
    session: httpx.AsyncClient = None,
    return_raw: bool = False,
    is_use_default_account_class: bool = True,
    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 - 1,
        **context_kwargs,
    )

    res = await account_routes.get_accounts(
        auth=self.auth,
        context=context,
    )

    if return_raw:
        return res

    if len(res.response) == 0:
        self.accounts = []
        return self.accounts

    self.accounts = await dmce.gather_with_concurrency(
        n=60,
        *[  # noqa: B026
            DomoAccount.get_by_id(
                account_id=obj.get("id"),
                auth=self.auth,
                context=context,
                is_use_default_account_class=is_use_default_account_class,
            )
            for obj in res.response
        ],
    )

    return self.accounts

get_accounts_queryapi async

get_accounts_queryapi(
    additional_filters_ls=None,
    is_use_default_account_class: bool = False,
    return_raw: bool = False,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    session: AsyncClient = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

v2 api for works with group_account_v2 beta

Calls route

Source code in src/crew_dcs/classes/DomoAccount/core.py
126
127
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
async def get_accounts_queryapi(
    self,
    additional_filters_ls=None,
    is_use_default_account_class: bool = False,
    return_raw: bool = False,
    debug_api: bool = False,
    debug_num_stacks_to_drop: int = 2,
    session: httpx.AsyncClient = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """v2 api for works with group_account_v2 beta"""
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        debug_num_stacks_to_drop=debug_num_stacks_to_drop - 1,
        **context_kwargs,
    )

    res = await datacenter_routes.search_datacenter(
        auth=self.auth,
        entity_type=datacenter_routes.Datacenter_Enum.ACCOUNT.value,
        additional_filters_ls=additional_filters_ls,
        context=context,
    )

    if return_raw:
        return res

    if len(res.response) == 0:
        self.accounts = []
        return self.accounts

    self.accounts = [
        DomoAccount.from_dict(
            auth=self.auth,
            obj=account_obj,
            is_use_default_class=is_use_default_account_class,
        )
        for account_obj in res.response
    ]
    return self.accounts

get_oauths async

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

Calls route

Source code in src/crew_dcs/classes/DomoAccount/core.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
async def get_oauths(
    self,
    debug_api: bool = False,
    session: httpx.AsyncClient = None,
    return_raw: 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 account_routes.get_oauth_accounts(
        auth=self.auth,
        context=context,
    )

    if return_raw:
        return res

    self.oauths = [
        DomoAccount_OAuth.from_dict(
            obj=obj, auth=self.auth, is_use_default_account_class=True
        )
        for obj in res.response
    ]

    return self.oauths

search_by_name async

search_by_name(
    account_name: str,
    data_provider_type: str | None = None,
    is_use_default_account_class: bool = True,
    is_suppress_not_found_exception: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> DomoAccount | None

Search for an account by name (matches display_name or name).

Parameters:

Name Type Description Default
account_name str

Account name to search for (case-insensitive)

required
data_provider_type str | None

Optional filter by data provider type

None
is_use_default_account_class bool

Use default account class

True
is_suppress_not_found_exception bool

Return None instead of raising when no account matches

False
context RouteContext | None

Optional RouteContext for API call configuration

None
**context_kwargs

Additional context parameters (session, debug_api, etc.)

{}

Returns:

Type Description
DomoAccount | None

The first matching DomoAccount; None only when no account matches and

DomoAccount | None

is_suppress_not_found_exception is True.

Raises:

Type Description
DomoAccounts_NoAccount

No account matches and is_suppress_not_found_exception is False.

Source code in src/crew_dcs/classes/DomoAccount/core.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
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
305
306
307
308
309
310
311
async def search_by_name(
    self,
    account_name: str,
    data_provider_type: str | None = None,
    is_use_default_account_class: bool = True,
    is_suppress_not_found_exception: bool = False,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> DomoAccount | None:
    """Search for an account by name (matches display_name or name).

    Args:
        account_name: Account name to search for (case-insensitive)
        data_provider_type: Optional filter by data provider type
        is_use_default_account_class: Use default account class
        is_suppress_not_found_exception: Return None instead of raising when
            no account matches
        context: Optional RouteContext for API call configuration
        **context_kwargs: Additional context parameters (session, debug_api, etc.)

    Returns:
        The first matching DomoAccount; None only when no account matches and
        is_suppress_not_found_exception is True.

    Raises:
        DomoAccounts_NoAccount: No account matches and
            is_suppress_not_found_exception is False.
    """
    context = RouteContext.build_context(context=context, **context_kwargs)

    await self.get(
        context=context,
        is_use_default_account_class=is_use_default_account_class,
    )

    for account in self.accounts:
        # Check both name and display_name for matching
        name_match = False
        if (
            account.display_name
            and account.display_name.lower() == account_name.lower()
        ) or (account.name and account.name.lower() == account_name.lower()):
            name_match = True

        if not name_match:
            continue

        # If data_provider_type specified, must match
        if data_provider_type and data_provider_type != account.data_provider_type:
            continue

        return account

    if is_suppress_not_found_exception:
        return None

    raise DomoAccounts_NoAccount(
        cls=self.__class__,
        message=f"No account found with name '{account_name}'",
        domo_instance=self.auth.domo_instance,
    )

upsert_account async classmethod

upsert_account(
    auth: DomoAuth,
    account_id: str | None = None,
    account_name: str | None = None,
    account_config: AccountConfig = None,
    data_provider_type: str | None = None,
    debug_api: bool = False,
    return_raw: bool = False,
    return_search: bool = False,
    is_use_default_account_class: bool = True,
    session: AsyncClient = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
)

search for an account and upsert it

Source code in src/crew_dcs/classes/DomoAccount/core.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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
368
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
@classmethod
async def upsert_account(
    cls,
    auth: DomoAuth,
    account_id: str | None = None,
    account_name: str | None = None,
    account_config: AccountConfig = None,
    data_provider_type: str | None = None,
    debug_api: bool = False,
    return_raw: bool = False,
    return_search: bool = False,
    is_use_default_account_class: bool = True,
    session: httpx.AsyncClient = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
):
    """search for an account and upsert it"""

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

    if not account_name and not account_id:
        raise UpsertAccount_MatchCriteriaError(domo_instance=auth.domo_instance)

    data_provider_type = data_provider_type or (
        account_config and account_config.data_provider_type
    )
    acc = None

    if account_id:
        with contextlib.suppress(dmde.DomoError):
            acc = await DomoAccount.get_by_id(
                auth=auth,
                account_id=account_id,
                context=context,
                is_use_default_account_class=is_use_default_account_class,
            )

    if account_name and not acc:
        try:
            domo_accounts = DomoAccounts(auth=auth)
            acc = await domo_accounts.search_by_name(
                account_name=account_name,
                data_provider_type=data_provider_type,
                is_use_default_account_class=is_use_default_account_class,
                context=context,
            )
        except dmde.DomoError:
            pass

    if return_search:
        return acc

    if not isinstance(
        acc, DomoAccount_Default | DomoAccount | DomoAccountCredential
    ):
        await logger.info(
            f"Creating account {account_name} in {auth.domo_instance}"
        )

        return await DomoAccount.create_account(
            account_name=account_name,
            config=account_config,
            auth=auth,
            context=context,
            return_raw=return_raw,
        )

    if account_name and account_id:
        await logger.info(
            f"Updating account {acc.id} - {acc.display_name or acc.name} in {auth.domo_instance}"
        )

        await acc.update_name(
            account_name=account_name,
            context=context,
            return_raw=return_raw,
        )

    if account_config:  # upsert account
        acc.Config = account_config

        await logger.info(f"Updating config for account {acc.id}")

        await acc.update_config(context=context, return_raw=return_raw)

    return acc