Debian Codegraph @

apigeeconnect/apiv1/tether_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package apigeeconnect
18
19 import (
20 "context"
21 "log/slog"
22 "math"
23
24 apigeeconnectpb "cloud.google.com/go/apigeeconnect/apiv1/apigeeconnectpb"
25 gax "github.com/googleapis/gax-go/v2"
26 "google.golang.org/api/option"
27 "google.golang.org/api/option/internaloption"
28 gtransport "google.golang.org/api/transport/grpc"
29 "google.golang.org/grpc"
30 )
31
32 var newTetherClientHook clientHook
33
34 // TetherCallOptions contains the retry settings for each method of TetherClient.
35 type TetherCallOptions struct {
36 Egress []gax.CallOption
37 }
38
39 func defaultTetherGRPCClientOptions() []option.ClientOption {
40 return []option.ClientOption{
41 internaloption.WithDefaultEndpoint("apigeeconnect.googleapis.com:443"),
42 internaloption.WithDefaultEndpointTemplate("apigeeconnect.UNIVERSE_DOMAIN:443"),
43 internaloption.WithDefaultMTLSEndpoint("apigeeconnect.mtls.googleapis.com:443"),
44 internaloption.WithDefaultUniverseDomain("googleapis.com"),
45 internaloption.WithDefaultAudience("https://apigeeconnect.googleapis.com/"),
46 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
47 internaloption.EnableJwtWithScope(),
48 internaloption.EnableNewAuthLibrary(),
49 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
50 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
51 }
52 }
53
54 func defaultTetherCallOptions() *TetherCallOptions {
55 return &TetherCallOptions{
56 Egress: []gax.CallOption{},
57 }
58 }
59
60 // internalTetherClient is an interface that defines the methods available from Apigee Connect API.
61 type internalTetherClient interface {
62 Close() error
63 setGoogleClientInfo(...string)
64 Connection() *grpc.ClientConn
65 Egress(context.Context, ...gax.CallOption) (apigeeconnectpb.Tether_EgressClient, error)
66 }
67
68 // TetherClient is a client for interacting with Apigee Connect API.
69 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
70 //
71 // Tether provides a way for the control plane to send HTTP API requests to
72 // services in data planes that runs in a remote datacenter without
73 // requiring customers to open firewalls on their runtime plane.
74 type TetherClient struct {
75 // The internal transport-dependent client.
76 internalClient internalTetherClient
77
78 // The call options for this service.
79 CallOptions *TetherCallOptions
80 }
81
82 // Wrapper methods routed to the internal client.
83
84 // Close closes the connection to the API service. The user should invoke this when
85 // the client is no longer required.
86 func (c *TetherClient) Close() error {
87 return c.internalClient.Close()
88 }
89
90 // setGoogleClientInfo sets the name and version of the application in
91 // the `x-goog-api-client` header passed on each request. Intended for
92 // use by Google-written clients.
93 func (c *TetherClient) setGoogleClientInfo(keyval ...string) {
94 c.internalClient.setGoogleClientInfo(keyval...)
95 }
96
97 // Connection returns a connection to the API service.
98 //
99 // Deprecated: Connections are now pooled so this method does not always
100 // return the same resource.
101 func (c *TetherClient) Connection() *grpc.ClientConn {
102 return c.internalClient.Connection()
103 }
104
105 // Egress egress streams egress requests and responses. Logically, this is not
106 // actually a streaming request, but uses streaming as a mechanism to flip
107 // the client-server relationship of gRPC so that the server can act as a
108 // client.
109 // The listener, the RPC server, accepts connections from the dialer,
110 // the RPC client.
111 // The listener streams http requests and the dialer streams http responses.
112 func (c *TetherClient) Egress(ctx context.Context, opts ...gax.CallOption) (apigeeconnectpb.Tether_EgressClient, error) {
113 return c.internalClient.Egress(ctx, opts...)
114 }
115
116 // tetherGRPCClient is a client for interacting with Apigee Connect API over gRPC transport.
117 //
118 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
119 type tetherGRPCClient struct {
120 // Connection pool of gRPC connections to the service.
121 connPool gtransport.ConnPool
122
123 // Points back to the CallOptions field of the containing TetherClient
124 CallOptions **TetherCallOptions
125
126 // The gRPC API client.
127 tetherClient apigeeconnectpb.TetherClient
128
129 // The x-goog-* metadata to be sent with each request.
130 xGoogHeaders []string
131
132 logger *slog.Logger
133 }
134
135 // NewTetherClient creates a new tether client based on gRPC.
136 // The returned client must be Closed when it is done being used to clean up its underlying connections.
137 //
138 // Tether provides a way for the control plane to send HTTP API requests to
139 // services in data planes that runs in a remote datacenter without
140 // requiring customers to open firewalls on their runtime plane.
141 func NewTetherClient(ctx context.Context, opts ...option.ClientOption) (*TetherClient, error) {
142 clientOpts := defaultTetherGRPCClientOptions()
143 if newTetherClientHook != nil {
144 hookOpts, err := newTetherClientHook(ctx, clientHookParams{})
145 if err != nil {
146 return nil, err
147 }
148 clientOpts = append(clientOpts, hookOpts...)
149 }
150
151 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
152 if err != nil {
153 return nil, err
154 }
155 client := TetherClient{CallOptions: defaultTetherCallOptions()}
156
157 c := &tetherGRPCClient{
158 connPool: connPool,
159 tetherClient: apigeeconnectpb.NewTetherClient(connPool),
160 CallOptions: &client.CallOptions,
161 logger: internaloption.GetLogger(opts),
162 }
163 c.setGoogleClientInfo()
164
165 client.internalClient = c
166
167 return &client, nil
168 }
169
170 // Connection returns a connection to the API service.
171 //
172 // Deprecated: Connections are now pooled so this method does not always
173 // return the same resource.
174 func (c *tetherGRPCClient) Connection() *grpc.ClientConn {
175 return c.connPool.Conn()
176 }
177
178 // setGoogleClientInfo sets the name and version of the application in
179 // the `x-goog-api-client` header passed on each request. Intended for
180 // use by Google-written clients.
181 func (c *tetherGRPCClient) setGoogleClientInfo(keyval ...string) {
182 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
183 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
184 c.xGoogHeaders = []string{
185 "x-goog-api-client", gax.XGoogHeader(kv...),
186 }
187 }
188
189 // Close closes the connection to the API service. The user should invoke this when
190 // the client is no longer required.
191 func (c *tetherGRPCClient) Close() error {
192 return c.connPool.Close()
193 }
194
195 func (c *tetherGRPCClient) Egress(ctx context.Context, opts ...gax.CallOption) (apigeeconnectpb.Tether_EgressClient, error) {
196 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
197 var resp apigeeconnectpb.Tether_EgressClient
198 opts = append((*c.CallOptions).Egress[0:len((*c.CallOptions).Egress):len((*c.CallOptions).Egress)], opts...)
199 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
200 var err error
201 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "Egress")
202 resp, err = c.tetherClient.Egress(ctx, settings.GRPC...)
203 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "Egress")
204 return err
205 }, opts...)
206 if err != nil {
207 return nil, err
208 }
209 return resp, nil
210 }