Skip to content

account_credential

account_credential

DomoAccountCredential dataclass

DomoAccountCredential(
    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,
    target_auth: DomoAuth = None,
    target_user: DomoUser = None,
    target_access_token: DomoAccessToken = None,
    target_instance: str = None,
    is_valid_full_auth: bool = None,
    is_valid_token_auth: bool = None,
    _token_auth: DomoAuth = None,
    _full_auth: DomoAuth = None,
)

Bases: DomoAccount_Default

Account credential management class for Domo accounts.

This class extends DomoAccount_Default to provide credential management capabilities including authentication testing, password management, and access token operations.

Attributes:

Name Type Description
target_instance str

Target Domo instance for credential operations

is_valid_full_auth bool

Whether full authentication is valid

is_valid_token_auth bool

Whether token authentication is valid

target_auth DomoAuth

Active authentication object for target instance

target_user DomoUser

DomoUser object for the target user

target_access_token DomoAccessToken

Access token for the account

from_dict classmethod

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

Create Account_Credential from dictionary representation.

Parameters:

Name Type Description Default
obj dict[str, Any]

Dictionary containing account data

required
is_admin_summary bool

Whether this is an admin summary view

True
auth DomoAuth | None

Authentication object

None
**kwargs

Additional keyword arguments including target_instance

{}

Returns:

Type Description

DomoAccount_Credential instance

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@classmethod
def from_dict(
    cls,
    obj: dict[str, Any],
    is_admin_summary: bool = True,
    auth: DomoAuth | None = None,
    is_use_default_account_class: bool = False,
    **kwargs,
):
    """Create Account_Credential from dictionary representation.

    Args:
        obj: Dictionary containing account data
        is_admin_summary: Whether this is an admin summary view
        auth: Authentication object
        **kwargs: Additional keyword arguments including target_instance

    Returns:
        DomoAccount_Credential instance
    """
    # Note: is_use_default_account_class is consumed here and not passed to parent
    # to avoid TypeError when passed to dataclass __init__
    return super().from_dict(
        obj=obj,
        is_admin_summary=is_admin_summary,
        auth=auth,
        new_cls=cls,
        target_instance=kwargs.get("target_instance"),
    )

get_target_access_token async

