// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig"

import (
	
	
	
	
	
	
	

	
)

// DefaultEnvOptionsReader is the default environments reader.
var DefaultEnvOptionsReader = envconfig.EnvOptionsReader{
	GetEnv:    os.Getenv,
	ReadFile:  os.ReadFile,
	Namespace: "OTEL_EXPORTER_OTLP",
}

// ApplyGRPCEnvConfigs applies the env configurations for gRPC.
func ( Config) Config {
	 := getOptionsFromEnv()
	for ,  := range  {
		 = .ApplyGRPCOption()
	}
	return 
}

// ApplyHTTPEnvConfigs applies the env configurations for HTTP.
func ( Config) Config {
	 := getOptionsFromEnv()
	for ,  := range  {
		 = .ApplyHTTPOption()
	}
	return 
}

func getOptionsFromEnv() []GenericOption {
	 := []GenericOption{}

	 := &tls.Config{}
	DefaultEnvOptionsReader.Apply(
		envconfig.WithURL("ENDPOINT", func( *url.URL) {
			 = append(, withEndpointScheme())
			 = append(, newSplitOption(func( Config) Config {
				.Traces.Endpoint = .Host
				// For OTLP/HTTP endpoint URLs without a per-signal
				// configuration, the passed endpoint is used as a base URL
				// and the signals are sent to these paths relative to that.
				.Traces.URLPath = path.Join(.Path, DefaultTracesPath)
				return 
			}, withEndpointForGRPC()))
		}),
		envconfig.WithURL("TRACES_ENDPOINT", func( *url.URL) {
			 = append(, withEndpointScheme())
			 = append(, newSplitOption(func( Config) Config {
				.Traces.Endpoint = .Host
				// For endpoint URLs for OTLP/HTTP per-signal variables, the
				// URL MUST be used as-is without any modification. The only
				// exception is that if an URL contains no path part, the root
				// path / MUST be used.
				 := .Path
				if  == "" {
					 = "/"
				}
				.Traces.URLPath = 
				return 
			}, withEndpointForGRPC()))
		}),
		envconfig.WithCertPool("CERTIFICATE", func( *x509.CertPool) { .RootCAs =  }),
		envconfig.WithCertPool("TRACES_CERTIFICATE", func( *x509.CertPool) { .RootCAs =  }),
		envconfig.WithClientCert(
			"CLIENT_CERTIFICATE",
			"CLIENT_KEY",
			func( tls.Certificate) { .Certificates = []tls.Certificate{} },
		),
		envconfig.WithClientCert(
			"TRACES_CLIENT_CERTIFICATE",
			"TRACES_CLIENT_KEY",
			func( tls.Certificate) { .Certificates = []tls.Certificate{} },
		),
		withTLSConfig(, func( *tls.Config) {  = append(, WithTLSClientConfig()) }),
		envconfig.WithBool("INSECURE", func( bool) {  = append(, withInsecure()) }),
		envconfig.WithBool("TRACES_INSECURE", func( bool) {  = append(, withInsecure()) }),
		envconfig.WithHeaders("HEADERS", func( map[string]string) {  = append(, WithHeaders()) }),
		envconfig.WithHeaders("TRACES_HEADERS", func( map[string]string) {  = append(, WithHeaders()) }),
		WithEnvCompression("COMPRESSION", func( Compression) {  = append(, WithCompression()) }),
		WithEnvCompression("TRACES_COMPRESSION", func( Compression) {  = append(, WithCompression()) }),
		envconfig.WithDuration("TIMEOUT", func( time.Duration) {  = append(, WithTimeout()) }),
		envconfig.WithDuration("TRACES_TIMEOUT", func( time.Duration) {  = append(, WithTimeout()) }),
	)

	return 
}

func withEndpointScheme( *url.URL) GenericOption {
	switch strings.ToLower(.Scheme) {
	case "http", "unix":
		return WithInsecure()
	default:
		return WithSecure()
	}
}

func withEndpointForGRPC( *url.URL) func( Config) Config {
	return func( Config) Config {
		// For OTLP/gRPC endpoints, this is the target to which the
		// exporter is going to send telemetry.
		.Traces.Endpoint = path.Join(.Host, .Path)
		return 
	}
}

// WithEnvCompression retrieves the specified config and passes it to ConfigFn as a Compression.
func ( string,  func(Compression)) func( *envconfig.EnvOptionsReader) {
	return func( *envconfig.EnvOptionsReader) {
		if ,  := .GetEnvValue();  {
			 := NoCompression
			if  == "gzip" {
				 = GzipCompression
			}

			()
		}
	}
}

// revive:disable-next-line:flag-parameter
func withInsecure( bool) GenericOption {
	if  {
		return WithInsecure()
	}
	return WithSecure()
}

func withTLSConfig( *tls.Config,  func(*tls.Config)) func( *envconfig.EnvOptionsReader) {
	return func( *envconfig.EnvOptionsReader) {
		if .RootCAs != nil || len(.Certificates) > 0 {
			()
		}
	}
}