mirror of https://github.com/hashicorp/consul
62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
|
// Copyright (c) HashiCorp, Inc.
|
||
|
// SPDX-License-Identifier: MPL-2.0
|
||
|
|
||
|
package extensioncommon
|
||
|
|
||
|
import (
|
||
|
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
|
||
|
envoy_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
|
||
|
envoy_http_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
|
||
|
envoy_tls_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
|
||
|
"google.golang.org/protobuf/proto"
|
||
|
"google.golang.org/protobuf/types/known/anypb"
|
||
|
)
|
||
|
|
||
|
// MakeUpstreamTLSTransportSocket generates an Envoy transport socket for the given TLS context.
|
||
|
func MakeUpstreamTLSTransportSocket(tlsContext *envoy_tls_v3.UpstreamTlsContext) (*envoy_core_v3.TransportSocket, error) {
|
||
|
if tlsContext == nil {
|
||
|
return nil, nil
|
||
|
}
|
||
|
return MakeTransportSocket("tls", tlsContext)
|
||
|
}
|
||
|
|
||
|
// MakeTransportSocket generates an Envoy transport socket from the given proto message.
|
||
|
func MakeTransportSocket(name string, config proto.Message) (*envoy_core_v3.TransportSocket, error) {
|
||
|
any, err := anypb.New(config)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &envoy_core_v3.TransportSocket{
|
||
|
Name: name,
|
||
|
ConfigType: &envoy_core_v3.TransportSocket_TypedConfig{
|
||
|
TypedConfig: any,
|
||
|
},
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
|
// MakeEnvoyHTTPFilter generates an Envoy HTTP filter from the given proto message.
|
||
|
func MakeEnvoyHTTPFilter(name string, cfg proto.Message) (*envoy_http_v3.HttpFilter, error) {
|
||
|
any, err := anypb.New(cfg)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &envoy_http_v3.HttpFilter{
|
||
|
Name: name,
|
||
|
ConfigType: &envoy_http_v3.HttpFilter_TypedConfig{TypedConfig: any},
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
|
// MakeFilter generates an Envoy listener filter from the given proto message.
|
||
|
func MakeFilter(name string, cfg proto.Message) (*envoy_listener_v3.Filter, error) {
|
||
|
any, err := anypb.New(cfg)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &envoy_listener_v3.Filter{
|
||
|
Name: name,
|
||
|
ConfigType: &envoy_listener_v3.Filter_TypedConfig{TypedConfig: any},
|
||
|
}, nil
|
||
|
}
|