Skip to content

Commit 572210c

Browse files
committed
Update 2 Globus cases
1 parent b8fe696 commit 572210c

File tree

2 files changed

+66
-26
lines changed

2 files changed

+66
-26
lines changed

examples/simple_globus.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import configparser
12
import os
23
import re
34
import shutil
4-
from typing import List, Tuple
5+
from typing import List, Optional, Tuple
56
from urllib.parse import ParseResult, urlparse
67

78
from fair_research_login.client import NativeClient
@@ -29,33 +30,15 @@
2930
3031
# Run
3132
32-
Case 1: authenticate 2x on toy run, 0x on real run
33-
python simple_globus.py # REQUEST_SCOPES_EARLY=False
34-
# TOY RUN:
35-
# Prompts 1st time for auth code, no login requested
36-
# Prompts 2nd time for auth code:
37-
# > Argonne prompt > enter Argonne credentials
38-
# > NERSC prompt > no login requested
39-
# "Consents added, please re-run the previous command to start transfer"
40-
# "Now that we have the authentications, let's re-run."
41-
# REAL RUN:
42-
# "Might ask for 1st authentication prompt:"
43-
# No prompt at all!
44-
# "Authenticated for the 1st time!"
33+
# Reset Globus state, as described above
34+
35+
# Case 1: REQUEST_SCOPES_EARLY=False
36+
python simple_globus.py
4537
4638
# Reset Globus state, as described above
4739
48-
# Case 2: authenticate 1x on toy run, 1x on real run
49-
python simple_globus.py # REQUEST_SCOPES_EARLY=True
50-
# TOY RUN:
51-
# Prompts 1st time for auth code:
52-
# > Argonne prompt > no login requested
53-
# > NERSC prompt > no login requested
54-
# "Bypassed 2nd authentication."
55-
# "We didn't need to authenticate a second time on the toy run!"
56-
# REAL RUN:
57-
# Prompts 1st time for auth code, no login requested
58-
# "Bypassed 2nd authentication."
40+
# Case 2: REQUEST_SCOPES_EARLY=True
41+
python simple_globus.py
5942
"""
6043

6144
# Settings ####################################################################
@@ -66,6 +49,8 @@
6649
REMOTE_ENDPOINT: str = "NERSC Perlmutter"
6750

6851
# Constants ###################################################################
52+
GLOBUS_CFG: str = os.path.expanduser("~/.globus-native-apps.cfg")
53+
INI_PATH: str = os.path.expanduser("~/.zstash.ini")
6954
ZSTASH_CLIENT_ID: str = "6c1629cf-446c-49e7-af95-323c6412397f"
7055
NAME_TO_ENDPOINT_MAP = {
7156
"NERSC HPSS": "9cd89cfd-6d04-11e5-ba46-22000b92c6ec",
@@ -78,6 +63,7 @@
7863
def main():
7964
base_dir = os.getcwd()
8065
print(f"Starting in {base_dir}")
66+
reset_state_files()
8167
skipped_second_auth: bool = False
8268
try:
8369
skipped_second_auth = simple_transfer("toy_run")
@@ -93,16 +79,24 @@ def main():
9379
assert skipped_second_auth
9480

9581

82+
def reset_state_files():
83+
if os.path.exists(INI_PATH):
84+
os.remove(INI_PATH)
85+
if os.path.exists(GLOBUS_CFG):
86+
os.remove(GLOBUS_CFG)
87+
88+
9689
def simple_transfer(run_dir: str) -> bool:
9790
remote_path = f"globus://{NAME_TO_ENDPOINT_MAP[REMOTE_ENDPOINT]}/~/{REMOTE_DIR_PREFIX}_{run_dir}"
9891
config_path: str
9992
txt_file: str
10093
config_path, txt_file = get_dir_and_file_to_archive(run_dir)
10194
url: ParseResult = urlparse(remote_path)
10295
assert url.scheme == "globus"
96+
check_state_files()
10397
remote_endpoint: str = url.netloc
10498
print(f"url.scheme={url.scheme}, url.netloc={url.netloc}")
105-
local_endpoint: str = NAME_TO_ENDPOINT_MAP[LOCAL_ENDPOINT]
99+
local_endpoint: str = get_local_endpoint_id()
106100
both_endpoints: List[str] = [local_endpoint, remote_endpoint]
107101
native_client = NativeClient(
108102
client_id=ZSTASH_CLIENT_ID,
@@ -165,6 +159,35 @@ def simple_transfer(run_dir: str) -> bool:
165159
return skipped_second_auth
166160

167161

162+
def check_state_files():
163+
if os.path.exists(INI_PATH):
164+
print(f"{INI_PATH} exists.")
165+
else:
166+
print(f"{INI_PATH} does NOT exist.")
167+
if os.path.exists(GLOBUS_CFG):
168+
print(f"{GLOBUS_CFG} exists.")
169+
else:
170+
print(f"{GLOBUS_CFG} does NOT exist.")
171+
172+
173+
def get_local_endpoint_id() -> str:
174+
ini = configparser.ConfigParser()
175+
local_endpoint: Optional[str] = None
176+
if ini.read(INI_PATH):
177+
if "local" in ini.sections():
178+
local_endpoint = ini["local"].get("globus_endpoint_uuid")
179+
print("Got local_endpoint from ini file")
180+
else:
181+
ini["local"] = {"globus_endpoint_uuid": ""}
182+
with open(INI_PATH, "w") as f:
183+
ini.write(f)
184+
print("Added local_endpoint to ini file")
185+
if not local_endpoint:
186+
local_endpoint = NAME_TO_ENDPOINT_MAP[LOCAL_ENDPOINT]
187+
print("Got local endpoint from NAME_TO_ENDPOINT_MAP")
188+
return local_endpoint
189+
190+
168191
def get_dir_and_file_to_archive(run_dir: str) -> Tuple[str, str]:
169192
if os.path.exists(run_dir):
170193
shutil.rmtree(run_dir)

examples/simple_globus_output.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- Case 1: `REQUEST_SCOPES_EARLY: bool = False` => authenticate 2x on toy run, 0x on real run
2+
- Case 2: `REQUEST_SCOPES_EARLY: bool = True` => authenticate 1x on toy run, 1x on real run
3+
4+
| Code block | Case 1 | Case 2 |
5+
| --- | --- | --- |
6+
| TOY: `check_state_files` `INI_PATH` | `/home/ac.forsyth2/.zstash.ini does NOT exist.` | Same |
7+
| TOY: `check_state_files` `GLOBUS_CFG` | `/home/ac.forsyth2/.globus-native-apps.cfg does NOT exist.` | Same |
8+
| TOY: `get_local_endpoint_id` | `Added local_endpoint to ini file`, `Got local endpoint from NAME_TO_ENDPOINT_MAP` | Same |
9+
| TOY: `native_client_login`| Pasting URL brings us to "Allow" screen immediately, paste auth code at command line | Prompt (login NOT required) for Argonne, prompt (login NOT required) for NERSC, "Allow" screen, paste auth code at command line |
10+
| TOY: `transfer_client.submit_transfer` try/except | Prompt (login required) for Argonne, prompt (login required) for NERSC, "Allow" screen, paste auth code at command line, `Consents added, please re-run the previous command to start transfer` | `Bypassed 2nd authentication.` |
11+
| `For toy_run, skipped_second_auth=` | `False` | `True` |
12+
| REAL: `check_state_files` `INI_PATH` | `/home/ac.forsyth2/.zstash.ini exists.` | Same |
13+
| REAL: `check_state_files` `GLOBUS_CFG` | `/home/ac.forsyth2/.globus-native-apps.cfg exists.` | Same |
14+
| REAL: `get_local_endpoint_id` | `Got local_endpoint from ini file`, `Got local endpoint from NAME_TO_ENDPOINT_MAP` (implies the value retreived was `None`...) | Same |
15+
| REAL: `native_client_login`| No logins or prompts | Pasting URL brings us to "Allow" screen immediately, paste auth code at command line |
16+
| REAL: `transfer_client.submit_transfer` try/except | `Bypassed 2nd authentication.` | Same |
17+
| `For real_run, skipped_second_auth=` | `True` | Same |

0 commit comments

Comments
 (0)