Skip to content

http server that uses an API key in the header #27

@TomHarrop

Description

@TomHarrop

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions