cloudapi: Use distro repos if none included in imageRequest

In order to support cloudapi blueprint requests from the cmdline using
composer-cli it needs to select the repositories based on the selected
distribution instead of requiring the user to include them with the
request.

If the image request includes repositories they are used, which matches
the current behavior. If the repository list is empty it will use the
distribution name to select from the repositories shipped with
osbuild-composer.
This commit is contained in:
Brian C. Lane 2024-02-02 17:17:49 -08:00 committed by Brian C. Lane
parent 01ba674cac
commit 57ebfb4011
4 changed files with 49 additions and 12 deletions

View file

@ -4,16 +4,17 @@ package v2
import (
"crypto/rand"
"fmt"
"github.com/osbuild/images/pkg/distrofactory"
"github.com/osbuild/images/pkg/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/target"
"math"
"math/big"
"reflect"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distrofactory"
"github.com/osbuild/images/pkg/reporegistry"
"github.com/osbuild/images/pkg/rhsm/facts"
"github.com/osbuild/images/pkg/subscription"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/target"
)
// Return the string representation of the partitioning mode
@ -944,7 +945,7 @@ func (request *ComposeRequest) GetPartitioningMode() (disk.PartitioningMode, err
// GetImageRequests converts a composeRequest structure from the API to an intermediate imageRequest structure
// that's used for generating manifests and orchestrating worker jobs.
func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Factory) ([]imageRequest, error) {
func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Factory, repoRegistry *reporegistry.RepoRegistry) ([]imageRequest, error) {
distribution := distroFactory.GetDistro(request.Distribution)
if distribution == nil {
return nil, HTTPError(ErrorUnsupportedDistribution)
@ -1002,6 +1003,15 @@ func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Fac
return nil, err
}
// If no repositories are included with the imageRequest use the defaults for the distro
if len(ir.Repositories) == 0 {
dr, err := repoRegistry.ReposByImageTypeName(request.Distribution, arch.Name(), imageType.Name())
if err != nil {
return nil, err
}
repos = append(repos, dr...)
}
// Get the initial ImageOptions with image size set
imageOptions := ir.GetImageOptions(imageType, bp)