Skip to content

Commit fd353aa

Browse files
feat: add NETRC read support for rb_bundle_fetch to support authentication to private rubygems registries (#222)
Taken from: bazelbuild/rules_rust#2623 Bazel 7.1.0 support for NETRC in utils: bazelbuild/bazel#20915
1 parent de4a1d9 commit fd353aa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ruby/private/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ bzl_library(
7474
":utils",
7575
"//ruby/private/bundle_fetch:gemfile_lock_parser",
7676
"@bazel_skylib//lib:versions",
77+
"@bazel_tools//tools/build_defs/repo:utils.bzl",
7778
],
7879
)
7980

ruby/private/bundle_fetch.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"Implementation details for rb_bundle_fetch"
22

33
load("@bazel_skylib//lib:versions.bzl", "versions")
4+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
45
load("//ruby/private:bundler_checksums.bzl", "BUNDLER_CHECKSUMS")
56
load(
67
"//ruby/private:utils.bzl",
@@ -63,7 +64,7 @@ def _download_gem(repository_ctx, gem, cache_path, sha256 = None):
6364
kwargs = {}
6465
if sha256:
6566
kwargs["sha256"] = sha256
66-
download = repository_ctx.download(url = url, output = "%s/%s" % (cache_path, gem.filename), **kwargs)
67+
download = repository_ctx.download(url = url, output = "%s/%s" % (cache_path, gem.filename), auth = get_auth(repository_ctx, [url]), **kwargs)
6768
return download.sha256
6869

6970
def _get_gem_executables(repository_ctx, gem, cache_path):
@@ -276,6 +277,12 @@ rb_bundle_fetch = repository_rule(
276277
allow_single_file = True,
277278
default = "@rules_ruby//:ruby/private/bundle_fetch/bin/BUILD.tpl",
278279
),
280+
"auth_patterns": attr.string_dict(
281+
doc = "A list of patterns to match against urls for which the auth object should be used.",
282+
),
283+
"netrc": attr.string(
284+
doc = "Path to .netrc file to read credentials from",
285+
),
279286
},
280287
doc = """
281288
Fetches Bundler dependencies to be automatically installed by other targets.

0 commit comments

Comments
 (0)