question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for providing username and password for curl downloads

See original GitHub issue

I’d like to retrieve dependencies from a private URL that requires credentials. In my current setup, I’m using curl --netrc, which enables me to put a hostname, username, and password into ~/.netrc.

Poking through the source of the curl module, I see https://github.com/buildinspace/peru/blob/42ad4ad5eabbe6e6872d2b6f4c459475e4051304/peru/resources/plugins/curl/curl_plugin.py#L82 is where the request is created. I looked at the urllib.request docs and see this example for setting up for basic auth:

import urllib.request
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='PDQ Application',
                          uri='https://mahler:8092/site-updates.py',
                          user='klem',
                          passwd='kadidd!ehopper')
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
urllib.request.urlopen('http://www.example.com/login.html')

netrc parsing is, fortunately, a standard library feature of Python, through the aptly-named netrc library.

The implementation of this all seems pretty straightforward but the configuration within peru is unclear. It would probably make sense for peru to read this file and populate the opener by default but I could see how some users may feel that’s a security risk. So, a compromise may be opt-in in the peru.yml, an auth block:

# from the example in README.md
curl module pathogen:
    url: https://codeload.github.com/tpope/vim-pathogen/tar.gz/v2.3
    auth: netrc
    # Untar the archive after fetching.
    unpack: tar
    # After the unpack, use this subdirectory as the root of the module.
    export: vim-pathogen-2.3/autoload/

curl module pathogen:
    url: https://codeload.github.com/tpope/vim-pathogen/tar.gz/v2.3
    auth:
        username: whatever
        password: whywouldyouputthathere
    # Untar the archive after fetching.
    unpack: tar
    # After the unpack, use this subdirectory as the root of the module.
    export: vim-pathogen-2.3/autoload/

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
colindeancommented, Oct 30, 2018

I’ll see what I can drum up!

0reactions
felipefozcommented, Aug 31, 2021

It seems that I lost in this one.

Let’s see how it goes then. I will try to work on something in the next few days.

About the alias, I am opening another issue mentioning this discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using cURL with a username and password? - Stack Overflow
Use the -u flag to include a username, and curl will prompt for a password: curl -u username http://example.com.
Read more >
Help! How do you use cURL to download a file with a ...
I am trying to figure out how to use the cURL command to download that file. I can use cURL to download fine...
Read more >
Tutorial - curl
Curl also supports user and password in HTTP URLs, thus you can pick a file like: curl http://name:passwd@machine.domain/full/path/to/file.
Read more >
Sending Curl Request with Credentials - ReqBin
To make a Curl request with Credentials, you need to use the --user "username:password" command line parameter and pass the username and ......
Read more >
Linux / Unix curl Command Download File Example - nixCraft
Proxy support. User ... Allows you to provide your private key in this separate file. ... Curl: Download a file using username and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found