How to specify credentials for http_archive *within* the workspace?

Viewed 413

I would like to specify credentials for a single URL in http_archive, using a netrc file contained in my workspace. I have tried the following without success:

  1. I have tried to specify the "userinfo" part of my URL like http://<user>:<password>@host/path just to get an authentication error.
  2. I have tinkered with the netrc attribute of http_archive, but I can only see, how to use absolute pathnames there; I would prefer to include the netrc in my workspace.

Do I have to write my own repository rule or is there another way?

2 Answers

In the meantime, I have created my own repository rule because I could not find a simple alternative. That went well, but comprehensive documentation for repository_ctx.download_and_extract is lacking, so it turned out to be trial and error ;-).

Take a look at this PR named "Readd support for authentication and .netrc". It seems to contain a improved version of the http_archive that supports .netrc files.

def _http_archive_impl(ctx):
    ...
    "netrc": attr.string(
        doc = "Location of the .netrc file to use for authentication",
    ),
    ...

I do not know the current status of this feature - maybe its already part of the newest Bazel version (at the time of writing this post 3.4.1)

Related