| 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 |
"fmt" |
| 22 |
"log/slog" |
| 23 |
"math" |
| 24 |
"net/url" |
| 25 |
"time" |
| 26 |
|
| 27 |
apigeeconnectpb "cloud.google.com/go/apigeeconnect/apiv1/apigeeconnectpb" |
| 28 |
gax "github.com/googleapis/gax-go/v2" |
| 29 |
"google.golang.org/api/iterator" |
| 30 |
"google.golang.org/api/option" |
| 31 |
"google.golang.org/api/option/internaloption" |
| 32 |
gtransport "google.golang.org/api/transport/grpc" |
| 33 |
"google.golang.org/grpc" |
| 34 |
"google.golang.org/grpc/codes" |
| 35 |
"google.golang.org/protobuf/proto" |
| 36 |
) |
| 37 |
|
| 38 |
var newConnectionClientHook clientHook |
| 39 |
|
| 40 |
// ConnectionCallOptions contains the retry settings for each method of ConnectionClient. |
| 41 |
type ConnectionCallOptions struct { |
| 42 |
ListConnections []gax.CallOption |
| 43 |
} |
| 44 |
|
| 45 |
func defaultConnectionGRPCClientOptions() []option.ClientOption { |
| 46 |
return []option.ClientOption{ |
| 47 |
internaloption.WithDefaultEndpoint("apigeeconnect.googleapis.com:443"), |
| 48 |
internaloption.WithDefaultEndpointTemplate("apigeeconnect.UNIVERSE_DOMAIN:443"), |
| 49 |
internaloption.WithDefaultMTLSEndpoint("apigeeconnect.mtls.googleapis.com:443"), |
| 50 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 51 |
internaloption.WithDefaultAudience("https://apigeeconnect.googleapis.com/"), |
| 52 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 53 |
internaloption.EnableJwtWithScope(), |
| 54 |
internaloption.EnableNewAuthLibrary(), |
| 55 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 56 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
func defaultConnectionCallOptions() *ConnectionCallOptions { |
| 61 |
return &ConnectionCallOptions{ |
| 62 |
ListConnections: []gax.CallOption{ |
| 63 |
gax.WithTimeout(60000 * time.Millisecond), |
| 64 |
gax.WithRetry(func() gax.Retryer { |
| 65 |
return gax.OnCodes([]codes.Code{ |
| 66 |
codes.Unavailable, |
| 67 |
codes.Unknown, |
| 68 |
}, gax.Backoff{ |
| 69 |
Initial: 1000 * time.Millisecond, |
| 70 |
Max: 60000 * time.Millisecond, |
| 71 |
Multiplier: 1.30, |
| 72 |
}) |
| 73 |
}), |
| 74 |
}, |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
// internalConnectionClient is an interface that defines the methods available from Apigee Connect API. |
| 79 |
type internalConnectionClient interface { |
| 80 |
Close() error |
| 81 |
setGoogleClientInfo(...string) |
| 82 |
Connection() *grpc.ClientConn |
| 83 |
ListConnections(context.Context, *apigeeconnectpb.ListConnectionsRequest, ...gax.CallOption) *ConnectionIterator |
| 84 |
} |
| 85 |
|
| 86 |
// ConnectionClient is a client for interacting with Apigee Connect API. |
| 87 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 88 |
// |
| 89 |
// Service Interface for the Apigee Connect connection management APIs. |
| 90 |
type ConnectionClient struct { |
| 91 |
// The internal transport-dependent client. |
| 92 |
internalClient internalConnectionClient |
| 93 |
|
| 94 |
// The call options for this service. |
| 95 |
CallOptions *ConnectionCallOptions |
| 96 |
} |
| 97 |
|
| 98 |
// Wrapper methods routed to the internal client. |
| 99 |
|
| 100 |
// Close closes the connection to the API service. The user should invoke this when |
| 101 |
// the client is no longer required. |
| 102 |
func (c *ConnectionClient) Close() error { |
| 103 |
return c.internalClient.Close() |
| 104 |
} |
| 105 |
|
| 106 |
// setGoogleClientInfo sets the name and version of the application in |
| 107 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 108 |
// use by Google-written clients. |
| 109 |
func (c *ConnectionClient) setGoogleClientInfo(keyval ...string) { |
| 110 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 111 |
} |
| 112 |
|
| 113 |
// Connection returns a connection to the API service. |
| 114 |
// |
| 115 |
// Deprecated: Connections are now pooled so this method does not always |
| 116 |
// return the same resource. |
| 117 |
func (c *ConnectionClient) Connection() *grpc.ClientConn { |
| 118 |
return c.internalClient.Connection() |
| 119 |
} |
| 120 |
|
| 121 |
// ListConnections lists connections that are currently active for the given Apigee Connect |
| 122 |
// endpoint. |
| 123 |
func (c *ConnectionClient) ListConnections(ctx context.Context, req *apigeeconnectpb.ListConnectionsRequest, opts ...gax.CallOption) *ConnectionIterator { |
| 124 |
return c.internalClient.ListConnections(ctx, req, opts...) |
| 125 |
} |
| 126 |
|
| 127 |
// connectionGRPCClient is a client for interacting with Apigee Connect API over gRPC transport. |
| 128 |
// |
| 129 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 130 |
type connectionGRPCClient struct { |
| 131 |
// Connection pool of gRPC connections to the service. |
| 132 |
connPool gtransport.ConnPool |
| 133 |
|
| 134 |
// Points back to the CallOptions field of the containing ConnectionClient |
| 135 |
CallOptions **ConnectionCallOptions |
| 136 |
|
| 137 |
// The gRPC API client. |
| 138 |
connectionClient apigeeconnectpb.ConnectionServiceClient |
| 139 |
|
| 140 |
// The x-goog-* metadata to be sent with each request. |
| 141 |
xGoogHeaders []string |
| 142 |
|
| 143 |
logger *slog.Logger |
| 144 |
} |
| 145 |
|
| 146 |
// NewConnectionClient creates a new connection service client based on gRPC. |
| 147 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 148 |
// |
| 149 |
// Service Interface for the Apigee Connect connection management APIs. |
| 150 |
func NewConnectionClient(ctx context.Context, opts ...option.ClientOption) (*ConnectionClient, error) { |
| 151 |
clientOpts := defaultConnectionGRPCClientOptions() |
| 152 |
if newConnectionClientHook != nil { |
| 153 |
hookOpts, err := newConnectionClientHook(ctx, clientHookParams{}) |
| 154 |
if err != nil { |
| 155 |
return nil, err |
| 156 |
} |
| 157 |
clientOpts = append(clientOpts, hookOpts...) |
| 158 |
} |
| 159 |
|
| 160 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 161 |
if err != nil { |
| 162 |
return nil, err |
| 163 |
} |
| 164 |
client := ConnectionClient{CallOptions: defaultConnectionCallOptions()} |
| 165 |
|
| 166 |
c := &connectionGRPCClient{ |
| 167 |
connPool: connPool, |
| 168 |
connectionClient: apigeeconnectpb.NewConnectionServiceClient(connPool), |
| 169 |
CallOptions: &client.CallOptions, |
| 170 |
logger: internaloption.GetLogger(opts), |
| 171 |
} |
| 172 |
c.setGoogleClientInfo() |
| 173 |
|
| 174 |
client.internalClient = c |
| 175 |
|
| 176 |
return &client, nil |
| 177 |
} |
| 178 |
|
| 179 |
// Connection returns a connection to the API service. |
| 180 |
// |
| 181 |
// Deprecated: Connections are now pooled so this method does not always |
| 182 |
// return the same resource. |
| 183 |
func (c *connectionGRPCClient) Connection() *grpc.ClientConn { |
| 184 |
return c.connPool.Conn() |
| 185 |
} |
| 186 |
|
| 187 |
// setGoogleClientInfo sets the name and version of the application in |
| 188 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 189 |
// use by Google-written clients. |
| 190 |
func (c *connectionGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 191 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 192 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 193 |
c.xGoogHeaders = []string{ |
| 194 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
// Close closes the connection to the API service. The user should invoke this when |
| 199 |
// the client is no longer required. |
| 200 |
func (c *connectionGRPCClient) Close() error { |
| 201 |
return c.connPool.Close() |
| 202 |
} |
| 203 |
|
| 204 |
func (c *connectionGRPCClient) ListConnections(ctx context.Context, req *apigeeconnectpb.ListConnectionsRequest, opts ...gax.CallOption) *ConnectionIterator { |
| 205 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 206 |
|
| 207 |
hds = append(c.xGoogHeaders, hds...) |
| 208 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 209 |
opts = append((*c.CallOptions).ListConnections[0:len((*c.CallOptions).ListConnections):len((*c.CallOptions).ListConnections)], opts...) |
| 210 |
it := &ConnectionIterator{} |
| 211 |
req = proto.Clone(req).(*apigeeconnectpb.ListConnectionsRequest) |
| 212 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*apigeeconnectpb.Connection, string, error) { |
| 213 |
resp := &apigeeconnectpb.ListConnectionsResponse{} |
| 214 |
if pageToken != "" { |
| 215 |
req.PageToken = pageToken |
| 216 |
} |
| 217 |
if pageSize > math.MaxInt32 { |
| 218 |
req.PageSize = math.MaxInt32 |
| 219 |
} else if pageSize != 0 { |
| 220 |
req.PageSize = int32(pageSize) |
| 221 |
} |
| 222 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 223 |
var err error |
| 224 |
resp, err = executeRPC(ctx, c.connectionClient.ListConnections, req, settings.GRPC, c.logger, "ListConnections") |
| 225 |
return err |
| 226 |
}, opts...) |
| 227 |
if err != nil { |
| 228 |
return nil, "", err |
| 229 |
} |
| 230 |
|
| 231 |
it.Response = resp |
| 232 |
return resp.GetConnections(), resp.GetNextPageToken(), nil |
| 233 |
} |
| 234 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 235 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 236 |
if err != nil { |
| 237 |
return "", err |
| 238 |
} |
| 239 |
it.items = append(it.items, items...) |
| 240 |
return nextPageToken, nil |
| 241 |
} |
| 242 |
|
| 243 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 244 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 245 |
it.pageInfo.Token = req.GetPageToken() |
| 246 |
|
| 247 |
return it |
| 248 |
} |