| 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 privatecatalog |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"fmt" |
| 22 |
"log/slog" |
| 23 |
"math" |
| 24 |
"net/http" |
| 25 |
"net/url" |
| 26 |
|
| 27 |
privatecatalogpb "cloud.google.com/go/privatecatalog/apiv1beta1/privatecatalogpb" |
| 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 |
httptransport "google.golang.org/api/transport/http" |
| 34 |
"google.golang.org/grpc" |
| 35 |
"google.golang.org/protobuf/encoding/protojson" |
| 36 |
"google.golang.org/protobuf/proto" |
| 37 |
) |
| 38 |
|
| 39 |
var newClientHook clientHook |
| 40 |
|
| 41 |
// CallOptions contains the retry settings for each method of Client. |
| 42 |
type CallOptions struct { |
| 43 |
SearchCatalogs []gax.CallOption |
| 44 |
SearchProducts []gax.CallOption |
| 45 |
SearchVersions []gax.CallOption |
| 46 |
} |
| 47 |
|
| 48 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 49 |
return []option.ClientOption{ |
| 50 |
internaloption.WithDefaultEndpoint("cloudprivatecatalog.googleapis.com:443"), |
| 51 |
internaloption.WithDefaultEndpointTemplate("cloudprivatecatalog.UNIVERSE_DOMAIN:443"), |
| 52 |
internaloption.WithDefaultMTLSEndpoint("cloudprivatecatalog.mtls.googleapis.com:443"), |
| 53 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 54 |
internaloption.WithDefaultAudience("https://cloudprivatecatalog.googleapis.com/"), |
| 55 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 56 |
internaloption.EnableJwtWithScope(), |
| 57 |
internaloption.EnableNewAuthLibrary(), |
| 58 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 59 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
func defaultCallOptions() *CallOptions { |
| 64 |
return &CallOptions{ |
| 65 |
SearchCatalogs: []gax.CallOption{}, |
| 66 |
SearchProducts: []gax.CallOption{}, |
| 67 |
SearchVersions: []gax.CallOption{}, |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
func defaultRESTCallOptions() *CallOptions { |
| 72 |
return &CallOptions{ |
| 73 |
SearchCatalogs: []gax.CallOption{}, |
| 74 |
SearchProducts: []gax.CallOption{}, |
| 75 |
SearchVersions: []gax.CallOption{}, |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// internalClient is an interface that defines the methods available from Cloud Private Catalog API. |
| 80 |
type internalClient interface { |
| 81 |
Close() error |
| 82 |
setGoogleClientInfo(...string) |
| 83 |
Connection() *grpc.ClientConn |
| 84 |
SearchCatalogs(context.Context, *privatecatalogpb.SearchCatalogsRequest, ...gax.CallOption) *CatalogIterator |
| 85 |
SearchProducts(context.Context, *privatecatalogpb.SearchProductsRequest, ...gax.CallOption) *ProductIterator |
| 86 |
SearchVersions(context.Context, *privatecatalogpb.SearchVersionsRequest, ...gax.CallOption) *VersionIterator |
| 87 |
} |
| 88 |
|
| 89 |
// Client is a client for interacting with Cloud Private Catalog API. |
| 90 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 91 |
// |
| 92 |
// PrivateCatalog allows catalog consumers to retrieve Catalog, Product |
| 93 |
// and Version resources under a target resource context. |
| 94 |
// |
| 95 |
// Catalog is computed based on the Associations linked to the target |
| 96 |
// resource and its ancestors. Each association’s |
| 97 |
// google.cloud.privatecatalogproducer.v1beta.Catalog is transformed into a |
| 98 |
// Catalog. If multiple associations have the same parent |
| 99 |
// google.cloud.privatecatalogproducer.v1beta.Catalog, they are |
| 100 |
// de-duplicated into one Catalog. Users must have |
| 101 |
// cloudprivatecatalog.catalogTargets.get IAM permission on the resource |
| 102 |
// context in order to access catalogs. Catalog contains the resource name and |
| 103 |
// a subset of data of the original |
| 104 |
// google.cloud.privatecatalogproducer.v1beta.Catalog. |
| 105 |
// |
| 106 |
// Product is child resource of the catalog. A Product contains the resource |
| 107 |
// name and a subset of the data of the original |
| 108 |
// google.cloud.privatecatalogproducer.v1beta.Product. |
| 109 |
// |
| 110 |
// Version is child resource of the product. A Version contains the resource |
| 111 |
// name and a subset of the data of the original |
| 112 |
// google.cloud.privatecatalogproducer.v1beta.Version. |
| 113 |
type Client struct { |
| 114 |
// The internal transport-dependent client. |
| 115 |
internalClient internalClient |
| 116 |
|
| 117 |
// The call options for this service. |
| 118 |
CallOptions *CallOptions |
| 119 |
} |
| 120 |
|
| 121 |
// Wrapper methods routed to the internal client. |
| 122 |
|
| 123 |
// Close closes the connection to the API service. The user should invoke this when |
| 124 |
// the client is no longer required. |
| 125 |
func (c *Client) Close() error { |
| 126 |
return c.internalClient.Close() |
| 127 |
} |
| 128 |
|
| 129 |
// setGoogleClientInfo sets the name and version of the application in |
| 130 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 131 |
// use by Google-written clients. |
| 132 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 133 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 134 |
} |
| 135 |
|
| 136 |
// Connection returns a connection to the API service. |
| 137 |
// |
| 138 |
// Deprecated: Connections are now pooled so this method does not always |
| 139 |
// return the same resource. |
| 140 |
func (c *Client) Connection() *grpc.ClientConn { |
| 141 |
return c.internalClient.Connection() |
| 142 |
} |
| 143 |
|
| 144 |
// SearchCatalogs search Catalog resources that consumers have access to, within the |
| 145 |
// scope of the consumer cloud resource hierarchy context. |
| 146 |
func (c *Client) SearchCatalogs(ctx context.Context, req *privatecatalogpb.SearchCatalogsRequest, opts ...gax.CallOption) *CatalogIterator { |
| 147 |
return c.internalClient.SearchCatalogs(ctx, req, opts...) |
| 148 |
} |
| 149 |
|
| 150 |
// SearchProducts search Product resources that consumers have access to, within the |
| 151 |
// scope of the consumer cloud resource hierarchy context. |
| 152 |
func (c *Client) SearchProducts(ctx context.Context, req *privatecatalogpb.SearchProductsRequest, opts ...gax.CallOption) *ProductIterator { |
| 153 |
return c.internalClient.SearchProducts(ctx, req, opts...) |
| 154 |
} |
| 155 |
|
| 156 |
// SearchVersions search Version resources that consumers have access to, within the |
| 157 |
// scope of the consumer cloud resource hierarchy context. |
| 158 |
func (c *Client) SearchVersions(ctx context.Context, req *privatecatalogpb.SearchVersionsRequest, opts ...gax.CallOption) *VersionIterator { |
| 159 |
return c.internalClient.SearchVersions(ctx, req, opts...) |
| 160 |
} |
| 161 |
|
| 162 |
// gRPCClient is a client for interacting with Cloud Private Catalog API over gRPC transport. |
| 163 |
// |
| 164 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 165 |
type gRPCClient struct { |
| 166 |
// Connection pool of gRPC connections to the service. |
| 167 |
connPool gtransport.ConnPool |
| 168 |
|
| 169 |
// Points back to the CallOptions field of the containing Client |
| 170 |
CallOptions **CallOptions |
| 171 |
|
| 172 |
// The gRPC API client. |
| 173 |
client privatecatalogpb.PrivateCatalogClient |
| 174 |
|
| 175 |
// The x-goog-* metadata to be sent with each request. |
| 176 |
xGoogHeaders []string |
| 177 |
|
| 178 |
logger *slog.Logger |
| 179 |
} |
| 180 |
|
| 181 |
// NewClient creates a new private catalog client based on gRPC. |
| 182 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 183 |
// |
| 184 |
// PrivateCatalog allows catalog consumers to retrieve Catalog, Product |
| 185 |
// and Version resources under a target resource context. |
| 186 |
// |
| 187 |
// Catalog is computed based on the Associations linked to the target |
| 188 |
// resource and its ancestors. Each association’s |
| 189 |
// google.cloud.privatecatalogproducer.v1beta.Catalog is transformed into a |
| 190 |
// Catalog. If multiple associations have the same parent |
| 191 |
// google.cloud.privatecatalogproducer.v1beta.Catalog, they are |
| 192 |
// de-duplicated into one Catalog. Users must have |
| 193 |
// cloudprivatecatalog.catalogTargets.get IAM permission on the resource |
| 194 |
// context in order to access catalogs. Catalog contains the resource name and |
| 195 |
// a subset of data of the original |
| 196 |
// google.cloud.privatecatalogproducer.v1beta.Catalog. |
| 197 |
// |
| 198 |
// Product is child resource of the catalog. A Product contains the resource |
| 199 |
// name and a subset of the data of the original |
| 200 |
// google.cloud.privatecatalogproducer.v1beta.Product. |
| 201 |
// |
| 202 |
// Version is child resource of the product. A Version contains the resource |
| 203 |
// name and a subset of the data of the original |
| 204 |
// google.cloud.privatecatalogproducer.v1beta.Version. |
| 205 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 206 |
clientOpts := defaultGRPCClientOptions() |
| 207 |
if newClientHook != nil { |
| 208 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 209 |
if err != nil { |
| 210 |
return nil, err |
| 211 |
} |
| 212 |
clientOpts = append(clientOpts, hookOpts...) |
| 213 |
} |
| 214 |
|
| 215 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 216 |
if err != nil { |
| 217 |
return nil, err |
| 218 |
} |
| 219 |
client := Client{CallOptions: defaultCallOptions()} |
| 220 |
|
| 221 |
c := &gRPCClient{ |
| 222 |
connPool: connPool, |
| 223 |
client: privatecatalogpb.NewPrivateCatalogClient(connPool), |
| 224 |
CallOptions: &client.CallOptions, |
| 225 |
logger: internaloption.GetLogger(opts), |
| 226 |
} |
| 227 |
c.setGoogleClientInfo() |
| 228 |
|
| 229 |
client.internalClient = c |
| 230 |
|
| 231 |
return &client, nil |
| 232 |
} |
| 233 |
|
| 234 |
// Connection returns a connection to the API service. |
| 235 |
// |
| 236 |
// Deprecated: Connections are now pooled so this method does not always |
| 237 |
// return the same resource. |
| 238 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 239 |
return c.connPool.Conn() |
| 240 |
} |
| 241 |
|
| 242 |
// setGoogleClientInfo sets the name and version of the application in |
| 243 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 244 |
// use by Google-written clients. |
| 245 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 246 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 247 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 248 |
c.xGoogHeaders = []string{ |
| 249 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
// Close closes the connection to the API service. The user should invoke this when |
| 254 |
// the client is no longer required. |
| 255 |
func (c *gRPCClient) Close() error { |
| 256 |
return c.connPool.Close() |
| 257 |
} |
| 258 |
|
| 259 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 260 |
type restClient struct { |
| 261 |
// The http endpoint to connect to. |
| 262 |
endpoint string |
| 263 |
|
| 264 |
// The http client. |
| 265 |
httpClient *http.Client |
| 266 |
|
| 267 |
// The x-goog-* headers to be sent with each request. |
| 268 |
xGoogHeaders []string |
| 269 |
|
| 270 |
// Points back to the CallOptions field of the containing Client |
| 271 |
CallOptions **CallOptions |
| 272 |
|
| 273 |
logger *slog.Logger |
| 274 |
} |
| 275 |
|
| 276 |
// NewRESTClient creates a new private catalog rest client. |
| 277 |
// |
| 278 |
// PrivateCatalog allows catalog consumers to retrieve Catalog, Product |
| 279 |
// and Version resources under a target resource context. |
| 280 |
// |
| 281 |
// Catalog is computed based on the Associations linked to the target |
| 282 |
// resource and its ancestors. Each association’s |
| 283 |
// google.cloud.privatecatalogproducer.v1beta.Catalog is transformed into a |
| 284 |
// Catalog. If multiple associations have the same parent |
| 285 |
// google.cloud.privatecatalogproducer.v1beta.Catalog, they are |
| 286 |
// de-duplicated into one Catalog. Users must have |
| 287 |
// cloudprivatecatalog.catalogTargets.get IAM permission on the resource |
| 288 |
// context in order to access catalogs. Catalog contains the resource name and |
| 289 |
// a subset of data of the original |
| 290 |
// google.cloud.privatecatalogproducer.v1beta.Catalog. |
| 291 |
// |
| 292 |
// Product is child resource of the catalog. A Product contains the resource |
| 293 |
// name and a subset of the data of the original |
| 294 |
// google.cloud.privatecatalogproducer.v1beta.Product. |
| 295 |
// |
| 296 |
// Version is child resource of the product. A Version contains the resource |
| 297 |
// name and a subset of the data of the original |
| 298 |
// google.cloud.privatecatalogproducer.v1beta.Version. |
| 299 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 300 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 301 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 302 |
if err != nil { |
| 303 |
return nil, err |
| 304 |
} |
| 305 |
|
| 306 |
callOpts := defaultRESTCallOptions() |
| 307 |
c := &restClient{ |
| 308 |
endpoint: endpoint, |
| 309 |
httpClient: httpClient, |
| 310 |
CallOptions: &callOpts, |
| 311 |
logger: internaloption.GetLogger(opts), |
| 312 |
} |
| 313 |
c.setGoogleClientInfo() |
| 314 |
|
| 315 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 316 |
} |
| 317 |
|
| 318 |
func defaultRESTClientOptions() []option.ClientOption { |
| 319 |
return []option.ClientOption{ |
| 320 |
internaloption.WithDefaultEndpoint("https://cloudprivatecatalog.googleapis.com"), |
| 321 |
internaloption.WithDefaultEndpointTemplate("https://cloudprivatecatalog.UNIVERSE_DOMAIN"), |
| 322 |
internaloption.WithDefaultMTLSEndpoint("https://cloudprivatecatalog.mtls.googleapis.com"), |
| 323 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 324 |
internaloption.WithDefaultAudience("https://cloudprivatecatalog.googleapis.com/"), |
| 325 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 326 |
internaloption.EnableNewAuthLibrary(), |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
// setGoogleClientInfo sets the name and version of the application in |
| 331 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 332 |
// use by Google-written clients. |
| 333 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 334 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 335 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 336 |
c.xGoogHeaders = []string{ |
| 337 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
// Close closes the connection to the API service. The user should invoke this when |
| 342 |
// the client is no longer required. |
| 343 |
func (c *restClient) Close() error { |
| 344 |
// Replace httpClient with nil to force cleanup. |
| 345 |
c.httpClient = nil |
| 346 |
return nil |
| 347 |
} |
| 348 |
|
| 349 |
// Connection returns a connection to the API service. |
| 350 |
// |
| 351 |
// Deprecated: This method always returns nil. |
| 352 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 353 |
return nil |
| 354 |
} |
| 355 |
func (c *gRPCClient) SearchCatalogs(ctx context.Context, req *privatecatalogpb.SearchCatalogsRequest, opts ...gax.CallOption) *CatalogIterator { |
| 356 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} |
| 357 |
|
| 358 |
hds = append(c.xGoogHeaders, hds...) |
| 359 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 360 |
opts = append((*c.CallOptions).SearchCatalogs[0:len((*c.CallOptions).SearchCatalogs):len((*c.CallOptions).SearchCatalogs)], opts...) |
| 361 |
it := &CatalogIterator{} |
| 362 |
req = proto.Clone(req).(*privatecatalogpb.SearchCatalogsRequest) |
| 363 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Catalog, string, error) { |
| 364 |
resp := &privatecatalogpb.SearchCatalogsResponse{} |
| 365 |
if pageToken != "" { |
| 366 |
req.PageToken = pageToken |
| 367 |
} |
| 368 |
if pageSize > math.MaxInt32 { |
| 369 |
req.PageSize = math.MaxInt32 |
| 370 |
} else if pageSize != 0 { |
| 371 |
req.PageSize = int32(pageSize) |
| 372 |
} |
| 373 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 374 |
var err error |
| 375 |
resp, err = executeRPC(ctx, c.client.SearchCatalogs, req, settings.GRPC, c.logger, "SearchCatalogs") |
| 376 |
return err |
| 377 |
}, opts...) |
| 378 |
if err != nil { |
| 379 |
return nil, "", err |
| 380 |
} |
| 381 |
|
| 382 |
it.Response = resp |
| 383 |
return resp.GetCatalogs(), resp.GetNextPageToken(), nil |
| 384 |
} |
| 385 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 386 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 387 |
if err != nil { |
| 388 |
return "", err |
| 389 |
} |
| 390 |
it.items = append(it.items, items...) |
| 391 |
return nextPageToken, nil |
| 392 |
} |
| 393 |
|
| 394 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 395 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 396 |
it.pageInfo.Token = req.GetPageToken() |
| 397 |
|
| 398 |
return it |
| 399 |
} |
| 400 |
|
| 401 |
func (c *gRPCClient) SearchProducts(ctx context.Context, req *privatecatalogpb.SearchProductsRequest, opts ...gax.CallOption) *ProductIterator { |
| 402 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} |
| 403 |
|
| 404 |
hds = append(c.xGoogHeaders, hds...) |
| 405 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 406 |
opts = append((*c.CallOptions).SearchProducts[0:len((*c.CallOptions).SearchProducts):len((*c.CallOptions).SearchProducts)], opts...) |
| 407 |
it := &ProductIterator{} |
| 408 |
req = proto.Clone(req).(*privatecatalogpb.SearchProductsRequest) |
| 409 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Product, string, error) { |
| 410 |
resp := &privatecatalogpb.SearchProductsResponse{} |
| 411 |
if pageToken != "" { |
| 412 |
req.PageToken = pageToken |
| 413 |
} |
| 414 |
if pageSize > math.MaxInt32 { |
| 415 |
req.PageSize = math.MaxInt32 |
| 416 |
} else if pageSize != 0 { |
| 417 |
req.PageSize = int32(pageSize) |
| 418 |
} |
| 419 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 420 |
var err error |
| 421 |
resp, err = executeRPC(ctx, c.client.SearchProducts, req, settings.GRPC, c.logger, "SearchProducts") |
| 422 |
return err |
| 423 |
}, opts...) |
| 424 |
if err != nil { |
| 425 |
return nil, "", err |
| 426 |
} |
| 427 |
|
| 428 |
it.Response = resp |
| 429 |
return resp.GetProducts(), resp.GetNextPageToken(), nil |
| 430 |
} |
| 431 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 432 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 433 |
if err != nil { |
| 434 |
return "", err |
| 435 |
} |
| 436 |
it.items = append(it.items, items...) |
| 437 |
return nextPageToken, nil |
| 438 |
} |
| 439 |
|
| 440 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 441 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 442 |
it.pageInfo.Token = req.GetPageToken() |
| 443 |
|
| 444 |
return it |
| 445 |
} |
| 446 |
|
| 447 |
func (c *gRPCClient) SearchVersions(ctx context.Context, req *privatecatalogpb.SearchVersionsRequest, opts ...gax.CallOption) *VersionIterator { |
| 448 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} |
| 449 |
|
| 450 |
hds = append(c.xGoogHeaders, hds...) |
| 451 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 452 |
opts = append((*c.CallOptions).SearchVersions[0:len((*c.CallOptions).SearchVersions):len((*c.CallOptions).SearchVersions)], opts...) |
| 453 |
it := &VersionIterator{} |
| 454 |
req = proto.Clone(req).(*privatecatalogpb.SearchVersionsRequest) |
| 455 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Version, string, error) { |
| 456 |
resp := &privatecatalogpb.SearchVersionsResponse{} |
| 457 |
if pageToken != "" { |
| 458 |
req.PageToken = pageToken |
| 459 |
} |
| 460 |
if pageSize > math.MaxInt32 { |
| 461 |
req.PageSize = math.MaxInt32 |
| 462 |
} else if pageSize != 0 { |
| 463 |
req.PageSize = int32(pageSize) |
| 464 |
} |
| 465 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 466 |
var err error |
| 467 |
resp, err = executeRPC(ctx, c.client.SearchVersions, req, settings.GRPC, c.logger, "SearchVersions") |
| 468 |
return err |
| 469 |
}, opts...) |
| 470 |
if err != nil { |
| 471 |
return nil, "", err |
| 472 |
} |
| 473 |
|
| 474 |
it.Response = resp |
| 475 |
return resp.GetVersions(), resp.GetNextPageToken(), nil |
| 476 |
} |
| 477 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 478 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 479 |
if err != nil { |
| 480 |
return "", err |
| 481 |
} |
| 482 |
it.items = append(it.items, items...) |
| 483 |
return nextPageToken, nil |
| 484 |
} |
| 485 |
|
| 486 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 487 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 488 |
it.pageInfo.Token = req.GetPageToken() |
| 489 |
|
| 490 |
return it |
| 491 |
} |
| 492 |
|
| 493 |
// SearchCatalogs search Catalog resources that consumers have access to, within the |
| 494 |
// scope of the consumer cloud resource hierarchy context. |
| 495 |
func (c *restClient) SearchCatalogs(ctx context.Context, req *privatecatalogpb.SearchCatalogsRequest, opts ...gax.CallOption) *CatalogIterator { |
| 496 |
it := &CatalogIterator{} |
| 497 |
req = proto.Clone(req).(*privatecatalogpb.SearchCatalogsRequest) |
| 498 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 499 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Catalog, string, error) { |
| 500 |
resp := &privatecatalogpb.SearchCatalogsResponse{} |
| 501 |
if pageToken != "" { |
| 502 |
req.PageToken = pageToken |
| 503 |
} |
| 504 |
if pageSize > math.MaxInt32 { |
| 505 |
req.PageSize = math.MaxInt32 |
| 506 |
} else if pageSize != 0 { |
| 507 |
req.PageSize = int32(pageSize) |
| 508 |
} |
| 509 |
baseUrl, err := url.Parse(c.endpoint) |
| 510 |
if err != nil { |
| 511 |
return nil, "", err |
| 512 |
} |
| 513 |
baseUrl.Path += fmt.Sprintf("/v1beta1/%v/catalogs:search", req.GetResource()) |
| 514 |
|
| 515 |
params := url.Values{} |
| 516 |
params.Add("$alt", "json;enum-encoding=int") |
| 517 |
if req.GetPageSize() != 0 { |
| 518 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 519 |
} |
| 520 |
if req.GetPageToken() != "" { |
| 521 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 522 |
} |
| 523 |
if req.GetQuery() != "" { |
| 524 |
params.Add("query", fmt.Sprintf("%v", req.GetQuery())) |
| 525 |
} |
| 526 |
|
| 527 |
baseUrl.RawQuery = params.Encode() |
| 528 |
|
| 529 |
// Build HTTP headers from client and context metadata. |
| 530 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 531 |
headers := gax.BuildHeaders(ctx, hds...) |
| 532 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 533 |
if settings.Path != "" { |
| 534 |
baseUrl.Path = settings.Path |
| 535 |
} |
| 536 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 537 |
if err != nil { |
| 538 |
return err |
| 539 |
} |
| 540 |
httpReq.Header = headers |
| 541 |
|
| 542 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "SearchCatalogs") |
| 543 |
if err != nil { |
| 544 |
return err |
| 545 |
} |
| 546 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 547 |
return err |
| 548 |
} |
| 549 |
|
| 550 |
return nil |
| 551 |
}, opts...) |
| 552 |
if e != nil { |
| 553 |
return nil, "", e |
| 554 |
} |
| 555 |
it.Response = resp |
| 556 |
return resp.GetCatalogs(), resp.GetNextPageToken(), nil |
| 557 |
} |
| 558 |
|
| 559 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 560 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 561 |
if err != nil { |
| 562 |
return "", err |
| 563 |
} |
| 564 |
it.items = append(it.items, items...) |
| 565 |
return nextPageToken, nil |
| 566 |
} |
| 567 |
|
| 568 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 569 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 570 |
it.pageInfo.Token = req.GetPageToken() |
| 571 |
|
| 572 |
return it |
| 573 |
} |
| 574 |
|
| 575 |
// SearchProducts search Product resources that consumers have access to, within the |
| 576 |
// scope of the consumer cloud resource hierarchy context. |
| 577 |
func (c *restClient) SearchProducts(ctx context.Context, req *privatecatalogpb.SearchProductsRequest, opts ...gax.CallOption) *ProductIterator { |
| 578 |
it := &ProductIterator{} |
| 579 |
req = proto.Clone(req).(*privatecatalogpb.SearchProductsRequest) |
| 580 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 581 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Product, string, error) { |
| 582 |
resp := &privatecatalogpb.SearchProductsResponse{} |
| 583 |
if pageToken != "" { |
| 584 |
req.PageToken = pageToken |
| 585 |
} |
| 586 |
if pageSize > math.MaxInt32 { |
| 587 |
req.PageSize = math.MaxInt32 |
| 588 |
} else if pageSize != 0 { |
| 589 |
req.PageSize = int32(pageSize) |
| 590 |
} |
| 591 |
baseUrl, err := url.Parse(c.endpoint) |
| 592 |
if err != nil { |
| 593 |
return nil, "", err |
| 594 |
} |
| 595 |
baseUrl.Path += fmt.Sprintf("/v1beta1/%v/products:search", req.GetResource()) |
| 596 |
|
| 597 |
params := url.Values{} |
| 598 |
params.Add("$alt", "json;enum-encoding=int") |
| 599 |
if req.GetPageSize() != 0 { |
| 600 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 601 |
} |
| 602 |
if req.GetPageToken() != "" { |
| 603 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 604 |
} |
| 605 |
if req.GetQuery() != "" { |
| 606 |
params.Add("query", fmt.Sprintf("%v", req.GetQuery())) |
| 607 |
} |
| 608 |
|
| 609 |
baseUrl.RawQuery = params.Encode() |
| 610 |
|
| 611 |
// Build HTTP headers from client and context metadata. |
| 612 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 613 |
headers := gax.BuildHeaders(ctx, hds...) |
| 614 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 615 |
if settings.Path != "" { |
| 616 |
baseUrl.Path = settings.Path |
| 617 |
} |
| 618 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 619 |
if err != nil { |
| 620 |
return err |
| 621 |
} |
| 622 |
httpReq.Header = headers |
| 623 |
|
| 624 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "SearchProducts") |
| 625 |
if err != nil { |
| 626 |
return err |
| 627 |
} |
| 628 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 629 |
return err |
| 630 |
} |
| 631 |
|
| 632 |
return nil |
| 633 |
}, opts...) |
| 634 |
if e != nil { |
| 635 |
return nil, "", e |
| 636 |
} |
| 637 |
it.Response = resp |
| 638 |
return resp.GetProducts(), resp.GetNextPageToken(), nil |
| 639 |
} |
| 640 |
|
| 641 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 642 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 643 |
if err != nil { |
| 644 |
return "", err |
| 645 |
} |
| 646 |
it.items = append(it.items, items...) |
| 647 |
return nextPageToken, nil |
| 648 |
} |
| 649 |
|
| 650 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 651 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 652 |
it.pageInfo.Token = req.GetPageToken() |
| 653 |
|
| 654 |
return it |
| 655 |
} |
| 656 |
|
| 657 |
// SearchVersions search Version resources that consumers have access to, within the |
| 658 |
// scope of the consumer cloud resource hierarchy context. |
| 659 |
func (c *restClient) SearchVersions(ctx context.Context, req *privatecatalogpb.SearchVersionsRequest, opts ...gax.CallOption) *VersionIterator { |
| 660 |
it := &VersionIterator{} |
| 661 |
req = proto.Clone(req).(*privatecatalogpb.SearchVersionsRequest) |
| 662 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 663 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Version, string, error) { |
| 664 |
resp := &privatecatalogpb.SearchVersionsResponse{} |
| 665 |
if pageToken != "" { |
| 666 |
req.PageToken = pageToken |
| 667 |
} |
| 668 |
if pageSize > math.MaxInt32 { |
| 669 |
req.PageSize = math.MaxInt32 |
| 670 |
} else if pageSize != 0 { |
| 671 |
req.PageSize = int32(pageSize) |
| 672 |
} |
| 673 |
baseUrl, err := url.Parse(c.endpoint) |
| 674 |
if err != nil { |
| 675 |
return nil, "", err |
| 676 |
} |
| 677 |
baseUrl.Path += fmt.Sprintf("/v1beta1/%v/versions:search", req.GetResource()) |
| 678 |
|
| 679 |
params := url.Values{} |
| 680 |
params.Add("$alt", "json;enum-encoding=int") |
| 681 |
if req.GetPageSize() != 0 { |
| 682 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 683 |
} |
| 684 |
if req.GetPageToken() != "" { |
| 685 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 686 |
} |
| 687 |
params.Add("query", fmt.Sprintf("%v", req.GetQuery())) |
| 688 |
|
| 689 |
baseUrl.RawQuery = params.Encode() |
| 690 |
|
| 691 |
// Build HTTP headers from client and context metadata. |
| 692 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 693 |
headers := gax.BuildHeaders(ctx, hds...) |
| 694 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 695 |
if settings.Path != "" { |
| 696 |
baseUrl.Path = settings.Path |
| 697 |
} |
| 698 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 699 |
if err != nil { |
| 700 |
return err |
| 701 |
} |
| 702 |
httpReq.Header = headers |
| 703 |
|
| 704 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "SearchVersions") |
| 705 |
if err != nil { |
| 706 |
return err |
| 707 |
} |
| 708 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 709 |
return err |
| 710 |
} |
| 711 |
|
| 712 |
return nil |
| 713 |
}, opts...) |
| 714 |
if e != nil { |
| 715 |
return nil, "", e |
| 716 |
} |
| 717 |
it.Response = resp |
| 718 |
return resp.GetVersions(), resp.GetNextPageToken(), nil |
| 719 |
} |
| 720 |
|
| 721 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 722 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 723 |
if err != nil { |
| 724 |
return "", err |
| 725 |
} |
| 726 |
it.items = append(it.items, items...) |
| 727 |
return nextPageToken, nil |
| 728 |
} |
| 729 |
|
| 730 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 731 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 732 |
it.pageInfo.Token = req.GetPageToken() |
| 733 |
|
| 734 |
return it |
| 735 |
} |