Skip to content

Commit

Permalink
client temporary fix (#667)
Browse files Browse the repository at this point in the history
* client handles mis-configured proxy settings on paginated api endpoints
  • Loading branch information
ieaves authored Sep 28, 2023
1 parent 08a222d commit 0d55a71
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 88 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/client-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ jobs:
with:
python-version: "${{ env.py_ver }}"

- run: |
pip install pytest
pip install .
- uses: abatilo/actions-poetry@v2
with:
poetry-version: "${{ env.poetry_ver }}"

- run: poetry install

- run: pytest
- run: poetry run pytest
1 change: 1 addition & 0 deletions .github/workflows/integration-looker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ jobs:
poetry-version: "${{ env.poetry_ver }}"

- run: poetry install

- run: poetry run pytest
2 changes: 1 addition & 1 deletion actions/grai-actions
Submodule grai-actions updated 49 files
+7 −9 .github/workflows/integration_tests.yaml
+12 −26 .github/workflows/local_tests.yaml
+152 −152 README.md
+1 −1 bigquery/README.md
+2 −2 bigquery/action.yaml
+1 −1 dbt/README.md
+2 −2 dbt/action.yaml
+1 −1 fivetran/README.md
+2 −2 fivetran/action.yaml
+1 −1 flat-file/README.md
+2 −2 flat-file/action.yaml
+1 −1 image/entrypoints/bigquery.sh
+1 −1 image/entrypoints/dbt.sh
+1 −1 image/entrypoints/fivetran.sh
+1 −1 image/entrypoints/flat-file.sh
+1 −1 image/entrypoints/mssql.sh
+1 −1 image/entrypoints/mysql.sh
+1 −2 image/entrypoints/postgres.sh
+1 −1 image/entrypoints/redshift.sh
+1 −1 image/entrypoints/snowflake.sh
+806 −805 image/grai-actions/poetry.lock
+14 −51 image/grai-actions/pyproject.toml
+1 −2 image/grai-actions/src/grai_actions/config.py
+2 −4 image/grai-actions/src/grai_actions/integrations/__init__.py
+6 −3 image/grai-actions/src/grai_actions/integrations/bigquery/__init__.py
+2 −5 image/grai-actions/src/grai_actions/integrations/dbt/__init__.py
+4 −3 image/grai-actions/src/grai_actions/integrations/fivetran/__init__.py
+4 −3 image/grai-actions/src/grai_actions/integrations/flat_file/__init__.py
+7 −3 image/grai-actions/src/grai_actions/integrations/mssql/__init__.py
+4 −3 image/grai-actions/src/grai_actions/integrations/mysql/__init__.py
+4 −3 image/grai-actions/src/grai_actions/integrations/postgres/__init__.py
+4 −3 image/grai-actions/src/grai_actions/integrations/redshift/__init__.py
+4 −3 image/grai-actions/src/grai_actions/integrations/snowflake/__init__.py
+3 −6 image/grai-actions/src/grai_actions/main.py
+4 −28 image/grai-actions/src/grai_actions/tools.py
+9 −4 image/grai-actions/src/grai_actions/utilities.py
+0 −1 image/grai-actions/tests/gh_action_demo_script.py
+16 −55 image/grai-actions/tests/test_tools.py
+1 −1 mssql/README.md
+2 −2 mssql/action.yaml
+1 −1 mysql/README.md
+2 −2 mysql/action.yaml
+1 −1 postgres/README.md
+2 −2 postgres/action.yaml
+1 −1 redshift/README.md
+2 −2 redshift/action.yaml
+0 −2 run_test.sh
+1 −1 snowflake/README.md
+2 −2 snowflake/action.yaml
2 changes: 1 addition & 1 deletion actions/grai-actions-server
15 changes: 12 additions & 3 deletions grai-cli/grai_cli/api/server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import typer

from grai_cli.api.callbacks import requires_config_callback
from grai_cli.api.entrypoint import app
from grai_cli.settings.config import config
from grai_cli.utilities.headers import authenticate
from grai_cli.utilities.styling import print as print_styled

if TYPE_CHECKING:
from grai_client.endpoints.client import BaseClient
Expand All @@ -31,8 +31,17 @@ def get_default_client() -> BaseClient:
url = str(config.server.url)
workspace = config.server.workspace

client = _clients[config.server.api_version](url=url, workspace=workspace)
authenticate(client)
try:
client = _clients[config.server.api_version](url=url, workspace=workspace)
authenticate(client)
except:
message = (
f"Failed to authenticate with the Grai server at `{url}` using the `{workspace}` workspace and"
f" provided credentials. Double check your configuration settings are correct. If you're attempting to "
f"connect to the cloud instance insure you're using `api.grai.io` not `app.grai.io`. "
)
print_styled(message)
raise typer.Exit()

return client

Expand Down
1 change: 1 addition & 0 deletions grai-cli/grai_cli/utilities/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def authenticate_with_username(client: BaseClient) -> BaseClient:
Raises:
"""

client.authenticate(username=config.auth.username, password=config.auth.password.get_secret_value())
return client

Expand Down
Empty file added grai-client/nginx.conf
Empty file.
185 changes: 108 additions & 77 deletions grai-client/poetry.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion grai-client/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "grai-client"
version = "0.3.2"
version = "0.3.3"
description = ""
authors = ["Ian Eaves <ian@grai.io>"]
license = "Elastic-2.0"
Expand Down Expand Up @@ -35,6 +35,7 @@ types-pyyaml = "^6.0.12.2"
pre-commit = "^2.20.0"
pdoc = "^13.1.1"
pytest-durations = "^1.2.0"
toml = "^0.10.2"

[tool.isort]
profile = "black"
Expand All @@ -43,6 +44,10 @@ known_first_party = "grai_client"
[tool.black]
line-length = 120

[tool.pytest.ini_options]
xfail_strict = true


[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down
2 changes: 1 addition & 1 deletion grai-client/src/grai_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
utilities,
)

__version__ = "0.3.1"
__version__ = "0.3.3"
3 changes: 3 additions & 0 deletions grai-client/src/grai_client/endpoints/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def validate_connection_arguments(
"""

if insecure is not None and not isinstance(insecure, bool):
raise ValueError(f"Unexpected `insecure` value: {insecure}, `insecure` must be either " f"True, False or None.")

if url is not None:
# derive from url
parsed_url = furl(url)
Expand Down
8 changes: 8 additions & 0 deletions grai-client/src/grai_client/endpoints/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def response_status_check(resp: Response) -> Response:
"If you think this should not be the case it might be a bug, you can "
"submit a bug report at https://github.com/grai-io/grai-core/issues"
)

raise RequestException(message)


Expand Down Expand Up @@ -154,17 +155,24 @@ def inner(client: "BaseClient", url: str, options: "ClientOptions") -> List[Dict
url:
options:
"""

if page := options.pagination.get("page", False):
return fn(client, page, options).json()["results"]

# Temporary fix for pagination to deal with poorly configured proxy headers

results = []
page = url
secure = url.startswith("https")
while page:
resp = fn(client, page, options).json()

results.extend(resp["results"])
page = resp["next"]

if page and page.startswith("http") and secure:
page = f"https{page[4:]}"

return results

return inner
Expand Down
1 change: 1 addition & 0 deletions grai-client/src/grai_client/endpoints/v1/get/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_node_by_label_v1(
"""
url = client.get_url(grai_type)
resp = paginated_get(client, url, options)

return [node_builder(obj) for obj in resp]


Expand Down
12 changes: 12 additions & 0 deletions grai-client/tests/test_project_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

import toml

from grai_client import __version__


def test_correct_version():
toml_file = os.path.join(os.path.dirname(__file__), "../pyproject.toml")
pyproject = toml.load(toml_file)
version = pyproject["tool"]["poetry"]["version"]
assert version == __version__

0 comments on commit 0d55a71

Please sign in to comment.