Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@W-9746696 refresh token logic for falcon added #36

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion argusclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ def with_auth_token(*args, **kwargs):
except ArgusAuthException:
if argus.password:
logging.debug("Token refresh failed, will attempt a fresh login", exc_info=True)
if argus.falconEnv:
logging.debug("Access Token and Refresh Token expired, update token files and provide relevant path")
vmeena0418 marked this conversation as resolved.
Show resolved Hide resolved
argus.refreshToken, argus.accessToken = getTokensFromFiles()
else:
raise
if not argus.accessToken and argus.password:
Expand All @@ -712,6 +715,18 @@ def with_auth_token(*args, **kwargs):

return with_auth_token

# Updates Access token and refresh token from files for mac to falcon usecase
vmeena0418 marked this conversation as resolved.
Show resolved Hide resolved
def getTokensFromFiles():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def getTokensFromFiles():
def promptForTokens():

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update method calls as well

# Prompt for access token
filepath = raw_input("Provide path to access token file")
vmeena0418 marked this conversation as resolved.
Show resolved Hide resolved
with open(filepath, 'r') as f:
access_token = f.read()

# Prompt for refresh token
filepath = raw_input("Provide path to refresh token file")
vmeena0418 marked this conversation as resolved.
Show resolved Hide resolved
with open(filepath, 'r') as f:
refresh_token = f.read()
return access_token, refresh_token

class ArgusServiceClient(object):
"""
Expand Down Expand Up @@ -763,7 +778,7 @@ class ArgusServiceClient(object):

"""

def __init__(self, user, password, endpoint, timeout=(10, 120), refreshToken=None, accessToken=None):
def __init__(self, user, password, endpoint, timeout=(10, 120), refreshToken=None, accessToken=None, falconEnv=False):
"""
Creates a new client object to interface with the Argus RESTful API.

Expand All @@ -779,6 +794,8 @@ def __init__(self, user, password, endpoint, timeout=(10, 120), refreshToken=Non
:type refreshToken: str
:param accessToken: A token that can be used to authenticate with Argus. If a ``refreshToken`` or ``password`` is specified, the ``accessToken`` will be refreshed as and when it is needed.
:type refreshToken: str
:param falconEnv: is falcon environment
:type falconEnv: bool
"""
if not user:
raise ValueError("A valid user must be specified")
Expand All @@ -788,6 +805,7 @@ def __init__(self, user, password, endpoint, timeout=(10, 120), refreshToken=Non
raise ValueError("Need a valid Argus endpoint URL")

self.user = user
self.falconEnv = falconEnv
self.password = password
self.endpoint = endpoint
self.timeout = timeout
Expand Down