2

I need to download a file from a private GitLab.

I already saw this post: Download from a GitLab private repository

But I cannot use the API, since I dont have the needed IDs to download the files. In fact, I need to download them by theirs HTTP raw urls, like:

http://gitlab.private.com/group/repo_name/raw/master/diagrams/test.plantuml

Since I turned on authentication, every time I try to access something programatically, I am redirected to login page. I wrote a Python script to mimic the login process, obtain the authenticity_token and the _gitlab_session cookie, but still not working.

If I grab a session cookie from my Chrome browser after a successful login, everything works like a charm (from the file download perspective) on Python and even curl.

So, any help is apreciated to obtain this cookie, os a different approach. To use the API I would first need to struggle among all repos performing strings matches so I can find the proper IDs. This is the last option.

Tks Marco

Community
  • 1
  • 1
Lovato
  • 2,250
  • 1
  • 16
  • 22
  • Do you really need a Python script to fake login ? You can login through the API: send a `POST /session` with login & password as parameters; and obtain the `private_token`. Take a look [here](http://doc.gitlab.com/ce/api/session.html) – Pierre Aug 12 '14 at 12:28
  • Yes, I know I can use the API. But if I do that, I need to download the file via API. Then, I will need to parse groups/repos to transform my groups/repos names to IDs. FakeLogin is getting worse as time passes... – Lovato Aug 12 '14 at 12:31

1 Answers1

0

First generate a Personal Access Token from your settings page: /profile/personal_access_tokens. Make sure it has the read_repository scope.

Then you can use one of two methods, replacing PRIVATETOKEN with the token you acquired:

  1. Pass a Private-Token header in your request. E.g.

    curl --header "Private-Token: PRIVATETOKEN" http://gitlab.private.com/group/repo_name/raw/master/diagrams/test.plantuml
    
  2. Add a private_token query string to your request. E.g.

    curl 'http://gitlab.private.com/group/repo_name/raw/master/diagrams/test.plantuml?private_token=PRIVATETOKEN'
    
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328