diff --git a/dataall_cli/cli.py b/dataall_cli/cli.py index 8a76cd6..692bba4 100644 --- a/dataall_cli/cli.py +++ b/dataall_cli/cli.py @@ -7,6 +7,11 @@ from typing import Any, Dict, List, Optional import click +from dataall_core.auth.oidc_browser_auth import ( + DEFAULT_FALLBACK_REDIRECT_URI, + DEFAULT_REDIRECT_URI, + DEFAULT_SCOPES, +) from dataall_core.dataall_client import DataallClient from dataall_core.profile import CONFIG_PATH @@ -52,9 +57,6 @@ def dataall_cli() -> None: AUTH_TYPES = ["CognitoAuth", "CustomAuth", "OidcBrowserAuth"] -DEFAULT_REDIRECT_URI = "http://localhost:8765/callback" -DEFAULT_FALLBACK_REDIRECT_URI = "http://localhost:8766/callback" -DEFAULT_SCOPES = "openid offline_access" DISCOVERED = "dataall_discovered" DISCOVERED_FOR = "dataall_discovered_for" diff --git a/dataall_cli/utils/__init__.py b/dataall_cli/utils/__init__.py index 12324e7..767629e 100644 --- a/dataall_cli/utils/__init__.py +++ b/dataall_cli/utils/__init__.py @@ -1,6 +1,7 @@ """data.all cli utils.""" +from dataall_core.discovery import discover_from_frontend, frontend_origin + from .config import load_config, save_config -from .discovery import discover_from_frontend, frontend_origin __all__ = ["discover_from_frontend", "frontend_origin", "load_config", "save_config"] diff --git a/dataall_cli/utils/discovery.py b/dataall_cli/utils/discovery.py deleted file mode 100644 index b623a52..0000000 --- a/dataall_cli/utils/discovery.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Discover CLI settings from a deployed data.all front page.""" - -import re -from typing import Dict -from urllib.parse import urljoin, urlparse - -import httpx - -BUNDLE_PATTERN = re.compile(r'src="([^"]*static/js/main\.[^"]+\.js)"') -VALUE_PATTERN = re.compile(r'(REACT_APP_[A-Z_]+):"([^"]*)"') -API_SUFFIX = "/graphql/api" - - -def frontend_origin(dataall_url: str) -> str: - """Return ``scheme://host`` of a data.all URL.""" - parsed = urlparse(dataall_url) - return f"{parsed.scheme}://{parsed.netloc}" - - -def discover_from_frontend(dataall_url: str) -> Dict[str, str]: - """Read the auth type, identity provider, client id and API endpoint from the front page bundle. - - Returns ``frontend_url`` plus whichever values were found. - """ - found = {"frontend_url": frontend_origin(dataall_url)} - base = dataall_url.rstrip("/") + "/" - index = httpx.get(base, follow_redirects=True, timeout=30) - index.raise_for_status() - match = BUNDLE_PATTERN.search(index.text) - if not match: - return found - bundle = httpx.get(urljoin(base, match.group(1)), follow_redirects=True, timeout=60) - bundle.raise_for_status() - values = dict(VALUE_PATTERN.findall(bundle.text)) - - if values.get("REACT_APP_CUSTOM_AUTH") and values.get("REACT_APP_CUSTOM_AUTH_URL"): - found["auth_type"] = "OidcBrowserAuth" - found["idp_domain_url"] = values["REACT_APP_CUSTOM_AUTH_URL"] - if values.get("REACT_APP_CUSTOM_AUTH_CLIENT_ID"): - found["client_id"] = values["REACT_APP_CUSTOM_AUTH_CLIENT_ID"] - elif values.get("REACT_APP_COGNITO_APP_CLIENT_ID"): - found["auth_type"] = "CognitoAuth" - found["client_id"] = values["REACT_APP_COGNITO_APP_CLIENT_ID"] - domain = values.get("REACT_APP_COGNITO_DOMAIN", "") - if domain: - found["idp_domain_url"] = domain if "://" in domain else f"https://{domain}" - if values.get("REACT_APP_COGNITO_REDIRECT_SIGNIN"): - found["redirect_uri"] = values["REACT_APP_COGNITO_REDIRECT_SIGNIN"] - api = values.get("REACT_APP_GRAPHQL_API", "") - if api: - found["api_endpoint_url"] = ( - api[: -len(API_SUFFIX)] if api.endswith(API_SUFFIX) else api - ) - return found diff --git a/poetry.lock b/poetry.lock index 50597e7..95edd4d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1408,14 +1408,14 @@ test-randomorder = ["pytest-randomly"] [[package]] name = "dataall-core" -version = "0.5.0" +version = "0.6.0" description = "AWS data.all core" optional = false python-versions = "<4.0,>=3.9" groups = ["main"] files = [ - {file = "dataall_core-0.5.0-py3-none-any.whl", hash = "sha256:5edf4c7d2a0f0d8f176e232a8cb7c4020aa1a736456d33a30858f3a20335c40e"}, - {file = "dataall_core-0.5.0.tar.gz", hash = "sha256:2b9ee04bb2c84547e1d87aa83947e259131ac558013751a2aad0473facfa3736"}, + {file = "dataall_core-0.6.0-py3-none-any.whl", hash = "sha256:9ef1d560c4aea12e583e80b8b53d53f204edb14b5605db3f53f15cf10008ee98"}, + {file = "dataall_core-0.6.0.tar.gz", hash = "sha256:63e9c44b9c7ea2e8101cf9d3a10dc02bcf0cb83e9f031f79c268ff18403f820f"}, ] [package.dependencies] @@ -4991,4 +4991,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.1" python-versions = ">=3.9,<4.0" -content-hash = "02be3fe6cdd26745c036208f8973c9822282fb32d4a4c82c0c223ddecb8909d0" +content-hash = "f50f7e0561008664d95a17129319788a06db0c0011aa0ef57382e8c871d0b094" diff --git a/pyproject.toml b/pyproject.toml index 66ee184..f18ec39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dataall-cli" -version = "0.5.0" +version = "0.6.0" description = "AWS data.all CLI" authors = [{ name = "Amazon Web Services" }] license = { text = "Apache License 2.0" } @@ -22,7 +22,7 @@ dependencies = [ "atomicfile>=1.0.1", "PyYAML>=6.0.1", "setuptools; python_version >= '3.12'", - "dataall-core>=0.5.0,<0.6.0", + "dataall-core>=0.6.0,<0.7.0", ] [project.scripts] diff --git a/tests/unit/test_discovery.py b/tests/unit/test_discovery.py deleted file mode 100644 index 9021aad..0000000 --- a/tests/unit/test_discovery.py +++ /dev/null @@ -1,93 +0,0 @@ -import httpx -import pytest - -from dataall_cli.utils import discover_from_frontend, frontend_origin - -FRONT = "https://dataall.example.com" -INDEX = ( - "