thoughtspot / thoughtspot_rest_api_v1_python

Python implementations of ThoughtSpot REST APIs V1 and V2
Other
3 stars 6 forks source link

Update cookies on successful login and add session/isactive api #13

Open amardeep-kahali-ts opened 1 year ago

amardeep-kahali-ts commented 1 year ago

Reason for adding these endpoints: In the perf framework, we decorate each function with a login_if_needed decorator so that we do not explicitly need to call the login APIs. Here's the code for the decorator:

def login_if_needed(func):
    """
    Decorator to check if login is needed
    Args:
        func(object): Function which requires login
    """

    def wrapper(self, *args, **kwargs):
        if not self.session_isactive():
            self.session_login(self.username, self.password)
        return func(self, *args, **kwargs)
    return wrapper

# Usage
@login_if_needed
def user_list(self) -> Dict:
    endpoint = "user/list"
    url = self.base_url + endpoint
    response = self.requests_session.get(url=url)
    response.raise_for_status()
    return response.json()

It would help us if this functionality was incorporated in the library.