Skip to content

Commit 42855a2

Browse files
committed
Add auth_patterns support to RPM rule
Sometimes RPM rules are on non-private locations. Add .netrc support to RPM rules. Signed-off-by: Roman Mohr <rmohr@google.com>
1 parent 0e89202 commit 42855a2

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

cmd/lockfile.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
)
1111

1212
type lockfileOpts struct {
13-
repofiles []string
14-
configname string
15-
lockfile string
13+
repofiles []string
14+
configname string
15+
lockfile string
1616
}
1717

1818
var lockfileopts = lockfileOpts{}
@@ -22,7 +22,7 @@ func NewLockFileCmd() *cobra.Command {
2222
lockfileCmd := &cobra.Command{
2323
Use: "lockfile",
2424
Short: "Manage bazeldnf lock file",
25-
Long: `Keep the bazeldnf lock file up to date using a set of dependencies`,
25+
Long: `Keep the bazeldnf lock file up to date using a set of dependencies`,
2626
Args: cobra.MinimumNArgs(1),
2727
RunE: func(cmd *cobra.Command, required []string) error {
2828
repos, err := repo.LoadRepoFiles(lockfileopts.repofiles)

cmd/resolve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
type resolveOpts struct {
13-
repofiles []string
13+
repofiles []string
1414
}
1515

1616
var resolveopts = resolveOpts{}

cmd/rpmtree.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
)
1515

1616
type rpmtreeOpts struct {
17-
repofiles []string
18-
workspace string
19-
toMacro string
20-
buildfile string
21-
configname string
22-
lockfile string
23-
name string
24-
public bool
17+
repofiles []string
18+
workspace string
19+
toMacro string
20+
buildfile string
21+
configname string
22+
lockfile string
23+
name string
24+
public bool
2525
}
2626

2727
var rpmtreeopts = rpmtreeOpts{}

internal/rpm.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"Exposes rpm files to a Bazel workspace"
1616

17-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "update_attrs")
17+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "read_user_netrc", "update_attrs", "use_netrc")
1818

1919
RpmInfo = provider(
2020
doc = """\
@@ -29,6 +29,14 @@ RpmInfo = provider(
2929
},
3030
)
3131

32+
def _get_auth(ctx, urls):
33+
"""Given the list of URLs obtain the correct auth dict."""
34+
if "NETRC" in ctx.os.environ:
35+
netrc = read_netrc(ctx, ctx.os.environ["NETRC"])
36+
else:
37+
netrc = read_user_netrc(ctx)
38+
return use_netrc(netrc, urls, ctx.attr.auth_patterns)
39+
3240
def _rpm_rule_impl(ctx):
3341
"""\
3442
Implementation for the rpm rule
@@ -79,6 +87,7 @@ def _rpm_impl(ctx):
7987
output = "rpm/" + downloaded_file_path,
8088
sha256 = ctx.attr.sha256,
8189
integrity = ctx.attr.integrity,
90+
auth = _get_auth(ctx, ctx.attr.urls),
8291
)
8392
else:
8493
fail("urls must be specified")
@@ -100,6 +109,7 @@ _rpm_attrs = {
100109
mandatory = False,
101110
providers = [RpmInfo],
102111
),
112+
"auth_patterns": attr.string_dict(),
103113
}
104114

105115
rpm = repository_rule(

pkg/reducer/helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/rmohr/bazeldnf/pkg/api/bazeldnf"
66
)
77

8-
func withRepository(packages []api.Package) []api.Package{
8+
func withRepository(packages []api.Package) []api.Package {
99
r := []api.Package{}
1010
for _, p := range packages {
1111
p.Repository = &bazeldnf.Repository{}

pkg/sat/sat_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,9 @@ func TestNewResolver(t *testing.T) {
13541354
"testa",
13551355
},
13561356
ignoreRegex: []string{"testb.*"},
1357-
install: []string{"testa-0:1", "testc-0:1"},
1358-
exclude: []string{},
1359-
solvable: true,
1357+
install: []string{"testa-0:1", "testc-0:1"},
1358+
exclude: []string{},
1359+
solvable: true,
13601360
},
13611361
{name: "only allow package", packages: []*api.Package{
13621362
newPkg("testa", "1", []string{}, []string{"b", "c"}, []string{}),
@@ -1366,9 +1366,9 @@ func TestNewResolver(t *testing.T) {
13661366
"testa",
13671367
},
13681368
allowRegex: []string{"testa.*"},
1369-
install: []string{"testa-0:1"},
1370-
exclude: []string{},
1371-
solvable: true,
1369+
install: []string{"testa-0:1"},
1370+
exclude: []string{},
1371+
solvable: true,
13721372
},
13731373
// TODO: Add test cases.
13741374
}

0 commit comments

Comments
 (0)