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

fix: grpc meta auth #811

Merged
merged 2 commits into from
Aug 30, 2022
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
9 changes: 6 additions & 3 deletions client/clip_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def __init__(self, server: str, credential: dict = {}, **kwargs):
else:
raise ValueError(f'{server} is not a valid scheme')

self._authorization = credential.get('Authorization', None)
self._authorization = credential.get(
'Authorization', os.environ.get('CLIP_AUTH_TOKEN')
)

@overload
def encode(
Expand Down Expand Up @@ -205,8 +207,9 @@ def _get_post_payload(self, content, kwargs):
request_size=kwargs.get('batch_size', 8),
total_docs=len(content) if hasattr(content, '__len__') else None,
)

if self._scheme == 'grpc' and self._authorization:
payload.update(metadata=('authorization', self._authorization))
payload.update(metadata=(('authorization', self._authorization),))
elif self._scheme == 'http' and self._authorization:
payload.update(headers={'Authorization': self._authorization})
return payload
Expand Down Expand Up @@ -413,7 +416,7 @@ def _get_rank_payload(self, content, kwargs):
total_docs=len(content) if hasattr(content, '__len__') else None,
)
if self._scheme == 'grpc' and self._authorization:
payload.update(metadata=('authorization', self._authorization))
payload.update(metadata=(('authorization', self._authorization),))
elif self._scheme == 'http' and self._authorization:
payload.update(headers={'Authorization': self._authorization})
return payload
Expand Down