func()

in functionaltests/internal/ecclient/client.go [155:201]


func (c *Client) getVersionInfos(
	ctx context.Context,
	region string,
	showUnusable bool,
	preFilter func(*models.StackVersionConfig) bool, // Filter before conversion
	postFilter func(StackVersion) bool, // Filter after conversion
) (StackVersionInfos, error) {
	showDeleted := false
	resp, err := c.ecAPI.V1API.Stack.GetVersionStacks(
		// Add region to get the stack versions for that region only
		stack.NewGetVersionStacksParamsWithContext(api.WithRegion(ctx, region)).
			WithShowDeleted(&showDeleted).
			WithShowUnusable(&showUnusable),
		c.ecAPI.AuthWriter,
	)
	if err != nil {
		return nil, fmt.Errorf("cannot retrieve stack versions: %w", err)
	}

	if resp.Payload == nil || len(resp.Payload.Stacks) == 0 {
		return nil, errors.New("stack versions response payload is empty")
	}

	versionInfos := make(StackVersionInfos, 0, len(resp.Payload.Stacks))
	for _, s := range resp.Payload.Stacks {
		if preFilter != nil && !preFilter(s) {
			continue
		}
		v, err := NewStackVersionFromStr(s.Version)
		if err != nil {
			return nil, fmt.Errorf("cannot parse stack version '%v': %w", s.Version, err)
		}
		if postFilter == nil || postFilter(v) {
			upgradableTo, err := sortedStackVersionsForStrs(s.UpgradableTo)
			if err != nil {
				return nil, fmt.Errorf("cannot parse upgradable to for '%v': %w", s.Version, err)
			}
			versionInfos = append(versionInfos, StackVersionInfo{
				Version:      v,
				UpgradableTo: upgradableTo,
			})
		}
	}

	versionInfos.Sort()
	return versionInfos, nil
}