credentials
Handle credentials and connection to server for AYON launcher.
Cache and store used server urls. Store/load API keys to/from keyring if needed. Store metadata about used urls, usernames for the urls and when was the connection with the username established.
On bootstrap is created global connection with information about site and AYON launcher version. The connection object lives in 'ayon_api'.
add_server(url, username)
Add server to server info metadata.
This function will also mark the url as last used url on the machine so on next launch will be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url. | required |
username | str | Name of user used to log in. | required |
Source code in common/ayon_common/connection/credentials.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
ask_to_login_ui(url=None, always_on_top=False, username=None, api_key=None, force_username=False)
Ask user to login using UI.
This should be used only when user is not yet logged in at all or available credentials are invalid. To change credentials use 'change_user_ui' function.
Use a subprocess to show UI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | Optional[str] | Server url that could be prefilled in UI. | None |
always_on_top | Optional[bool] | Window will be drawn on top of other windows. | False |
username | Optional[str] | Username that will be prefilled in UI. | None |
api_key | Optional[str] | API token that will be prefilled in UI. | None |
force_username | Optional[bool] | Username will be locked. | False |
Returns:
| Type | Description |
|---|---|
tuple[str, str, str] | tuple[str, str, str]: Url, user's token and username. |
Source code in common/ayon_common/connection/credentials.py
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 312 313 314 315 | |
change_token(url, token, username=None, old_url=None)
Change url and token in currently running session.
Function can also change server url, in that case are previous credentials NOT removed from cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Url to server. | required |
token | str | New token to be used for url connection. | required |
username | Optional[str] | Username of logged user. | None |
old_url | Optional[str] | Previous url. Value from 'get_last_server' is used if not entered. | None |
Source code in common/ayon_common/connection/credentials.py
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 | |
change_user_ui()
Change user using UI.
Show UI to user where he can change credentials or url. Output will contain all information about old/new values of url, username, api key. If user confirmed or declined values.
Returns:
| Name | Type | Description |
|---|---|---|
ChangeUserResult | ChangeUserResult | Information about user change. |
Source code in common/ayon_common/connection/credentials.py
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 | |
confirm_server_login(url, token, username)
Confirm login of user and do necessary stepts to apply changes.
This should not be used on "change" of user but on first login.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url where user authenticated. | required |
token | str | API token used for authentication to server. | required |
username | Union[str, None] | Username related to API token. | required |
Source code in common/ayon_common/connection/credentials.py
550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
connect_and_check_login(username=None)
Create global connection and check if server url or login are needed.
Url and token are validated only once by the global connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username | Optional[str] | Token must belong to user with this username. Ignored if is 'None'. | None |
Returns:
| Type | Description |
|---|---|
tuple[bool, bool] | tuple[bool, bool]: Server url or login are needed. Both are 'False' if url and token are valid. |
Source code in common/ayon_common/connection/credentials.py
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 | |
create_global_connection()
Create global connection with site id and AYON launcher version.
Make sure this function is called once during process runtime.
The global connection in 'ayon_api' have entered site id and AYON launcher version.
Returns:
| Type | Description |
|---|---|
GlobalServerAPI | ayon_api.GlobalServerAPI: Created global connection. |
Source code in common/ayon_common/connection/credentials.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
get_last_server(data=None)
Last server used to log in on this machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | Optional[dict[str, Any]] | Prepared server information data. | None |
Returns:
| Type | Description |
|---|---|
Union[str, None] | Union[str, None]: Last used server url. |
Source code in common/ayon_common/connection/credentials.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
get_last_server_with_username()
Receive last server and username used in last connection.
Returns:
| Type | Description |
|---|---|
| tuple[Union[str, None], Union[str, None]]: Url and username. |
Source code in common/ayon_common/connection/credentials.py
184 185 186 187 188 189 190 191 192 193 194 | |
get_last_username_by_url(url, data=None)
Get last username which was used for passed url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url. | required |
data | Optional[dict[str, Any]] | Servers info. | None |
Returns:
| Type | Description |
|---|---|
Union[str, None] | Union[str, None]: Username. |
Source code in common/ayon_common/connection/credentials.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
get_servers_info_data()
Metadata about used server on this machine.
Store data about all used server urls, last used url and user username for the url. Using this metadata we can remember which username was used per url if token stored in keyring loose lifetime.
Returns:
| Type | Description |
|---|---|
| dict[str, Any]: Information about servers. |
Source code in common/ayon_common/connection/credentials.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
load_environments()
Load environments on startup.
Handle environments needed for connection with server. Environments are 'AYON_SERVER_URL' and 'AYON_API_KEY'.
Server is looked up from environment. Already set environent is not changed. If environemnt is not filled then last server stored in launcher local directory is used.
Token is skipped if url is not available. Otherwise, is also checked from env and if is not available then uses 'load_token' to try to get token based on server url.
Source code in common/ayon_common/connection/credentials.py
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 | |
load_token(url)
Get token for url from keyring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url. | required |
Returns:
| Type | Description |
|---|---|
Union[str, None] | Union[str, None]: Token for passed url available in keyring. |
Source code in common/ayon_common/connection/credentials.py
235 236 237 238 239 240 241 242 243 244 245 | |
logout(url, token)
Logout from server and throw token away.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Url from which should be logged out. | required |
token | str | Token which should be used to log out. | required |
Source code in common/ayon_common/connection/credentials.py
446 447 448 449 450 451 452 453 454 455 456 457 458 | |
remove_server(url)
Remove server url from servers information.
This should be used on logout to completelly loose information about server on the machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url. | required |
Source code in common/ayon_common/connection/credentials.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
remove_token_cache(url, token)
Remove token from local cache of url.
Is skipped if cached token under the passed url is not the same as passed token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Url to server. | required |
token | str | Token to be removed from url cache. | required |
Source code in common/ayon_common/connection/credentials.py
431 432 433 434 435 436 437 438 439 440 441 442 443 | |
remove_url_cache(url)
Clear cache for server url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url which is removed from cache. | required |
Source code in common/ayon_common/connection/credentials.py
421 422 423 424 425 426 427 428 | |
set_environments(url, token)
Change url and token environemnts in currently running process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | New server url. | required |
token | str | User's token. | required |
Source code in common/ayon_common/connection/credentials.py
488 489 490 491 492 493 494 495 496 | |
show_invalid_credentials_ui(message=None, in_subprocess=False, always_on_top=False)
Show UI with information about invalid credentials.
This can be used when AYON launcher is in bypass login mode. In that case 'change_user_ui' cannot be used to change credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_subprocess | bool | Show UI in subprocess. | False |
message | Optional[str] | Message to be shown to user. | None |
always_on_top | Optional[bool] | Window will be drawn on top of other windows. | False |
Source code in common/ayon_common/connection/credentials.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
show_login_ui(url, username, token)
Show login UI and process inputs.
Todos
Add more arguments to function to be able to prefill UI with information, like server is unreachable, url is invalid, token is unauthorized, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | Union[str, None] | Server url that could be prefilled in UI. | required |
username | Union[str, None] | Username that could be prefilled in UI. | required |
token | Union[str, None] | User's token that could be prefilled in UI. | required |
Returns:
| Name | Type | Description |
|---|---|---|
ChangeUserResult | ChangeUserResult | Information about user change. |
Source code in common/ayon_common/connection/credentials.py
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 | |
store_token(url, token)
Store token by url to keyring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Server url. | required |
token | str | User token to server. | required |
Source code in common/ayon_common/connection/credentials.py
248 249 250 251 252 253 254 255 256 | |