1package resource
2
3import (
4	"github.com/golang/protobuf/ptypes"
5
6	core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
7	listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
8	hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
9)
10
11// Resource types in xDS v3.
12const (
13	apiTypePrefix       = "type.googleapis.com/"
14	EndpointType        = apiTypePrefix + "envoy.config.endpoint.v3.ClusterLoadAssignment"
15	ClusterType         = apiTypePrefix + "envoy.config.cluster.v3.Cluster"
16	RouteType           = apiTypePrefix + "envoy.config.route.v3.RouteConfiguration"
17	ListenerType        = apiTypePrefix + "envoy.config.listener.v3.Listener"
18	SecretType          = apiTypePrefix + "envoy.extensions.transport_sockets.tls.v3.Secret"
19	ExtensionConfigType = apiTypePrefix + "envoy.config.core.v3.TypedExtensionConfig"
20	RuntimeType         = apiTypePrefix + "envoy.service.runtime.v3.Runtime"
21
22	// AnyType is used only by ADS
23	AnyType = ""
24)
25
26// Fetch urls in xDS v3.
27const (
28	FetchEndpoints        = "/v3/discovery:endpoints"
29	FetchClusters         = "/v3/discovery:clusters"
30	FetchListeners        = "/v3/discovery:listeners"
31	FetchRoutes           = "/v3/discovery:routes"
32	FetchSecrets          = "/v3/discovery:secrets"
33	FetchRuntimes         = "/v3/discovery:runtime"
34	FetchExtensionConfigs = "/v3/discovery:extension_configs"
35)
36
37// DefaultAPIVersion is the api version
38const DefaultAPIVersion = core.ApiVersion_V3
39
40// GetHTTPConnectionManager creates a HttpConnectionManager from filter
41func GetHTTPConnectionManager(filter *listener.Filter) *hcm.HttpConnectionManager {
42	config := &hcm.HttpConnectionManager{}
43
44	// use typed config if available
45	if typedConfig := filter.GetTypedConfig(); typedConfig != nil {
46		ptypes.UnmarshalAny(typedConfig, config)
47	}
48	return config
49}
50