Is it possible to pass custom headers using the snakemake_storage_plugin_http?
I'm trying to download files from a server that uses an API key in the header
for authentication (I have no control over this).
I've tried variations of storage.http(url_to_get,headers=request_headers) and
passing a requests.get object but it doesn't work.
The auth argument says it needs a request.auth subclass. I can do this in
python:
import os
import requests
class ApiKeyAuth(requests.auth.AuthBase):
def __init__(self, api_key):
self.api_key = api_key
def __call__(self, r):
r.headers["Authorization"] = self.api_key
return r
apikey = os.getenv("my_key")
auth = ApiKeyAuth(apikey)
url_to_get = "https://server.com/file.bam"
resp = requests.get(url_to_get, auth=auth, stream=True)
Would it be possible to allow custom AuthBase classes with something like
issubclass(auth_type, requests.auth.AuthBase)? Right now the plugin hard
codes the available classes
|
if auth_type == "HTTPBasicAuth": |
|
return HTTPBasicAuth(*matches.group("arg").split(",")) |
|
elif auth_type == "HTTPDigestAuth": |
|
return HTTPDigestAuth(*matches.group("arg").split(",")) |
|
elif auth_type == "OAuth1": |
|
return OAuth1(*matches.group("arg").split(",")) |
Maybe there's an easier way?
Is it possible to pass custom headers using the snakemake_storage_plugin_http?
I'm trying to download files from a server that uses an API key in the header
for authentication (I have no control over this).
I've tried variations of
storage.http(url_to_get,headers=request_headers)andpassing a
requests.getobject but it doesn't work.The
authargument says it needs a request.auth subclass. I can do this inpython:
Would it be possible to allow custom AuthBase classes with something like
issubclass(auth_type, requests.auth.AuthBase)? Right now the plugin hardcodes the available classes
snakemake-storage-plugin-http/snakemake_storage_plugin_http/__init__.py
Lines 44 to 49 in 41e3eb5
Maybe there's an easier way?