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

Handling exception of invalid header and strip token #825

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [UNRELEASED] neptune-client 0.14.3

## Features
- Stripping whitespaces from Neptune API Token ([#825](https://github.com/neptune-ai/neptune-client/pull/825))

## Fixes
- Raise proper exception when invalid token were provided ([#825](https://github.com/neptune-ai/neptune-client/pull/825))

## neptune-client 0.14.2

### Features
Expand Down
5 changes: 5 additions & 0 deletions neptune/new/internal/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
ClientHttpError,
NeptuneFeatureNotAvailableException,
MetadataInconsistency,
NeptuneInvalidApiTokenException,
)
from neptune.new.internal.backends.api_model import ClientConfig
from neptune.new.internal.operation import Operation, CopyAttribute
Expand Down Expand Up @@ -99,6 +100,10 @@ def wrapper(*args, **kwargs):

try:
return func(*args, **kwargs)
except requests.exceptions.InvalidHeader as e:
pkasprzyk marked this conversation as resolved.
Show resolved Hide resolved
if "X-Neptune-Api-Token" in e.args[0]:
raise NeptuneInvalidApiTokenException()
raise
except requests.exceptions.SSLError as e:
raise SSLError() from e
except (
Expand Down
1 change: 1 addition & 0 deletions neptune/new/internal/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def from_token(cls, api_token: Optional[str] = None) -> "Credentials":
if api_token is None:
raise NeptuneMissingApiTokenException()

api_token = api_token.strip()
token_dict = Credentials._api_token_to_dict(api_token)
# TODO: Consider renaming 'api_address' (breaking backward compatibility)
if "api_address" not in token_dict:
Expand Down