(
            self, file_path: Optional[Text] = '',
            section: Optional[Text] = 'timesketch',
            token_file_path: Optional[Text] = '')
Save the current config to a file.

        Args:
            file_path (str): A full path to the location where the
                configuration file is to be stored. If not provided the
                default location will be used.
            section (str): The configuration section to write to. This
                is optional and defaults to timesketch. This can be
                useful if you have multiple Timesketch servers to connect to,
                with each one of them having a separate section in the config
                file.
            token_file_path (str): Optional path to the location of the token
                file.
Save the current config to a file.
Save the current config to a file .
def save_config(
            self, file_path: Optional[Text] = '',
            section: Optional[Text] = 'timesketch',
            token_file_path: Optional[Text] = ''):
        """Save the current config to a file.

        Args:
            file_path (str): A full path to the location where the
                configuration file is to be stored. If not provided the
                default location will be used.
            section (str): The configuration section to write to. This
                is optional and defaults to timesketch. This can be
                useful if you have multiple Timesketch servers to connect to,
                with each one of them having a separate section in the config
                file.
            token_file_path (str): Optional path to the location of the token
                file.
        """
        if not file_path:
            home_path = os.path.expanduser('~')
            file_path = os.path.join(home_path, self.RC_FILENAME)

        config = configparser.ConfigParser()

        if not os.path.isfile(file_path):
            fw = open(file_path, 'a')
            fw.close()

        # Read in other sections in the config file as well.
        try:
            _ = config.read([file_path])
        except configparser.MissingSectionHeaderError:
            pass

        # TODO: Remove this, temporary here to transition from the use of
        # timesketch to the auth mode of userpass.
        auth_mode = self._config.get('auth_mode', 'userpass')
        if auth_mode == 'timesketch':
            auth_mode = 'userpass'

        if not section:
            section = 'timesketch'

        config[section] = {
            'host_uri': self._config.get('host_uri'),
            'username': self._config.get('username'),
            'verify': self._config.get('verify', True),
            'client_id': self._config.get('client_id', ''),
            'client_secret': self._config.get('client_secret', ''),
            'auth_mode': auth_mode,
        }
        config['cli'] = {
            'sketch': self._config.get('sketch', ''),
            'output_format': self._config.get('output_format', 'tabular')
        }
        if token_file_path:
            config[section]['token_file_path'] = token_file_path

        if 'cred_key' in self._config:
            cred_key = self._config.get('cred_key')
            if isinstance(cred_key, bytes):
                cred_key = cred_key.decode('utf-8')
            config[section]['cred_key'] = cred_key

        with open(file_path, 'w') as fw:
            config.write(fw)
def save_config ( self , file_path : Optional [ Text ] = '' , section : Optional [ Text ] = 'timesketch' , token_file_path : Optional [ Text ] = '' ) : if not file_path : home_path = os . path . expanduser ( '~' ) file_path = os . path . join ( home_path , self . RC_FILENAME ) config = configparser . ConfigParser ( ) if not os . path . isfile ( file_path ) : fw = open ( file_path , 'a' ) fw . close ( ) # Read in other sections in the config file as well. try : _ = config . read ( [ file_path ] ) except configparser . MissingSectionHeaderError : pass # TODO: Remove this, temporary here to transition from the use of # timesketch to the auth mode of userpass. auth_mode = self . _config . get ( 'auth_mode' , 'userpass' ) if auth_mode == 'timesketch' : auth_mode = 'userpass' if not section : section = 'timesketch' config [ section ] = { 'host_uri' : self . _config . get ( 'host_uri' ) , 'username' : self . _config . get ( 'username' ) , 'verify' : self . _config . get ( 'verify' , True ) , 'client_id' : self . _config . get ( 'client_id' , '' ) , 'client_secret' : self . _config . get ( 'client_secret' , '' ) , 'auth_mode' : auth_mode , } config [ 'cli' ] = { 'sketch' : self . _config . get ( 'sketch' , '' ) , 'output_format' : self . _config . get ( 'output_format' , 'tabular' ) } if token_file_path : config [ section ] [ 'token_file_path' ] = token_file_path if 'cred_key' in self . _config : cred_key = self . _config . get ( 'cred_key' ) if isinstance ( cred_key , bytes ) : cred_key = cred_key . decode ( 'utf-8' ) config [ section ] [ 'cred_key' ] = cred_key with open ( file_path , 'w' ) as fw : config . write ( fw )