コード例 #1
0
def _set_access_token(username: str, access_token: str,
                      connect_string: str) -> Optional[str]:
    """
    Sets the access_token for the connect request by doing the following:

    1. retrieves the token configured for the connect_string from the 
       .arkouda/tokens.txt file, if any
    2. if access_token is None, returns the retrieved token
    3. if access_token is not None, replaces retrieved token with the access_token
       to account for situations where the token can change for a url (for example,
       the arkouda_server is restarted and a corresponding new token is generated).

    :param str username: the username retrieved from the user's home directory
    :param str access_token: the access_token supplied by the user, defaults to None
    :param str connect_string: the arkouda_server host:port connect string
    :return: the retrieved or supplied access_token, defaults to None
    """
    path = '{}/tokens.txt'.format(security.get_arkouda_client_directory())
    tokens = io_util.delimited_file_to_dict(path)

    if access_token and access_token not in {'', 'None'}:
        saved_token = tokens.get(connect_string)
        if saved_token is None or saved_token != access_token:
            tokens[connect_string] = access_token
            io_util.dict_to_delimited_file(values=tokens,
                                           path=path,
                                           delimiter=',')
        return access_token
    else:
        tokens = io_util.delimited_file_to_dict(path)
        return tokens.get(connect_string)
コード例 #2
0
ファイル: security_test.py プロジェクト: mcdobe100/arkouda
 def testGetArkoudaDirectory(self):
     security_test_dir = '{}/arkouda_test'.format(os.getcwd())
     os.environ['ARKOUDA_CLIENT_DIRECTORY'] = str(security_test_dir)
     ak_directory = security.get_arkouda_client_directory()
     self.assertEquals('{}/.arkouda'.format(security_test_dir),
                       str(ak_directory))
     shutil.rmtree(security_test_dir)
コード例 #3
0
def _set_access_token(access_token: Optional[str],
                      connect_string: str = 'localhost:5555') -> Optional[str]:
    """
    Sets the access_token for the connect request by doing the following:

    1. retrieves the token configured for the connect_string from the 
       .arkouda/tokens.txt file, if any
    2. if access_token is None, returns the retrieved token
    3. if access_token is not None, replaces retrieved token with the access_token
       to account for situations where the token can change for a url (for example,
       the arkouda_server is restarted and a corresponding new token is generated).

    Parameters
    ----------
    username : str
        The username retrieved from the user's home directory    
    access_token : str
        The access_token supplied by the user, which is required if authentication
        is enabled, defaults to None
    connect_string : str
        The arkouda_server host:port connect string, defaults to localhost:5555
    
    Returns
    -------
    str
        The access token configured for the host:port, None if there is no
        token configured for the host:port
    
    Raises
    ------
    IOError
        If there's an error writing host:port -> access_token mapping to
        the user's tokens.txt file or retrieving the user's tokens
    """
    path = '{}/tokens.txt'.format(security.get_arkouda_client_directory())
    try:
        tokens = io_util.delimited_file_to_dict(path)
    except Exception as e:
        raise IOError(e)

    if cast(str, access_token) and cast(str, access_token) not in {'', 'None'}:
        saved_token = tokens.get(connect_string)
        if saved_token is None or saved_token != access_token:
            tokens[connect_string] = cast(str, access_token)
            try:
                io_util.dict_to_delimited_file(values=tokens,
                                               path=path,
                                               delimiter=',')
            except Exception as e:
                raise IOError(e)
        return access_token
    else:
        try:
            tokens = io_util.delimited_file_to_dict(path)
        except Exception as e:
            raise IOError(e)
        return tokens.get(connect_string)
コード例 #4
0
 def testGetArkoudaDirectory(self):
     ak_directory = security.get_arkouda_client_directory()
     self.assertEqual('{}/.arkouda'.format(security.get_home_directory()), 
                      str(ak_directory))