Skip to content

Commit

Permalink
dnfjson: support dnf base config proxy option
Browse files Browse the repository at this point in the history
`dnf-json` can add this proxy to its base config when depsolving.
  • Loading branch information
croissanne committed Apr 12, 2024
1 parent 9b91fba commit 3df3650
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -142,6 +143,9 @@ type Solver struct {

rootDir string

// Proxy to use while depsolving. This is used in DNF's base configuration.
proxy string

subscriptions *rhsm.Subscriptions
}

Expand Down Expand Up @@ -170,6 +174,15 @@ func (s *Solver) GetCacheDir() string {
return filepath.Join(s.cache.root, b)
}

// Set the proxy to use while depsolving. The proxy will be set in DNF's base configuration.
func (s *Solver) SetProxy(proxy string) error {
if _, err := url.ParseRequestURI(proxy); err != nil {
return fmt.Errorf("proxy URL %q is invalid", proxy)
}
s.proxy = proxy
return nil
}

// Depsolve the list of required package sets with explicit excludes using
// their associated repositories. Each package set is depsolved as a separate
// transactions in a chain. It returns a list of all packages (with solved
Expand Down Expand Up @@ -453,6 +466,7 @@ func (s *Solver) makeDepsolveRequest(pkgSets []rpmmd.PackageSet) (*Request, map[
Arch: s.arch,
Releasever: s.releaseVer,
CacheDir: s.GetCacheDir(),
Proxy: s.proxy,
Arguments: args,
}

Expand All @@ -471,6 +485,7 @@ func (s *Solver) makeDumpRequest(repos []rpmmd.RepoConfig) (*Request, error) {
Arch: s.arch,
Releasever: s.releaseVer,
CacheDir: s.GetCacheDir(),
Proxy: s.proxy,
Arguments: arguments{
Repos: dnfRepos,
},
Expand All @@ -490,6 +505,7 @@ func (s *Solver) makeSearchRequest(repos []rpmmd.RepoConfig, packages []string)
Arch: s.arch,
CacheDir: s.GetCacheDir(),
Releasever: s.releaseVer,
Proxy: s.proxy,
Arguments: arguments{
Repos: dnfRepos,
Search: searchArgs{
Expand Down Expand Up @@ -579,6 +595,9 @@ type Request struct {
// Cache directory for the DNF metadata
CacheDir string `json:"cachedir"`

// Proxy to use
Proxy string `json:"proxy"`

// Arguments for the action defined by Command
Arguments arguments `json:"arguments"`
}
Expand Down

0 comments on commit 3df3650

Please sign in to comment.