internal/rpmmd: return helpful error message when subscriptions == nil

It can happen that the system is not subscribed and the user requests a
source with rhsm set to "true". Return useful error message in such case
informing the user what to do about it.
This commit is contained in:
Martin Sehnoutka 2021-06-09 09:20:46 +02:00 committed by msehnout
parent 04a62d677f
commit 1227633e7c

View file

@ -404,6 +404,9 @@ func (repo RepoConfig) toDNFRepoConfig(rpmmd *rpmmdImpl, i int, arch, releasever
MetadataExpire: repo.MetadataExpire,
}
if repo.RHSM {
if rpmmd.subscriptions == nil {
return dnfRepoConfig{}, fmt.Errorf("This system does not have any valid subscriptions. Subscribe it before specifying rhsm: true in sources.")
}
secrets, err := rpmmd.subscriptions.GetSecretsForBaseurl(repo.BaseURL, arch, releasever)
if err != nil {
return dnfRepoConfig{}, fmt.Errorf("RHSM secrets not found on the host for this baseurl: %s", repo.BaseURL)