utils.aind_validators¶
ActiveDirectoryUser ¶
Bases: BaseModel
A user record returned by the AIND Active Directory metadata service.
get_aind_rig_name ¶
Return the AIND rig name from the aibs_comp_id environment variable.
Single source of truth for reading the rig identifier from the environment; prefer this
over reading aibs_comp_id directly so the variable name lives in exactly one place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
required
|
bool
|
When True, raise :class: |
False
|
Returns:
| Type | Description |
|---|---|
str | None
|
The rig name, or |
Source code in src/clabe/utils/aind_validators.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
get_active_directory_user ¶
get_active_directory_user(
username: str, timeout: float | None = 2
) -> ActiveDirectoryUser
Fetches a user's record from the AIND Active Directory metadata service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
The username to look up. |
required |
timeout
|
float | None
|
Timeout in seconds for the HTTP request. Defaults to 2. |
2
|
Returns:
| Type | Description |
|---|---|
ActiveDirectoryUser
|
The user's record. |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the request fails or the user is not found. |
ValidationError
|
If the response payload is malformed. |
Example
user = get_active_directory_user("j.doe")
Source code in src/clabe/utils/aind_validators.py
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 | |
validate_username ¶
Validates if the given username exists in the AIND Active Directory.
Queries the AIND metadata service to verify the username exists. Returns None (instead of raising) on network errors or an invalid username so callers can decide how to handle the degraded state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
The username to validate. |
required |
timeout
|
float | None
|
Timeout in seconds for the HTTP request. Defaults to 2. |
2
|
Returns:
| Type | Description |
|---|---|
str | None
|
The canonical username from the Active Directory record (which may differ in |
str | None
|
case from the input), or None if the username is invalid. |
Example
canonical_username = validate_username("j.doe")
is_valid = canonical_username is not None
Source code in src/clabe/utils/aind_validators.py
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 | |
validate_rig_computer_name ¶
validate_rig_computer_name(rig: TRig) -> TRig
Ensures rig and computer name are set from environment variables if available, otherwise defaults to rig configuration values.
Source code in src/clabe/utils/aind_validators.py
113 114 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 | |