Skip to content

Add auth_patterns support to RPM rule #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

type lockfileOpts struct {
repofiles []string
configname string
lockfile string
repofiles []string
configname string
lockfile string
}

var lockfileopts = lockfileOpts{}
Expand All @@ -22,7 +22,7 @@ func NewLockFileCmd() *cobra.Command {
lockfileCmd := &cobra.Command{
Use: "lockfile",
Short: "Manage bazeldnf lock file",
Long: `Keep the bazeldnf lock file up to date using a set of dependencies`,
Long: `Keep the bazeldnf lock file up to date using a set of dependencies`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, required []string) error {
repos, err := repo.LoadRepoFiles(lockfileopts.repofiles)
Expand Down
2 changes: 1 addition & 1 deletion cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type resolveOpts struct {
repofiles []string
repofiles []string
}

var resolveopts = resolveOpts{}
Expand Down
16 changes: 8 additions & 8 deletions cmd/rpmtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
)

type rpmtreeOpts struct {
repofiles []string
workspace string
toMacro string
buildfile string
configname string
lockfile string
name string
public bool
repofiles []string
workspace string
toMacro string
buildfile string
configname string
lockfile string
name string
public bool
}

var rpmtreeopts = rpmtreeOpts{}
Expand Down
12 changes: 11 additions & 1 deletion internal/rpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"Exposes rpm files to a Bazel workspace"

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

RpmInfo = provider(
doc = """\
Expand All @@ -29,6 +29,14 @@ RpmInfo = provider(
},
)

def _get_auth(ctx, urls):
"""Given the list of URLs obtain the correct auth dict."""
if "NETRC" in ctx.os.environ:
netrc = read_netrc(ctx, ctx.os.environ["NETRC"])
else:
netrc = read_user_netrc(ctx)
return use_netrc(netrc, urls, ctx.attr.auth_patterns)

def _rpm_rule_impl(ctx):
"""\
Implementation for the rpm rule
Expand Down Expand Up @@ -82,6 +90,7 @@ def _rpm_impl(ctx):
ctx.download(
url = ctx.attr.urls,
output = "rpm/" + downloaded_file_path,
auth = _get_auth(ctx, ctx.attr.urls),
**args
)
else:
Expand All @@ -104,6 +113,7 @@ _rpm_attrs = {
mandatory = False,
providers = [RpmInfo],
),
"auth_patterns": attr.string_dict(),
}

rpm = repository_rule(
Expand Down
2 changes: 1 addition & 1 deletion pkg/reducer/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/rmohr/bazeldnf/pkg/api/bazeldnf"
)

func withRepository(packages []api.Package) []api.Package{
func withRepository(packages []api.Package) []api.Package {
r := []api.Package{}
for _, p := range packages {
p.Repository = &bazeldnf.Repository{}
Expand Down
12 changes: 6 additions & 6 deletions pkg/sat/sat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,9 +1354,9 @@ func TestNewResolver(t *testing.T) {
"testa",
},
ignoreRegex: []string{"testb.*"},
install: []string{"testa-0:1", "testc-0:1"},
exclude: []string{},
solvable: true,
install: []string{"testa-0:1", "testc-0:1"},
exclude: []string{},
solvable: true,
},
{name: "only allow package", packages: []*api.Package{
newPkg("testa", "1", []string{}, []string{"b", "c"}, []string{}),
Expand All @@ -1366,9 +1366,9 @@ func TestNewResolver(t *testing.T) {
"testa",
},
allowRegex: []string{"testa.*"},
install: []string{"testa-0:1"},
exclude: []string{},
solvable: true,
install: []string{"testa-0:1"},
exclude: []string{},
solvable: true,
},
// TODO: Add test cases.
}
Expand Down
Loading