github.com/tetratelabs/proxy-wasm-go-sdk@v0.23.1-0.20240517021853-021aa9cf78e8/properties/upstream.go (about)

     1  package properties
     2  
     3  // This file hosts helper functions to retrieve upstream-related properties as described in:
     4  // https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes#upstream-attributes
     5  
     6  var (
     7  	upstreamAddress                     = []string{"upstream", "address"}
     8  	upstreamPort                        = []string{"upstream", "port"}
     9  	upstreamTlsVersion                  = []string{"upstream", "tls_version"}
    10  	upstreamSubjectLocalCertificate     = []string{"upstream", "subject_local_certificate"}
    11  	upstreamSubjectPeerCertificate      = []string{"upstream", "subject_peer_certificate"}
    12  	upstreamDnsSanLocalCertificate      = []string{"upstream", "dns_san_local_certificate"}
    13  	upstreamDnsSanPeerCertificate       = []string{"upstream", "dns_san_peer_certificate"}
    14  	upstreamUriSanLocalCertificate      = []string{"upstream", "uri_san_local_certificate"}
    15  	upstreamUriSanPeerCertificate       = []string{"upstream", "uri_san_peer_certificate"}
    16  	upstreamSha256PeerCertificateDigest = []string{"upstream", "sha256_peer_certificate_digest"}
    17  	upstreamLocalAddress                = []string{"upstream", "local_address"}
    18  	upstreamTransportFailureReason      = []string{"upstream", "transport_failure_reason"}
    19  )
    20  
    21  // GetUpstreamAddress returns the upstream connection remote address.
    22  func GetUpstreamAddress() (string, error) {
    23  	return getPropertyString(upstreamAddress)
    24  }
    25  
    26  // GetUpstreamPort returns the upstream connection remote port.
    27  func GetUpstreamPort() (uint64, error) {
    28  	return getPropertyUint64(upstreamPort)
    29  }
    30  
    31  // GetUpstreamTlsVersion returns the TLS version of the upstream TLS connection.
    32  func GetUpstreamTlsVersion() (string, error) {
    33  	return getPropertyString(upstreamTlsVersion)
    34  }
    35  
    36  // GetUpstreamSubjectLocalCertificate returns the subject field of the local
    37  // certificate in the upstream TLS connection.
    38  func GetUpstreamSubjectLocalCertificate() (string, error) {
    39  	return getPropertyString(upstreamSubjectLocalCertificate)
    40  }
    41  
    42  // GetUpstreamSubjectPeerCertificate returns the subject field of the peer
    43  // certificate in the upstream TLS connection.
    44  func GetUpstreamSubjectPeerCertificate() (string, error) {
    45  	return getPropertyString(upstreamSubjectPeerCertificate)
    46  }
    47  
    48  // GetUpstreamDnsSanLocalCertificate returns the first DNS entry in the SAN
    49  // field of the local certificate in the upstream TLS connection.
    50  func GetUpstreamDnsSanLocalCertificate() (string, error) {
    51  	return getPropertyString(upstreamDnsSanLocalCertificate)
    52  }
    53  
    54  // GetUpstreamDnsSanPeerCertificate returns the first DNS entry in the SAN
    55  // field of the peer certificate in the upstream TLS connection.
    56  func GetUpstreamDnsSanPeerCertificate() (string, error) {
    57  	return getPropertyString(upstreamDnsSanPeerCertificate)
    58  }
    59  
    60  // GetUpstreamUriSanLocalCertificate returns the first URI entry in the SAN
    61  // field of the local certificate in the upstream TLS connection.
    62  func GetUpstreamUriSanLocalCertificate() (string, error) {
    63  	return getPropertyString(upstreamUriSanLocalCertificate)
    64  }
    65  
    66  // GetUpstreamUriSanPeerCertificate returns the first URI entry in the SAN
    67  // field of the peer certificate in the upstream TLS connection.
    68  func GetUpstreamUriSanPeerCertificate() (string, error) {
    69  	return getPropertyString(upstreamUriSanPeerCertificate)
    70  }
    71  
    72  // GetUpstreamSha256PeerCertificateDigest returns the SHA256 digest of the
    73  // peer certificate in the upstream TLS connection if present.
    74  func GetUpstreamSha256PeerCertificateDigest() (string, error) {
    75  	return getPropertyString(upstreamSha256PeerCertificateDigest)
    76  }
    77  
    78  // GetUpstreamLocalAddress returns the local address of the upstream connection.
    79  func GetUpstreamLocalAddress() (string, error) {
    80  	return getPropertyString(upstreamLocalAddress)
    81  }
    82  
    83  // GetUpstreamTransportFailureReason returns the upstream transport failure
    84  // reason e.g. certificate validation failed.
    85  func GetUpstreamTransportFailureReason() (string, error) {
    86  	return getPropertyString(upstreamTransportFailureReason)
    87  }