// GetProxyOpts validates and returns the given proxy handler options
GetProxyOpts validates and returns the given proxy handler options
// GetProxyOpts validates and returns the given proxy handler options
func GetProxyOpts(
	upstreamAddr string,
	upstreamAuthClient dockerregistryproxyv1.AuthenticationProviderAPIClient,
	authVerifiers map[string]dockerregistryproxyv1.AuthenticationVerifierAPIClient,
) (*ProxyOpts, error) {
	opts := &ProxyOpts{
		Transport: NewRedirectFollower(transport.NewRetry(http.DefaultTransport)),
	}
	upstreamURI, err := url.Parse(upstreamAddr)
	if err != nil {
		return nil, fmt.Errorf("could not parse upstream: %w", err)
	}
	if len(upstreamURI.Host) < 1 {
		return nil, ErrUpstreamCouldNotParseHost
	}
	opts.Upstream = upstreamURI
	registryOpts := []name.Option{}
	if upstreamURI.Scheme == "http" {
		registryOpts = append(registryOpts, name.Insecure)
	}
	r, err := name.NewRegistry(opts.Upstream.Host, registryOpts...)
	if err != nil {
		return nil, fmt.Errorf("could not parse registry: %w", err)
	}
	opts.Registry = r
	if upstreamAuthClient != nil {
		auth, err := RegistryAuthResolveGRPC(upstreamAuthClient)
		if err != nil {
			return nil, fmt.Errorf("could not resolve auth: %w", err)
		}
		opts.Auth = auth
	} else {
		defAuth, err := authn.DefaultKeychain.Resolve(r)
		if err != nil {
			return nil, fmt.Errorf("could not resolve default keychain auth: %w", err)
		}
		opts.Auth = defAuth
	}
	opts.AuthVerifiers = authVerifiers
	return opts, nil
}
func GetProxyOpts ( upstreamAddr string , upstreamAuthClient dockerregistryproxyv1 . AuthenticationProviderAPIClient , authVerifiers map [ string ] dockerregistryproxyv1 . AuthenticationVerifierAPIClient , ) ( * ProxyOpts , error ) { opts := & ProxyOpts { Transport : NewRedirectFollower ( transport . NewRetry ( http . DefaultTransport ) ) , } upstreamURI , err := url . Parse ( upstreamAddr ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if len ( upstreamURI . Host ) < 1 { return nil , ErrUpstreamCouldNotParseHost } opts . Upstream = upstreamURI registryOpts := [ ] name . Option { } if upstreamURI . Scheme == " " { registryOpts = append ( registryOpts , name . Insecure ) } r , err := name . NewRegistry ( opts . Upstream . Host , registryOpts ... ) if err != nil { return nil , fmt . Errorf ( " " , err ) } opts . Registry = r if upstreamAuthClient != nil { auth , err := RegistryAuthResolveGRPC ( upstreamAuthClient ) if err != nil { return nil , fmt . Errorf ( " " , err ) } opts . Auth = auth } else { defAuth , err := authn . DefaultKeychain . Resolve ( r ) if err != nil { return nil , fmt . Errorf ( " " , err ) } opts . Auth = defAuth } opts . AuthVerifiers = authVerifiers return opts , nil }
GetProxyOpts validates and returns the given proxy handler options
GetProxyOpts validates and returns the given proxy handler options