Skip to content
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
12 changes: 7 additions & 5 deletions packages/polaris/polaris/polaris/modules/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ class ApiOp:
class ApiTarget:
name: str
base_url: str
auth: Optional[Callable[[str], str]] = None
headers: Optional[Callable[[], Dict[str, str]]] = None

def build_url(self, path: str) -> str:
url = f"{self.base_url.rstrip('/')}/{path.lstrip('/')}"
if self.auth:
url = self.auth(url)
return url
return f"{self.base_url.rstrip('/')}/{path.lstrip('/')}"

def get_headers(self) -> Dict[str, str]:
if self.headers:
return self.headers()
return {}


class ApiProvider:
Expand Down
9 changes: 4 additions & 5 deletions packages/polaris/polaris/polaris/modules/api/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def target(self):
return ApiTarget(
name=PROVIDER_NAME,
base_url=self.galaxy_root,
auth=self._galaxy_auth,
headers=self._galaxy_headers,
)

def ops(self):
Expand Down Expand Up @@ -65,8 +65,7 @@ def resolve_op(self, name):
},
)

def _galaxy_auth(self, url):
def _galaxy_headers(self):
if self.galaxy_key:
sep = "&" if "?" in url else "?"
return f"{url}{sep}key={self.galaxy_key}"
return url
return {"x-api-key": self.galaxy_key}
return {}
3 changes: 2 additions & 1 deletion packages/polaris/polaris/polaris/modules/api/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ async def openapi_get(target, input, meta):
sep = "&" if "?" in url else "?"
url = f"{url}{sep}{urlencode(query_params)}"

return await http.request("GET", url)
headers = target.get_headers()
return await http.request("GET", url, headers=headers)