jupyterhub / binderhub

Run your code in the cloud, with technology so advanced, it feels like magic!
https://binderhub.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.57k stars 390 forks source link

Allow provider redirects #1458

Open minrk opened 2 years ago

minrk commented 2 years ago

Proposed change

Allow providers to redirect to other providers, if there are multiple valid providers for a given resource and one is preferred.

The main use case is redirecting from the raw Git provider to GitHub, Bitbucket, etc.

Alternative options

Don't do this. Require deployments that want to apply resources/bans to make sure they are applied consistently across all providers that may link to a repo.

Who would use this feature?

Deployers of BinderHub, especially those who want to consistently manage statistics, bans, quotas, etc.

(Optional): Suggest a solution

Perform a check at the beginning of resolving a spec, and select the new provider. This needs to take into account other registered providers, and (maybe?) their priorities.

Maybe something like:

current_provider_class = provider.__class__
repo_ref_url = provider.get_resolved_ref_url()

# check if a higher-priority provider can be used for this URL
for Provider in repo_providers:
    if Provider(config=config).accepts_url(repo_ref_url):
        # switch to higher-priority provider
        provider = Provider.from_url(repo_ref_url)
        break
    if Provider is provider.__class__:
        # ignore lower-priority providers
        break

Alternately, this could be a special feature of the GitRepoProvider, which I suspect is the only one likely to run into this.

This could result in an HTTP redirect (would need to happen before any event-stream messages), or it could merely instantiate the right RepoProvider within the handler (i.e. not visible to the user).

A more general 'awesome-bar' style functionality, where users provide a URL and BinderHub is responsible for picking the provider would also make this easier.