Skip to content

Commit

Permalink
fix: grpc meta auth (#811)
Browse files Browse the repository at this point in the history
* fix: grpc meta auth

* fix: use clip-auth-token env
  • Loading branch information
numb3r3 authored Aug 30, 2022
1 parent 83a8120 commit ea23968
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit ea23968

Please sign in to comment.