// findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match.
findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match.
// findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match .
func (c *registryClient) findClosestProtocolCompatibleVersion(ctx context.Context, provider addrs.Provider, version Version) (Version, error) {
	var match Version
	available, _, err := c.ProviderVersions(ctx, provider)
	if err != nil {
		return UnspecifiedVersion, err
	}
	versionList := make(VersionList, 0, len(available))
	for versionStr := range available {
		v, err := ParseVersion(versionStr)
		if err != nil {
			return UnspecifiedVersion, ErrQueryFailed{
				Provider: provider,
				Wrapped:  fmt.Errorf("registry response includes invalid version string %q: %s", versionStr, err),
			}
		}
		versionList = append(versionList, v)
	}
	versionList.Sort() 
	protoVersions := MeetingConstraints(SupportedPluginProtocols)
FindMatch:
	for index := len(versionList) - 1; index >= 0; index-- { 
		for _, protoStr := range available[versionList[index].String()] {
			p, err := ParseVersion(protoStr)
			if err != nil {
				return UnspecifiedVersion, ErrQueryFailed{
					Provider: provider,
					Wrapped:  fmt.Errorf("registry response includes invalid protocol string %q: %s", protoStr, err),
				}
			}
			if protoVersions.Has(p) {
				match = versionList[index]
				break FindMatch
			}
		}
	}
	return match, nil
}
func ( c * registryClient ) findClosestProtocolCompatibleVersion ( ctx context . Context , provider addrs . Provider , version Version ) ( Version , error ) { var match Version available , _ , err := c . ProviderVersions ( ctx , provider ) if err != nil { return UnspecifiedVersion , err } versionList := make ( VersionList , 0 , len ( available ) ) for versionStr := range available { v , err := ParseVersion ( versionStr ) if err != nil { return UnspecifiedVersion , ErrQueryFailed { Provider : provider , Wrapped : fmt . Errorf ( " " , versionStr , err ) , } } versionList = append ( versionList , v ) } versionList . Sort ( ) protoVersions := MeetingConstraints ( SupportedPluginProtocols ) FindMatch : for index := len ( versionList ) - 1 ; index >= 0 ; index -- { for _ , protoStr := range available [ versionList [ index ] . String ( ) ] { p , err := ParseVersion ( protoStr ) if err != nil { return UnspecifiedVersion , ErrQueryFailed { Provider : provider , Wrapped : fmt . Errorf ( " " , protoStr , err ) , } } if protoVersions . Has ( p ) { match = versionList [ index ] break FindMatch } } } return match , nil }
findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match.
findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match .
// extract the maps keys so we can make a sorted list of available versions. // lowest precedence first, preserving order when equal precedence // put the versions in increasing order of precedence // walk backwards to consider newer versions first