get_target_access_token(
    token_name: str | None = None,
    user_email: str | None = None,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> DomoAccessToken

Retrieve an access token for the target user.

Parameters:

Name Type Description Default
token_name str | None

Name of the access token (defaults to account name)

None
user_email str | None

Email address of user (defaults to configured username)

None
target_auth DomoAuth | None

Authentication object (defaults to self.target_auth)

None
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None
context RouteContext | None

Optional RouteContext for API call configuration

None
**context_kwargs

Additional context parameters

{}

Returns:

Type Description
DomoAccessToken

DomoAccessToken object if found, None otherwise

Raises:

Type Description
DACValidAuthError

If target authentication is not available

DAC_NoAccessTokenName

If token name is not provided or available

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
async def get_target_access_token(
    self,
    token_name: str | None = None,
    user_email: str | None = None,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> DomoAccessToken:
    """Retrieve an access token for the target user.

    Args:
        token_name: Name of the access token (defaults to account name)
        user_email: Email address of user (defaults to configured username)
        target_auth: Authentication object (defaults to self.target_auth)
        debug_api: Enable API debugging
        session: HTTP client session (optional)
        context: Optional RouteContext for API call configuration
        **context_kwargs: Additional context parameters

    Returns:
        DomoAccessToken object if found, None otherwise

    Raises:
        DACValidAuthError: If target authentication is not available
        DAC_NoAccessTokenName: If token name is not provided or available
    """
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    target_auth = target_auth or self.target_auth

    if not target_auth:
        raise DACValidAuthError(
            self,
            message="no target_auth, pass a valid backup_auth",
        )

    if not self.target_user:
        await self.get_target_user(
            context=context,
            user_email=user_email,
            target_auth=target_auth,
        )

    token_name = token_name or self.name

    if not token_name:
        raise DACNoAccessTokenNameError(self)

    domo_access_tokens = await self.target_user.get_access_tokens(
        context=context,
    )

    self.target_access_token = next(
        (
            dat
            for dat in domo_access_tokens
            if dat and (dat.name and dat.name.lower() == token_name.lower())
        ),
        None,
    )

    if not self.target_access_token:
        raise DACNoAccessTokenNameError(self)

    return self.target_access_token

get_target_user async

get_target_user(
    user_email: str | None = None,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> DomoUser

Retrieve the target user for this account.

Parameters:

Name Type Description Default
user_email str | None

Email address of user (defaults to configured username)

None
target_auth DomoAuth | None

Authentication object (defaults to self.target_auth)

None
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None
context RouteContext | None

Optional RouteContext for API call configuration

None

Returns:

Type Description
DomoUser

DomoUser object for the target user

Raises:

Type Description
DAC_NoUserName

If user email is not provided or configured

DACValidAuthError

If target authentication is not available

DAC_NoTargetUser

If user cannot be found

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
async def get_target_user(
    self,
    user_email: str | None = None,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> DomoUser:
    """Retrieve the target user for this account.

    Args:
        user_email: Email address of user (defaults to configured username)
        target_auth: Authentication object (defaults to self.target_auth)
        debug_api: Enable API debugging
        session: HTTP client session (optional)
        context: Optional RouteContext for API call configuration

    Returns:
        DomoUser object for the target user

    Raises:
        DAC_NoUserName: If user email is not provided or configured
        DACValidAuthError: If target authentication is not available
        DAC_NoTargetUser: If user cannot be found
    """
    user_email = user_email or self.Config.username

    if not user_email:
        raise DACNoUserNameError(self)

    target_auth = target_auth or self.target_auth

    if not target_auth:
        raise DACValidAuthError(
            self,
            message="no target_auth, pass a valid backup_auth",
        )

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

    self.target_user = await DomoUsers(auth=target_auth).search_by_email(
        email=[user_email],
        context=context,
    )

    if not self.target_user:
        raise DACNoTargetUserError(self)

    return self.target_user

regenerate_target_access_token async

regenerate_target_access_token(
    token_name: str | None = None,
    duration_in_days: int = 90,
    user_email: str | None = None,
    is_update_account: bool = True,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> DomoAccountCredential

Regenerate or create an access token for the target user.

If a token with the given name exists, it will be regenerated. Otherwise, a new token will be created.

Parameters:

Name Type Description Default
token_name str | None

Name of the access token (defaults to account name)

None
duration_in_days int

Token validity duration in days (default: 90)

90
user_email str | None

Email address of user (defaults to configured username)

None
is_update_account bool

Whether to update the account config with new token

True
target_auth DomoAuth | None

Authentication object (defaults to self.target_auth)

None
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None
context RouteContext | None

Optional RouteContext for API call configuration

None
**context_kwargs

Additional context parameters

{}

Returns:

Type Description
DomoAccountCredential

Self for method chaining

Raises:

Type Description
DACValidAuthError

If target authentication is not available

DAC_NoTargetUser

If target user cannot be retrieved

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
async def regenerate_target_access_token(
    self,
    token_name: str | None = None,
    duration_in_days: int = 90,
    user_email: str | None = None,
    is_update_account: bool = True,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> "DomoAccountCredential":
    """Regenerate or create an access token for the target user.

    If a token with the given name exists, it will be regenerated. Otherwise,
    a new token will be created.

    Args:
        token_name: Name of the access token (defaults to account name)
        duration_in_days: Token validity duration in days (default: 90)
        user_email: Email address of user (defaults to configured username)
        is_update_account: Whether to update the account config with new token
        target_auth: Authentication object (defaults to self.target_auth)
        debug_api: Enable API debugging
        session: HTTP client session (optional)
        context: Optional RouteContext for API call configuration
        **context_kwargs: Additional context parameters

    Returns:
        Self for method chaining

    Raises:
        DACValidAuthError: If target authentication is not available
        DAC_NoTargetUser: If target user cannot be retrieved
    """
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    target_auth = target_auth or self.target_auth

    if not target_auth:
        raise DACValidAuthError(
            self,
            message="no target_auth, pass a valid backup_auth",
        )

    domo_access_token = await self.get_target_access_token(
        token_name=token_name,
        user_email=user_email,
        target_auth=target_auth,
        context=context,
    )  # handles retrieving target user

    if not self.target_user:
        raise DACNoTargetUserError(self)

    if domo_access_token:
        await domo_access_token.regenerate(
            duration_in_days=duration_in_days, context=context
        )

    else:
        domo_access_token = await DomoAccessToken.generate(
            duration_in_days=duration_in_days,
            token_name=token_name,
            auth=target_auth,
            owner=self.target_user,
            context=context,
        )

        self.target_access_token = domo_access_token

    self.set_access_token(domo_access_token.token)

    if is_update_account:
        await self.update_config(context=context)

    return self

set_access_token

set_access_token(access_token: str) -> bool

Set the access token in the account configuration.

Parameters:

Name Type Description Default
access_token str

New access token to set

required

Returns:

Type Description
bool

True if successful

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
169
170
171
172
173
174
175
176
177
178
179
def set_access_token(self, access_token: str) -> bool:
    """Set the access token in the account configuration.

    Args:
        access_token: New access token to set

    Returns:
        True if successful
    """
    self.Config.domo_access_token = access_token
    return True

set_password

set_password(password: str) -> bool

Set the password in the account configuration.

Parameters:

Name Type Description Default
password str

New password to set

required

Returns:

Type Description
bool

True if successful

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
145
146
147
148
149
150
151
152
153
154
155
def set_password(self, password: str) -> bool:
    """Set the password in the account configuration.

    Args:
        password: New password to set

    Returns:
        True if successful
    """
    self.Config.password = password
    return True

set_username

set_username(username: str) -> bool

Set the username in the account configuration.

Parameters:

Name Type Description Default
username str

New username to set

required

Returns:

Type Description
bool

True if successful

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
157
158
159
160
161
162
163
164
165
166
167
def set_username(self, username: str) -> bool:
    """Set the username in the account configuration.

    Args:
        username: New username to set

    Returns:
        True if successful
    """
    self.Config.username = username
    return True

test_auths async

test_auths(
    backup_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
) -> dict

Test both token and full authentication methods.

Attempts to validate both authentication methods and sets the best available as the target authentication.

Parameters:

Name Type Description Default
backup_auth DomoAuth | None

Backup authentication to use if configured auths fail

None
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None

Returns:

Type Description
dict

Dictionary with authentication test results

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
307
308
309
310
311
312
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
async def test_auths(
    self,
    backup_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
) -> dict:
    """Test both token and full authentication methods.

    Attempts to validate both authentication methods and sets the best available
    as the target authentication.

    Args:
        backup_auth: Backup authentication to use if configured auths fail
        debug_api: Enable API debugging
        session: HTTP client session (optional)

    Returns:
        Dictionary with authentication test results
    """
    ## test token auth
    try:
        await self.test_token_auth(debug_api=debug_api, session=session)

    except DomoError as e:
        print(f"testing token: {self.name}: {e}")

    ## test full auth
    try:
        await self.test_full_auth(debug_api=debug_api, session=session)

    except DomoError as e:
        print(f"testing full auth: {self.name}: {e}")

    ## generate target_auth
    try:
        self._set_target_auth(valid_backup_auth=backup_auth)
    except DACValidAuthError as e:
        print(f"{self.name}: unable to generate valid target_auth: {e}")
    return self.to_dict()

test_full_auth async

test_full_auth(
    debug_api: bool = False,
    session: AsyncClient | None = None,
) -> bool

Test full authentication (username/password) for the account.

Generates a DomoFullAuth object and validates it against the target instance.

Parameters:

Name Type Description Default
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None

Returns:

Type Description
bool

True if authentication is valid, False otherwise

Raises:

Type Description
DAC_NoUserName

If username is not configured

DAC_NoPassword

If password is not configured

DAC_NoTargetInstance

If target instance is not set

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
225
226
async def test_full_auth(
    self, debug_api: bool = False, session: httpx.AsyncClient | None = None
) -> bool:
    """Test full authentication (username/password) for the account.

    Generates a DomoFullAuth object and validates it against the target instance.

    Args:
        debug_api: Enable API debugging
        session: HTTP client session (optional)

    Returns:
        True if authentication is valid, False otherwise

    Raises:
        DAC_NoUserName: If username is not configured
        DAC_NoPassword: If password is not configured
        DAC_NoTargetInstance: If target instance is not set
    """
    self.is_valid_full_auth = False

    if not self.Config.username:
        raise DACNoUserNameError(self)

    if not self.Config.password:
        raise DACNoPasswordError(self)

    if not self.target_instance:
        raise DACNoTargetInstanceError(self)

    self._full_auth = DomoFullAuth(
        domo_instance=self.target_instance,
        domo_username=self.Config.username,
        domo_password=self.Config.password,
    )

    try:
        await self._full_auth.print_is_token(debug_api=debug_api, session=session)
        self.is_valid_full_auth = True

    except AuthError as e:
        dmcv.print_md(f"🤯 test_full_auth for: ***{self.name}*** returned {e}")

        self.is_valid_full_auth = False

    return self.is_valid_full_auth

test_token_auth async

test_token_auth(
    debug_api: bool = False,
    session: AsyncClient | None = None,
) -> bool

Test token authentication for the account.

Generates a DomoTokenAuth object and validates it against the target instance.

Parameters:

Name Type Description Default
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None

Returns:

Type Description
bool

True if authentication is valid, False otherwise

Raises:

Type Description
DAC_NoAccessToken

If access token is not configured

DAC_NoTargetInstance

If target instance is not set

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
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
async def test_token_auth(
    self, debug_api: bool = False, session: httpx.AsyncClient | None = None
) -> bool:
    """Test token authentication for the account.

    Generates a DomoTokenAuth object and validates it against the target instance.

    Args:
        debug_api: Enable API debugging
        session: HTTP client session (optional)

    Returns:
        True if authentication is valid, False otherwise

    Raises:
        DAC_NoAccessToken: If access token is not configured
        DAC_NoTargetInstance: If target instance is not set
    """

    self.is_valid_token_auth = False

    if not self.Config.domo_access_token:
        raise DACNoAccessTokenError(self)

    if not self.target_instance:
        raise DACNoTargetInstanceError(self)

    self._token_auth = DomoTokenAuth(
        domo_instance=self.target_instance,
        domo_access_token=self.Config.domo_access_token,
    )

    try:
        await self._token_auth.print_is_token(debug_api=debug_api, session=session)
        self.is_valid_token_auth = True
        self.target_auth = self._token_auth

    except AuthError as e:
        dmcv.print_md(f"🤯 test_token_auth for: ***{self.name}*** returned {e}")
        self.is_valid_token_auth = False

    return self.is_valid_token_auth

to_dict

to_dict(return_snake_case: bool = False) -> dict

Convert credential information to dictionary.

Returns:

Type Description
dict

Dictionary containing account ID, alias, instance, and auth validity status

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
def to_dict(self, return_snake_case: bool = False) -> dict:
    """Convert credential information to dictionary.

    Returns:
        Dictionary containing account ID, alias, instance, and auth validity status
    """

    s = super().to_dict(return_snake_case=return_snake_case)
    s.update(
        {
            "account_id": self.id,
            "alias": self.name,
            "target_instance": self.target_instance,
            "is_valid_full_auth": self.is_valid_full_auth,
            "is_valid_token_auth": self.is_valid_token_auth,
        }
    )
    return s

update_target_user_password async

update_target_user_password(
    new_password: str,
    user_email: str | None = None,
    is_update_account: bool = True,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs
) -> DomoAccountCredential

Update the password for the target user.

Parameters:

Name Type Description Default
new_password str

New password to set for the user

required
user_email str | None

Email address of user (defaults to configured username)

None
is_update_account bool

Whether to update the account config with new password

True
target_auth DomoAuth | None

Authentication object (defaults to self.target_auth)

None
debug_api bool

Enable API debugging

False
session AsyncClient | None

HTTP client session (optional)

None
context RouteContext | None

Optional RouteContext for API call configuration

None
**context_kwargs

Additional context parameters

{}

Returns:

Type Description
DomoAccountCredential

Self for method chaining

Raises:

Type Description
DACValidAuthError

If target authentication is not available

Source code in src/crew_dcs/classes/DomoAccount/account_credential.py
423
424
425
426
427
428
429
430
431
432
433
434
435
436
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
async def update_target_user_password(
    self,
    new_password: str,
    user_email: str | None = None,
    is_update_account: bool = True,
    target_auth: DomoAuth | None = None,
    debug_api: bool = False,
    session: httpx.AsyncClient | None = None,
    *,
    context: RouteContext | None = None,
    **context_kwargs,
) -> "DomoAccountCredential":
    """Update the password for the target user.

    Args:
        new_password: New password to set for the user
        user_email: Email address of user (defaults to configured username)
        is_update_account: Whether to update the account config with new password
        target_auth: Authentication object (defaults to self.target_auth)
        debug_api: Enable API debugging
        session: HTTP client session (optional)
        context: Optional RouteContext for API call configuration
        **context_kwargs: Additional context parameters

    Returns:
        Self for method chaining

    Raises:
        DACValidAuthError: If target authentication is not available
    """
    context = RouteContext.build_context(
        context=context,
        session=session,
        debug_api=debug_api,
        **context_kwargs,
    )

    target_auth = target_auth or self.target_auth

    if not target_auth:
        raise DACValidAuthError(
            self,
            message="no target_auth, pass a valid backup_auth",
        )

    if not self.target_user:
        await self.get_target_user(
            context=context,
            user_email=user_email,
            target_auth=target_auth,
            **context_kwargs,
        )

    await self.target_user.reset_password(
        new_password=new_password,
        context=context,
        **context_kwargs,
    )

    self.set_password(new_password)

    if is_update_account:
        await self.update_config(context=context, **context_kwargs)

    return self