Skip to content

Commit

Permalink
Handle instances with a default port of 443
Browse files Browse the repository at this point in the history
Closes #162
  • Loading branch information
joshtemple committed Feb 20, 2021
1 parent cc20250 commit a76cadb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions spectacles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ def _build_base_subparser() -> argparse.ArgumentParser:
type=int,
action=EnvVarAction,
env_var="LOOKER_PORT",
default=19999,
help="The port of your Looker instance’s API. The default is port 19999.",
help="The port of your Looker instance’s API. The default is port 443 (HTTPS) for GCP-hosted instances and 19999 for legacy instances.",
)
base_subparser.add_argument(
"--api-version",
Expand Down
14 changes: 12 additions & 2 deletions spectacles/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
base_url: str,
client_id: str,
client_secret: str,
port: int = 19999,
port: Optional[int] = None,
api_version: float = 3.1,
):
supported_api_versions = [3.1]
Expand All @@ -64,7 +64,17 @@ def __init__(
)

self.base_url: str = base_url.rstrip("/")
self.api_url: str = f"{self.base_url}:{port}/api/{api_version}/"
if port is None and self.base_url.endswith("cloud.looker.com"):
# GCP-hosted instance, so use default port of 443 with HTTPS
if not self.base_url.startswith("https"):
raise SpectaclesException(
name="invalid-base-url",
title="Looker instance base URL is not valid.",
detail="The URL must be an HTTPS URL.",
)
self.api_url: str = f"{self.base_url}/api/{api_version}/"
else:
self.api_url = f"{self.base_url}:{port or 19999}/api/{api_version}/"
self.client_id: str = client_id
self.client_secret: str = client_secret
self.api_version: float = api_version
Expand Down

0 comments on commit a76cadb

Please sign in to comment.