Skip to content
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

Add allow-list support to resolve and rpmtree #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewResolveCmd() *cobra.Command {
resolveCmd.Flags().BoolVarP(&resolveopts.nobest, "nobest", "n", false, "allow picking versions which are not the newest")
resolveCmd.Flags().StringArrayVarP(&resolveopts.repofiles, "repofile", "r", []string{"repo.yaml"}, "repository information file. Can be specified multiple times. Will be used by default if no explicit inputs are provided.")
resolveCmd.Flags().StringArrayVar(&resolveopts.forceIgnoreRegex, "force-ignore-with-dependencies", []string{}, "Packages matching these regex patterns will not be installed. Allows force-removing unwanted dependencies. Be careful, this can lead to hidden missing dependencies.")
resolveCmd.Flags().StringArrayVar(&resolveopts.onlyAllowRegex, "only-allow", []string{}, "Packages matching these regex patterns may be installed. Allows scoping dependencies. Be careful, this can lead to hidden missing dependencies.")
resolveCmd.Flags().StringArrayVar(&resolveopts.onlyAllowRegex, "only-allow", []string{}, "Packages matching these regex patterns may be installed. Allows limiting the dependency scope. Be careful, this can lead to hidden missing dependencies.")
// deprecated options
resolveCmd.Flags().StringVarP(&resolveopts.baseSystem, "fedora-base-system", "f", "fedora-release-container", "base system to use (e.g. fedora-release-server, centos-stream-release, ...)")
resolveCmd.Flags().MarkDeprecated("fedora-base-system", "use --basesystem instead")
Expand Down
35 changes: 20 additions & 15 deletions pkg/sat/sat.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func (r *Resolver) ticket() string {
return "x" + strconv.Itoa(r.varsCount)
}

// LoadInvolvedPackages takes a list of all involved packages to install, as well as a list of regular
// expressions which denote packages which should be taken into account for solving the problem, but they
// should then be ignored together with their requirements in the provided list of installed packages.
// Additionally, we can take a list of packages that the maximum selection desired.
// LoadInvolvedPackages takes a list of all involved packages to install, a list of regular expressions
// which denote packages which should be taken into account for solving the problem, but they should
// then be ignored together with their requirements in the provided list of installed packages, and also
// a list of regular expressions that may be used to limit the selection to matching packages.
kellyma2 marked this conversation as resolved.
Show resolved Hide resolved
func (r *Resolver) LoadInvolvedPackages(packages []*api.Package, ignoreRegex []string, allowRegex []string) error {
// Deduplicate and detect excludes
deduplicated := map[string]*api.Package{}
Expand All @@ -117,33 +117,38 @@ func (r *Resolver) LoadInvolvedPackages(packages []*api.Package, ignoreRegex []s
}
fullName := pkg.String()
if _, exists := deduplicated[fullName]; !exists {
matchedAllow := len(allowRegex) == 0

allowed := len(allowRegex) == 0
for _, rex := range allowRegex {
if match, err := regexp.MatchString(rex, fullName); err != nil {
return fmt.Errorf("failed to match package with regex '%v': %v", rex, err)
} else if match {
matchedAllow = true
allowed = true
break
}
}

if !matchedAllow {
packages[i].Format.Requires.Entries = nil
logrus.Warnf("Package %v does not match allow list", pkg.String())
r.forceIgnoreWithDependencies[pkg.String()] = packages[i]
} else {
ignored := len(ignoreRegex) == 0
if allowed {
for _, rex := range ignoreRegex {
if match, err := regexp.MatchString(rex, fullName); err != nil {
return fmt.Errorf("failed to match package with regex '%v': %v", rex, err)
} else if match {
packages[i].Format.Requires.Entries = nil
logrus.Warnf("Package %v is forcefully ignored by regex '%v'.", pkg.String(), rex)
r.forceIgnoreWithDependencies[pkg.String()] = packages[i]
ignored = true
break
}
}
}


if !allowed {
logrus.Warnf("Package %v is not explicitly allowed", pkg.String())
}

if !allowed || ignored {
packages[i].Format.Requires.Entries = nil
r.forceIgnoreWithDependencies[pkg.String()] = packages[i]
}

deduplicated[pkg.String()] = packages[i]
}
}
Expand Down