httpimport
httpimport copied to clipboard
Support for Gitlab private repos
Hi there, this is very neat, would be fantastic to find a way to also support private gitlab/github maybe via an ssh key? Cheers!
For instance:
https://gitlab.com/api/v4/projects/xxxxxxxx/repository/files/avapi.tar.xz/raw?ref=main
requires a private-token in the header, how do I set that via the INIT files?
I have tried this:
import httpimport
profile = """
[gitlab]
headers:
PRIVATE-TOKEN:glpat-asfasfdsafdsfdsfddsf
"""
httpimport.set_profile(profile)
with httpimport.remote_repo("https://gitlab.com/api/v4/projects/xxxxxxxxx/repository/files/avapi.tar.xz/raw?ref=main",profile= profile):
import ciao
print(ciao)
but it doesn't seem to like it.
Hello @priamai ! SSH authentication for Git will not be implemented as this project is only using HTTP/S.
There is an example very close to your use-case in the README.md: https://github.com/operatorequals/httpimport#named-profiles
You'll need to use gitlab_repo instead of remote_repo and also use the Gitlab Token as an HTTP Basic Auth password (never tried that myself, read that here: https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#clone-repository-using-personal-access-token)
Also the profile parameter does accept the name of the profile, not the whole string itself, in your case profile='gitlab' should work!
Like this:
import httpimport
profile = """
[gitlab]
headers:
PRIVATE-TOKEN:glpat-xxxxxxxxxxxxxxxxxxxxx
"""
httpimport.set_profile(profile)
with httpimport.gitlab_repo("ava-clustering","ava-modules",profile= 'gitlab'):
import avapi
print(avapi.__dict__)
but I am getting this error
ModuleNotFoundError: No module named 'avapi'
This is how my folder looks like

profile = """ [gitlab] headers: PRIVATE-TOKEN:glpat-xxxxxxxxxxxxxxxxxxxxx """ httpimport.set_profile(profile) with httpimport.gitlab_repo("ava-clustering","ava-modules",profile= 'gitlab'): import avapi print(avapi.__dict__)
That's.much better but you need to see how Gitlab is expecting the token in the HTTP header. PRIVATE-TOKEN will not work.
Check Gitlab's documentation!
The documentation shows this:
curl --header "PRIVATE-TOKEN: <your_access_token>"
but I need to check how your code makes the request :-).
example from documentation:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb?ref=master"
here: https://docs.gitlab.com/ee/api/repository_files.html
I see. The code uses this template for the URL: https://github.com/operatorequals/httpimport/blob/master/httpimport.py#L34
It does not use the API so, the PRIVATE-TOKEN header doesn't work.
I haven't tried authenticated GitLab yet. Let's leave this issue open, so I can furtherly test it with Gitlab.
I also changed the Issue title to something more specific, so we can track the problem and eventually solve.
You are also welcome to submit a PR in case you make it work by altering httpimport!