Skip to content
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

Adds support for connection_uri GET request #7

Merged
merged 1 commit into from
Nov 16, 2024
Merged

Conversation

davidgomes
Copy link
Contributor

@davidgomes davidgomes commented Nov 10, 2024

This PR adds support for this missing endpoint in Neon's API (https://api-docs.neon.tech/reference/getconnectionuri).

>>> neon.connection_uri('twilight-king-17249571', 'neon_db', 'neondb_owner')
ConnectionUri(uri='postgresql://neondb_owner:bywO1ADn7Mse@ep-ancient-dew-a5la66a7-pooler.us-east-2.aws.neon.tech/neon_db?sslmode=require')

>>> neon.connection_uri('twilight-king-17249571', 'neon_db')
Traceback (most recent call last):
  File "/Users/david/src/neon-api-python/neon_api/client.py", line 117, in _request
    r.raise_for_status()
  File "/Users/david/src/neon-api-python/venv/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://console.neon.tech/api/v2/projects/twilight-king-17249571/connection_uri?database_name=neon_db

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/david/src/neon-api-python/neon_api/client.py", line 39, in wrapper
    return model(**func(*args, **kwargs))
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/david/src/neon-api-python/neon_api/client.py", line 230, in connection_uri
    return self._request("GET", f"projects/{project_id}/connection_uri", params=r_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/david/src/neon-api-python/neon_api/client.py", line 119, in _request
    raise NeonAPIError(r.text)
neon_api.exceptions.NeonAPIError: {"code":"","message":"invalid input"}

Also, make test works.

@davidgomes davidgomes self-assigned this Nov 10, 2024
@davidgomes davidgomes force-pushed the connection-uri-get branch 2 times, most recently from 55c57a8 to 03b9fff Compare November 10, 2024 18:28
@davidgomes davidgomes merged commit 8b347e3 into main Nov 16, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants