github.com/tetratelabs/proxy-wasm-go-sdk@v0.23.1-0.20240517021853-021aa9cf78e8/properties/types.go (about) 1 package properties 2 3 import "fmt" 4 5 // EnvoyTrafficDirection identifies the direction of the traffic relative to the local Envoy. 6 // 7 // https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/base.proto#enum-config-core-v3-trafficdirection 8 type EnvoyTrafficDirection int 9 10 const ( 11 // EnvoyTrafficDirectionUnspecified means that the direction is not specified. 12 EnvoyTrafficDirectionUnspecified EnvoyTrafficDirection = iota 13 // EnvoyTrafficDirectionInbound means that the transport is used for incoming traffic. 14 EnvoyTrafficDirectionInbound 15 // EnvoyTrafficDirectionOutbound means that the transport is used for outgoing traffic. 16 EnvoyTrafficDirectionOutbound 17 ) 18 19 // String converts the EnvoyTrafficDirection enum value to its corresponding string representation. 20 // It returns "UNSPECIFIED" for Unspecified, "INBOUND" for Inbound, and "OUTBOUND" for Outbound. 21 // If the enum value doesn't match any of the predefined values, it defaults to "UNSPECIFIED". 22 func (t EnvoyTrafficDirection) String() string { 23 switch t { 24 case EnvoyTrafficDirectionUnspecified: 25 return "UNSPECIFIED" 26 case EnvoyTrafficDirectionInbound: 27 return "INBOUND" 28 case EnvoyTrafficDirectionOutbound: 29 return "OUTBOUND" 30 } 31 return "UNSPECIFIED" 32 } 33 34 // EnvoyLocality identifies location of where either Envoy runs or where upstream hosts run. 35 // 36 // https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/base.proto#config-core-v3-locality 37 type EnvoyLocality struct { 38 Region string 39 Zone string 40 Subzone string 41 } 42 43 // EnvoyExtension holds version and identification for an Envoy extension. 44 // 45 // https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/base.proto#config-core-v3-extension 46 type EnvoyExtension struct { 47 Name string 48 Category string 49 TypeUrls []string 50 } 51 52 // IstioFilterMetadata provides additional inputs to filters based on matched listeners, 53 // filter chains, routes and endpoints. It is structured as a map, usually from 54 // filter name (in reverse DNS format) to metadata specific to the filter. Metadata 55 // key-values for a filter are merged as connection and request handling occurs, 56 // with later values for the same key overriding earlier values. 57 // 58 // https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/base.proto#config-core-v3-metadata 59 type IstioFilterMetadata struct { 60 Config string 61 Services []IstioService 62 } 63 64 // IstioService holds information of the host, name and namespace of an Istio Service. 65 type IstioService struct { 66 Host string 67 Name string 68 Namespace string 69 } 70 71 // IstioProxyStatsMatcher holds proxy stats name matches for stats creation. Note this is in addition to the minimum Envoy stats that 72 // Istio generates by default. 73 // 74 // https://istio.io/latest/docs/reference/config/istio.mesh.v1alpha1/#ProxyConfig-ProxyStatsMatcher 75 type IstioProxyStatsMatcher struct { 76 InclusionPrefixes []string 77 InclusionRegexps []string 78 InclusionSuffixes []string 79 } 80 81 // IstioTrafficInterceptionMode indicates how traffic to/from the workload is captured and sent to Envoy. This 82 // should not be confused with the CaptureMode in the API that indicates how the user wants traffic to be 83 // intercepted for the listener. IstioTrafficInterceptionMode is always derived from the Proxy metadata. 84 // 85 // https://pkg.go.dev/istio.io/istio/pilot/pkg/model#TrafficInterceptionMode 86 type IstioTrafficInterceptionMode int 87 88 const ( 89 // IstioTrafficInterceptionModeNone indicates that the workload is not using IPtables for traffic interception. 90 IstioTrafficInterceptionModeNone IstioTrafficInterceptionMode = iota 91 // IstioTrafficInterceptionModeTproxy implies traffic intercepted by IPtables with TPROXY mode. 92 IstioTrafficInterceptionModeTproxy 93 // IstioTrafficInterceptionModeRedirect implies traffic intercepted by IPtables with REDIRECT mode. This is our default mode. 94 IstioTrafficInterceptionModeRedirect 95 ) 96 97 // String converts the IstioTrafficInterceptionMode enum value to its corresponding string representation. 98 // It returns "NONE" for None, "TPROXY" for Tproxy, and "REDIRECT" for Redirect. 99 // If the enum value doesn't match any of the predefined values, it defaults to "REDIRECT". 100 func (t IstioTrafficInterceptionMode) String() string { 101 switch t { 102 case IstioTrafficInterceptionModeNone: 103 return "NONE" 104 case IstioTrafficInterceptionModeTproxy: 105 return "TPROXY" 106 case IstioTrafficInterceptionModeRedirect: 107 return "REDIRECT" 108 } 109 return "REDIRECT" 110 } 111 112 // ParseIstioTrafficInterceptionMode converts a string representation of IstioTrafficInterceptionMode to 113 // its corresponding enum value. It returns None for "NONE", Tproxy for "TPROXY", and Redirect for "REDIRECT". 114 // If the provided string doesn't match any of the predefined values, it returns an error and the default 115 // value Redirect. 116 func ParseIstioTrafficInterceptionMode(s string) (IstioTrafficInterceptionMode, error) { 117 switch s { 118 case "NONE": 119 return IstioTrafficInterceptionModeNone, nil 120 case "TPROXY": 121 return IstioTrafficInterceptionModeTproxy, nil 122 case "REDIRECT": 123 return IstioTrafficInterceptionModeRedirect, nil 124 default: 125 return IstioTrafficInterceptionModeRedirect, fmt.Errorf("invalid IstioTrafficInterceptionMode: %s", s) 126 } 127 }