-
Notifications
You must be signed in to change notification settings - Fork 137
Easy EU region selection: ROBOFLOW_REGION, auth login --region, auth set-region #513
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,19 @@ def check_key(api_key, model, notebook, num_retries=0): | |
| return "onboarding" | ||
|
|
||
|
|
||
| def login(workspace=None, force=False): | ||
| def login(workspace=None, force=False, region=None): | ||
| normalized_region = None | ||
| if region is not None: | ||
| if not isinstance(region, str) or region.lower() not in {"us", "eu"}: | ||
| raise ValueError(f"Invalid region '{region}'. Expected one of: us, eu.") | ||
| normalized_region = region.lower() | ||
|
|
||
| # Resolve at call time so a region passed by the CLI is honored even though | ||
| # the module-level URL constants were resolved when roboflow was imported. | ||
| from roboflow.config import resolve_url | ||
|
|
||
| app_url = resolve_url("APP_URL", region=normalized_region) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix_before_merge · bug · 96% — [sol-ultra] Programmatic EU login leaves the SDK on its import-time API endpoint
Why this matters — |
||
|
|
||
| os_name = os.name | ||
|
|
||
| if os_name == "nt": | ||
|
|
@@ -76,22 +88,31 @@ def login(workspace=None, force=False): | |
|
|
||
| # default configuration location | ||
| conf_location = os.getenv("ROBOFLOW_CONFIG_DIR", default=default_path) | ||
| existing_config = {} | ||
| if os.path.isfile(conf_location) and not force: | ||
| write_line("You are already logged into Roboflow. To make a different login,run roboflow.login(force=True).") | ||
| return None | ||
| # we could eventually return the workspace object here | ||
| # return Roboflow().workspace() | ||
| elif os.path.isfile(conf_location) and force: | ||
| try: | ||
| with open(conf_location) as f: | ||
| existing_config = json.load(f) | ||
| except json.JSONDecodeError: | ||
| # A forced login has historically replaced an unreadable config. | ||
| existing_config = {} | ||
| if not isinstance(existing_config, dict): | ||
| existing_config = {} | ||
| os.remove(conf_location) | ||
|
|
||
| if workspace is None: | ||
| write_line("visit " + APP_URL + "/auth-cli to get your authentication token.") | ||
| write_line("visit " + app_url + "/auth-cli to get your authentication token.") | ||
| else: | ||
| write_line("visit " + APP_URL + "/auth-cli/?workspace=" + workspace + " to get your authentication token.") | ||
| write_line("visit " + app_url + "/auth-cli/?workspace=" + workspace + " to get your authentication token.") | ||
|
|
||
| token = getpass("Paste the authentication token here: ") | ||
|
|
||
| r_login = requests.get(APP_URL + "/query/cliAuthToken/" + token) | ||
| r_login = requests.get(app_url + "/query/cliAuthToken/" + token) | ||
|
|
||
| if r_login.status_code == 200: | ||
| r_login = r_login.json() | ||
|
|
@@ -102,16 +123,18 @@ def login(workspace=None, force=False): | |
| if not os.path.exists(os.path.dirname(conf_location)): | ||
| os.makedirs(os.path.dirname(conf_location)) | ||
|
|
||
| r_login = {"workspaces": r_login} | ||
| existing_config["workspaces"] = r_login | ||
| # set first workspace as default workspace | ||
|
|
||
| default_workspace_id = list(r_login["workspaces"].keys())[0] | ||
| workspace = r_login["workspaces"][default_workspace_id] | ||
| r_login["RF_WORKSPACE"] = workspace["url"] | ||
| default_workspace_id = list(existing_config["workspaces"].keys())[0] | ||
| workspace = existing_config["workspaces"][default_workspace_id] | ||
| existing_config["RF_WORKSPACE"] = workspace["url"] | ||
| if normalized_region is not None: | ||
| existing_config["ROBOFLOW_REGION"] = normalized_region | ||
|
|
||
| # write config file | ||
| with open(conf_location, "w") as f: | ||
| json.dump(r_login, f, indent=2) | ||
| json.dump(existing_config, f, indent=2) | ||
|
|
||
| else: | ||
| r_login.raise_for_status() | ||
|
|
||
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.
fix_before_merge · api · 92% — [sol-ultra] Public URL helpers still reject EU application URLs
The new README states that the same package supports the EU platform, but the supplied complete roboflow/init.py still permits only literal
app.roboflow.comoruniverse.roboflow.comURLs in bothload_modelanddownload_dataset. Anapp.roboflow.eumodel or dataset URL is rejected before parsing, even when the effective region is EU.Why this matters —
regional-url-compatibility: Public helpers that accept platform URLs must recognize the corresponding hostname of every region the package claims to support.