-
Notifications
You must be signed in to change notification settings - Fork 47
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
example testing on env script #1440
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking through old PRs to see what we can clean up, and this looks good - just have one small suggestion.
also, would we expect to have any more env_testing
related files in this directory? I wouldn't really expect any more, so maybe putting this in a directory called scripts
or similar would be more appropriate
ENV_UNIQUE = { | ||
"preview": "pre", | ||
"production": "pro", | ||
"sandbox": "sa", | ||
"test": "t", | ||
"staging": "st", | ||
"integration": "i", | ||
} | ||
|
||
|
||
def get_env(arg: str) -> str | None: | ||
if arg: | ||
arg = arg.lower() | ||
for k, v in ENV_UNIQUE.items(): | ||
if arg.startswith(v) and k.startswith(arg): | ||
return k | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, stealing it for my own scripts 👿
fn_id = None | ||
if len(sys.argv) < 2 or len(sys.argv) > 3: | ||
show_help() | ||
elif len(sys.argv) == 3: | ||
try: | ||
fn_id = UUID(sys.argv[2]) | ||
except Exception: | ||
show_help(f"Invalid function UUID: {sys.argv[2]}") | ||
|
||
env_id = get_env(sys.argv[1]) | ||
if env_id is None: | ||
show_help(f"Invalid/non-unique environment: {env_id}") | ||
|
||
os.environ["GLOBUS_SDK_ENVIRONMENT"] = env_id | ||
print(f"Testing on GLOBUS_SDK_ENVIRONMENT: ({env_id})") | ||
try: | ||
gcc = Client(environment=env_id) | ||
except AuthAPIError as e: | ||
print( | ||
"Encountered AuthAPIError, you probably need to delete/refresh" | ||
" your token for this environment (delete storage.db is quickest)" | ||
) | ||
print(e) | ||
sys.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest using argparse
here instead
An example script to test on any environment. More details on # dev
See show_help() for example usage, but something like:
python3 run_env.py sand
With results like below:
Note that a 3-5 second delay before getting results vi Client() is fine for all environments except Staging, which needed 8 sometimes, thus the delay is currently set to 8.