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

Allow passing pathlib.Path derived types to user_credentials #623

Merged
merged 2 commits into from
Oct 18, 2024
Merged
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
12 changes: 8 additions & 4 deletions nats/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from dataclasses import dataclass
from email.parser import BytesParser
from io import BytesIO
from pathlib import Path
from random import shuffle
from secrets import token_hex
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Union
Expand Down Expand Up @@ -107,7 +108,7 @@ class RawCredentials(UserString):
pass


Credentials = Union[str, Tuple[str, str], RawCredentials]
Credentials = Union[str, Tuple[str, str], RawCredentials, Path]


@dataclass
Expand Down Expand Up @@ -558,7 +559,8 @@ def sig_cb(nonce: str) -> bytes:
return sig

self._signature_cb = sig_cb
elif isinstance(creds, str) or isinstance(creds, UserString):
elif (isinstance(creds, str) or isinstance(creds, UserString)
or isinstance(creds, Path)):
# Define the functions to be able to sign things using nkeys.
def user_cb() -> bytearray:
return self._read_creds_user_jwt(creds)
Expand All @@ -579,7 +581,9 @@ def sig_cb(nonce: str) -> bytes:

self._signature_cb = sig_cb

def _read_creds_user_nkey(self, creds: str | UserString) -> bytearray:
def _read_creds_user_nkey(
self, creds: str | UserString | Path
) -> bytearray:

def get_user_seed(f):
for line in f:
Expand Down Expand Up @@ -608,7 +612,7 @@ def get_user_seed(f):
with open(creds, "rb", buffering=0) as f:
return get_user_seed(f)

def _read_creds_user_jwt(self, creds: str | RawCredentials):
def _read_creds_user_jwt(self, creds: str | RawCredentials | Path):

def get_user_jwt(f):
user_jwt = None
Expand Down
Loading