Beispiel #1
0
    def load(self, conjur_url: str) -> CredentialsData:
        """
        Method for fetching user credentials from the system's keyring
        """
        loaded_credentials = {}
        if not self.is_exists(conjur_url):
            raise CredentialRetrievalException

        for attr in KEYSTORE_ATTRIBUTES:
            loaded_credentials[attr] = KeystoreWrapper.get_password(
                conjur_url, attr)
        return CredentialsData.convert_dict_to_obj(loaded_credentials)
Beispiel #2
0
 def cleanup_if_exists(self, conjur_url: str):
     """
     For each credential attribute, check if exists for
     the conjur_url identifier and delete if exists
     """
     for attr in KEYSTORE_ATTRIBUTES:
         try:
             if KeystoreWrapper.get_password(conjur_url, attr) is not None:
                 KeystoreWrapper.delete_password(conjur_url, attr)
         # Catches when credentials do not exist in the keyring. If the key does not exist,
         # the user has already logged out. we still try to remove other leftovers
         except Exception:  # pylint: disable=broad-except
             logging.debug(f"Cleanup failed for key '{attr}' from the "
                           f"'{self.keyring_name} credential store.' "
                           f"\n{traceback.format_exc()}")
Beispiel #3
0
 def is_exists(self, conjur_url) -> bool:
     for attr in KEYSTORE_ATTRIBUTES:
         if KeystoreWrapper.get_password(conjur_url, attr) is None:
             return False
     return True
 def test_get_password_use_proper_log_level(self, mock):
     logging.getLogger('keyring').setLevel(logging.DEBUG)
     KeystoreWrapper.get_password("", "")
     self.assertEquals(logging.getLogger('keyring').level, logging.INFO)