예제 #1
0
    def __init__(self):
        LOG.debug("Loading clientside session config.")

        # Check whether user's configuration exists.
        user_home = os.path.expanduser("~")
        session_cfg_file = os.path.join(user_home,
                                        ".codechecker.passwords.json")
        LOG.info("Checking local passwords or tokens in %s", session_cfg_file)

        scfg_dict = {}

        mistyped_cfg_file = os.path.join(user_home,
                                         ".codechecker.password.json")

        if os.path.exists(session_cfg_file):
            check_file_owner_rw(session_cfg_file)
            scfg_dict = load_json_or_empty(session_cfg_file, {},
                                           "user authentication")
            scfg_dict['credentials'] = \
                simplify_credentials(scfg_dict['credentials'])
            if not scfg_dict['credentials']:
                LOG.info("No saved tokens.")
            else:
                LOG.debug("Tokens or passwords were found for these hosts:")
                for k, v in scfg_dict['credentials'].items():
                    user, _ = v.split(":")
                    LOG.debug("  user '%s' host '%s'", user, k)
        elif os.path.exists(mistyped_cfg_file):
            LOG.warning("Typo in file name! Rename '%s' to '%s'.",
                        mistyped_cfg_file, session_cfg_file)
        else:
            LOG.info("Password file not found.")

        if not scfg_dict.get('credentials'):
            scfg_dict['credentials'] = {}

        self.__save = scfg_dict
        self.__autologin = scfg_dict.get('client_autologin', True)
        # Check and load token storage for user.
        self.token_file = os.path.join(user_home, ".codechecker.session.json")
        LOG.info("Checking for local valid sessions.")

        if os.path.exists(self.token_file):
            token_dict = load_json_or_empty(self.token_file, {},
                                            "user authentication")
            check_file_owner_rw(self.token_file)

            self.__tokens = token_dict.get('tokens')
            LOG.debug("Found session information for these hosts:")
            for k, _ in self.__tokens.items():
                LOG.debug("  %s", k)
        else:
            with open(self.token_file, 'w', encoding="utf-8",
                      errors="ignore") as f:
                json.dump({'tokens': {}}, f)
            os.chmod(self.token_file, stat.S_IRUSR | stat.S_IWUSR)

            self.__tokens = {}
예제 #2
0
 def __get_config_dict(self):
     """
     Get server config information from the configuration file. Raise
     ValueError if the configuration file is invalid.
     """
     LOG.debug(self.__configuration_file)
     cfg_dict = load_json_or_empty(self.__configuration_file, {},
                                   'server configuration')
     if cfg_dict != {}:
         check_file_owner_rw(self.__configuration_file)
     else:
         # If the configuration dict is empty, it means a JSON couldn't
         # have been parsed from it.
         raise ValueError("Server configuration file was invalid, or "
                          "empty.")
     return cfg_dict
예제 #3
0
    def __init__(self):
        LOG.debug("Loading clientside session config.")

        # Check whether user's configuration exists.
        user_home = os.path.expanduser("~")
        session_cfg_file = os.path.join(user_home,
                                        ".codechecker.passwords.json")
        LOG.debug(session_cfg_file)

        scfg_dict = {}
        if os.path.exists(session_cfg_file):
            scfg_dict = load_json_or_empty(session_cfg_file, {},
                                           "user authentication")
            scfg_dict['credentials'] = \
                simplify_credentials(scfg_dict['credentials'])

            check_file_owner_rw(session_cfg_file)
        else:
            misstyped_cfg_file = os.path.join(user_home,
                                              ".codechecker.password.json")
            if os.path.exists(misstyped_cfg_file):
                LOG.warning("Typo in file name! Rename '%s' to '%s'.",
                            misstyped_cfg_file, session_cfg_file)

        if not scfg_dict.get('credentials'):
            scfg_dict['credentials'] = {}

        self.__save = scfg_dict
        self.__autologin = scfg_dict.get('client_autologin', True)

        # Check and load token storage for user.
        self.token_file = os.path.join(user_home, ".codechecker.session.json")
        LOG.debug(self.token_file)

        if os.path.exists(self.token_file):
            token_dict = load_json_or_empty(self.token_file, {},
                                            "user authentication")
            check_file_owner_rw(self.token_file)

            self.__tokens = token_dict.get('tokens')
        else:
            with open(self.token_file, 'w') as f:
                json.dump({'tokens': {}}, f)
            os.chmod(self.token_file, stat.S_IRUSR | stat.S_IWUSR)

            self.__tokens = {}