build masked credentials for display purpose :param original_credentials: the original credentials :param credential_schema: the credential schema :return:
(original_credentials: Dict, credential_schema: Dict)
| 11 | |
| 12 | |
| 13 | def _build_display_credentials(original_credentials: Dict, credential_schema: Dict) -> Dict: |
| 14 | """ |
| 15 | build masked credentials for display purpose |
| 16 | :param original_credentials: the original credentials |
| 17 | :param credential_schema: the credential schema |
| 18 | :return: |
| 19 | """ |
| 20 | |
| 21 | display_credentials = {} |
| 22 | |
| 23 | for key, value in original_credentials.items(): |
| 24 | # check if the key is in the schema |
| 25 | if key in credential_schema["properties"]: |
| 26 | if credential_schema["properties"][key].get("secret"): |
| 27 | # mask the secret value |
| 28 | value_length = len(value) |
| 29 | |
| 30 | if value_length <= 8: |
| 31 | # if the value length is less than 8, just mask the whole value |
| 32 | masked_value = "*" * value_length |
| 33 | else: |
| 34 | masked_value = value[:2] + "*" * min(10, value_length - 4) + value[-2:] |
| 35 | |
| 36 | display_credentials[key] = masked_value |
| 37 | else: |
| 38 | # the value is not secret, so just keep the original value |
| 39 | display_credentials[key] = value |
| 40 | |
| 41 | return display_credentials |
| 42 | |
| 43 | |
| 44 | async def verify_model_credentials( |
no test coverage detected