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

GAIA-26824 Remove the get_access_token from sdk and --print_token from cli #388

Merged
Merged
Show file tree
Hide file tree
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
29 changes: 2 additions & 27 deletions groclient/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,14 @@ def main(): # pragma: no cover
Usage examples:
gro_client --item=soybeans --region=brazil --partner_region china --metric export
gro_client --item=sesame --region=ethiopia
gro_client [email protected] --print_token
For more information use --help
"""
parser = argparse.ArgumentParser(description="Gro API command line interface")
parser.add_argument("--user_email")
parser.add_argument("--user_password")
parser.add_argument("--item")
parser.add_argument("--metric")
parser.add_argument("--region")
parser.add_argument("--partner_region")
parser.add_argument("--file")
parser.add_argument(
"--print_token",
action="store_true",
help="Output API access token for the given user email and password. "
"Save it in GROAPI_TOKEN environment variable.",
)
parser.add_argument(
"--token",
default=os.environ.get("GROAPI_TOKEN"),
Expand All @@ -95,25 +86,9 @@ def main(): # pragma: no cover
print(groclient.lib.get_version_info().get("api-client-version"))
return

assert (
args.user_email or args.token
), "Need --token, or --user_email, or $GROAPI_TOKEN"
access_token = None

if args.token:
access_token = args.token
else:
if not args.user_password:
args.user_password = getpass.getpass()
access_token = groclient.lib.get_access_token(
groclient.cfg.API_HOST, args.user_email, args.user_password
)

if args.print_token:
print(access_token)
return
assert args.token, "Need --token, or the access token to be set in environment variable: $GROAPI_TOKEN"

client = GroClient(groclient.cfg.API_HOST, access_token)
client = GroClient(groclient.cfg.API_HOST, args.token)

if (
not args.metric
Expand Down
44 changes: 0 additions & 44 deletions groclient/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,50 +89,6 @@ def get_default_logger():
return logger


def get_access_token(api_host, user_email, user_password, logger=None):
"""Request an access token.
This is a DEPRECATED function and will no longer be supported after November 1, 2023!

Parameters
----------
api_host : string
The API host's url, excluding 'https://'
ex. 'api.gro-intelligence.com'
user_email : string
Email address associated with user's Gro account
user_password : string
Password for user's Gro account
logger : logging.Logger
Alternative logger object if wanting to use a non-default one.
Otherwise get_default_logger() will be used.

Returns
-------
accessToken : string

"""
warnings.warn(
f"get_access_token() is deprecated and will be removed on November 1, 2023.",
DeprecationWarning,
2,
)
retry_count = 0
if not logger:
logger = get_default_logger()
while retry_count <= cfg.MAX_RETRIES:
get_api_token = requests.post(
"https://" + api_host + "/api-token",
data={"email": user_email, "password": user_password},
)
if get_api_token.status_code == 200:
logger.debug("Authentication succeeded in get_access_token")
return get_api_token.json()["data"]["accessToken"]

logger.warning(f"Error in get_access_token: {get_api_token}")
retry_count += 1
raise Exception(f"Giving up on get_access_token after {retry_count} tries.")


def redirect(old_params, migration):
"""Update query parameters to follow a redirection response from the API.

Expand Down
Loading