// ProviderVersions returns the raw version and protocol strings produced by the
// registry for the given provider.
//
// The returned error will be ErrRegistryProviderNotKnown if the registry responds with
// 404 Not Found to indicate that the namespace or provider type are not known,
// ErrUnauthorized if the registry responds with 401 or 403 status codes, or
// ErrQueryFailed for any other protocol or operational problem.
ProviderVersions returns the raw version and protocol strings produced by the
registry for the given provider.

The returned error will be ErrRegistryProviderNotKnown if the registry responds with
404 Not Found to indicate that the namespace or provider type are not known,
ErrUnauthorized if the registry responds with 401 or 403 status codes, or
ErrQueryFailed for any other protocol or operational problem.
// ProviderVersions returns the raw version and protocol strings produced by the // registry for the given provider . // // The returned error will be ErrRegistryProviderNotKnown if the registry responds with // 404 Not Found to indicate that the namespace or provider type are not known // ErrUnauthorized if the registry responds with 401 or 403 status codes or // ErrQueryFailed for any other protocol or operational problem .
func (c *registryClient) ProviderVersions(ctx context.Context, addr addrs.Provider) (map[string][]string, []string, error) {
	endpointPath, err := url.Parse(path.Join(addr.Namespace, addr.Type, "versions"))
	if err != nil {
		return nil, nil, err
	}
	endpointURL := c.baseURL.ResolveReference(endpointPath)
	req, err := retryablehttp.NewRequest("GET", endpointURL.String(), nil)
	if err != nil {
		return nil, nil, err
	}
	req = req.WithContext(ctx)
	c.addHeadersToRequest(req.Request)
	resp, err := c.httpClient.Do(req)
	if err != nil {
		return nil, nil, c.errQueryFailed(addr, err)
	}
	defer resp.Body.Close()
	switch resp.StatusCode {
	case http.StatusOK:
	case http.StatusNotFound:
		return nil, nil, ErrRegistryProviderNotKnown{
			Provider: addr,
		}
	case http.StatusUnauthorized, http.StatusForbidden:
		return nil, nil, c.errUnauthorized(addr.Hostname)
	default:
		return nil, nil, c.errQueryFailed(addr, errors.New(resp.Status))
	}
	type ResponseBody struct {
		Versions []struct {
			Version   string   `json:"version"`
			Protocols []string `json:"protocols"`
		} `json:"versions"`
		Warnings []string `json:"warnings"`
	}
	var body ResponseBody
	dec := json.NewDecoder(resp.Body)
	if err := dec.Decode(&body); err != nil {
		return nil, nil, c.errQueryFailed(addr, err)
	}
	if len(body.Versions) == 0 {
		return nil, body.Warnings, nil
	}
	ret := make(map[string][]string, len(body.Versions))
	for _, v := range body.Versions {
		ret[v.Version] = v.Protocols
	}
	return ret, body.Warnings, nil
}
func ( c * registryClient ) ProviderVersions ( ctx context . Context , addr addrs . Provider ) ( map [ string ] [ ] string , [ ] string , error ) { endpointPath , err := url . Parse ( path . Join ( addr . Namespace , addr . Type , " " ) ) if err != nil { return nil , nil , err } endpointURL := c . baseURL . ResolveReference ( endpointPath ) req , err := retryablehttp . NewRequest ( " " , endpointURL . String ( ) , nil ) if err != nil { return nil , nil , err } req = req . WithContext ( ctx ) c . addHeadersToRequest ( req . Request ) resp , err := c . httpClient . Do ( req ) if err != nil { return nil , nil , c . errQueryFailed ( addr , err ) } defer resp . Body . Close ( ) switch resp . StatusCode { case http . StatusOK : case http . StatusNotFound : return nil , nil , ErrRegistryProviderNotKnown { Provider : addr , } case http . StatusUnauthorized , http . StatusForbidden : return nil , nil , c . errUnauthorized ( addr . Hostname ) default : return nil , nil , c . errQueryFailed ( addr , errors . New ( resp . Status ) ) } type ResponseBody struct { Versions [ ] struct { Version string `json:"version"` Protocols [ ] string `json:"protocols"` } `json:"versions"` Warnings [ ] string `json:"warnings"` } var body ResponseBody dec := json . NewDecoder ( resp . Body ) if err := dec . Decode ( & body ) ; err != nil { return nil , nil , c . errQueryFailed ( addr , err ) } if len ( body . Versions ) == 0 { return nil , body . Warnings , nil } ret := make ( map [ string ] [ ] string , len ( body . Versions ) ) for _ , v := range body . Versions { ret [ v . Version ] = v . Protocols } return ret , body . Warnings , nil }
ProviderVersions returns the raw version and protocol strings produced by the
registry for the given provider.
ProviderVersions returns the raw version and protocol strings produced by the registry for the given provider .
// Should never happen because we're constructing this from // already-validated components. // Great! // We ignore the platforms portion of the response body, because the // installer verifies the platform compatibility after pulling a provider // versions' metadata.