| 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 accounts |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
accountspb "cloud.google.com/go/shopping/merchant/accounts/apiv1/accountspb" |
| 30 |
gax "github.com/googleapis/gax-go/v2" |
| 31 |
"google.golang.org/api/iterator" |
| 32 |
"google.golang.org/api/option" |
| 33 |
"google.golang.org/api/option/internaloption" |
| 34 |
gtransport "google.golang.org/api/transport/grpc" |
| 35 |
httptransport "google.golang.org/api/transport/http" |
| 36 |
"google.golang.org/grpc" |
| 37 |
"google.golang.org/grpc/codes" |
| 38 |
"google.golang.org/protobuf/encoding/protojson" |
| 39 |
"google.golang.org/protobuf/proto" |
| 40 |
) |
| 41 |
|
| 42 |
var newAccountServicesClientHook clientHook |
| 43 |
|
| 44 |
// AccountServicesCallOptions contains the retry settings for each method of AccountServicesClient. |
| 45 |
type AccountServicesCallOptions struct { |
| 46 |
GetAccountService []gax.CallOption |
| 47 |
ListAccountServices []gax.CallOption |
| 48 |
ProposeAccountService []gax.CallOption |
| 49 |
ApproveAccountService []gax.CallOption |
| 50 |
RejectAccountService []gax.CallOption |
| 51 |
} |
| 52 |
|
| 53 |
func defaultAccountServicesGRPCClientOptions() []option.ClientOption { |
| 54 |
return []option.ClientOption{ |
| 55 |
internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"), |
| 56 |
internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"), |
| 57 |
internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"), |
| 58 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 59 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 60 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 61 |
internaloption.EnableJwtWithScope(), |
| 62 |
internaloption.EnableNewAuthLibrary(), |
| 63 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 64 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
func defaultAccountServicesCallOptions() *AccountServicesCallOptions { |
| 69 |
return &AccountServicesCallOptions{ |
| 70 |
GetAccountService: []gax.CallOption{ |
| 71 |
gax.WithTimeout(60000 * time.Millisecond), |
| 72 |
gax.WithRetry(func() gax.Retryer { |
| 73 |
return gax.OnCodes([]codes.Code{ |
| 74 |
codes.Unavailable, |
| 75 |
}, gax.Backoff{ |
| 76 |
Initial: 1000 * time.Millisecond, |
| 77 |
Max: 10000 * time.Millisecond, |
| 78 |
Multiplier: 1.30, |
| 79 |
}) |
| 80 |
}), |
| 81 |
}, |
| 82 |
ListAccountServices: []gax.CallOption{ |
| 83 |
gax.WithTimeout(60000 * time.Millisecond), |
| 84 |
gax.WithRetry(func() gax.Retryer { |
| 85 |
return gax.OnCodes([]codes.Code{ |
| 86 |
codes.Unavailable, |
| 87 |
}, gax.Backoff{ |
| 88 |
Initial: 1000 * time.Millisecond, |
| 89 |
Max: 10000 * time.Millisecond, |
| 90 |
Multiplier: 1.30, |
| 91 |
}) |
| 92 |
}), |
| 93 |
}, |
| 94 |
ProposeAccountService: []gax.CallOption{ |
| 95 |
gax.WithTimeout(60000 * time.Millisecond), |
| 96 |
gax.WithRetry(func() gax.Retryer { |
| 97 |
return gax.OnCodes([]codes.Code{ |
| 98 |
codes.Unavailable, |
| 99 |
}, gax.Backoff{ |
| 100 |
Initial: 1000 * time.Millisecond, |
| 101 |
Max: 10000 * time.Millisecond, |
| 102 |
Multiplier: 1.30, |
| 103 |
}) |
| 104 |
}), |
| 105 |
}, |
| 106 |
ApproveAccountService: []gax.CallOption{ |
| 107 |
gax.WithTimeout(60000 * time.Millisecond), |
| 108 |
gax.WithRetry(func() gax.Retryer { |
| 109 |
return gax.OnCodes([]codes.Code{ |
| 110 |
codes.Unavailable, |
| 111 |
}, gax.Backoff{ |
| 112 |
Initial: 1000 * time.Millisecond, |
| 113 |
Max: 10000 * time.Millisecond, |
| 114 |
Multiplier: 1.30, |
| 115 |
}) |
| 116 |
}), |
| 117 |
}, |
| 118 |
RejectAccountService: []gax.CallOption{ |
| 119 |
gax.WithTimeout(60000 * time.Millisecond), |
| 120 |
gax.WithRetry(func() gax.Retryer { |
| 121 |
return gax.OnCodes([]codes.Code{ |
| 122 |
codes.Unavailable, |
| 123 |
}, gax.Backoff{ |
| 124 |
Initial: 1000 * time.Millisecond, |
| 125 |
Max: 10000 * time.Millisecond, |
| 126 |
Multiplier: 1.30, |
| 127 |
}) |
| 128 |
}), |
| 129 |
}, |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
func defaultAccountServicesRESTCallOptions() *AccountServicesCallOptions { |
| 134 |
return &AccountServicesCallOptions{ |
| 135 |
GetAccountService: []gax.CallOption{ |
| 136 |
gax.WithTimeout(60000 * time.Millisecond), |
| 137 |
gax.WithRetry(func() gax.Retryer { |
| 138 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 139 |
Initial: 1000 * time.Millisecond, |
| 140 |
Max: 10000 * time.Millisecond, |
| 141 |
Multiplier: 1.30, |
| 142 |
}, |
| 143 |
http.StatusServiceUnavailable) |
| 144 |
}), |
| 145 |
}, |
| 146 |
ListAccountServices: []gax.CallOption{ |
| 147 |
gax.WithTimeout(60000 * time.Millisecond), |
| 148 |
gax.WithRetry(func() gax.Retryer { |
| 149 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 150 |
Initial: 1000 * time.Millisecond, |
| 151 |
Max: 10000 * time.Millisecond, |
| 152 |
Multiplier: 1.30, |
| 153 |
}, |
| 154 |
http.StatusServiceUnavailable) |
| 155 |
}), |
| 156 |
}, |
| 157 |
ProposeAccountService: []gax.CallOption{ |
| 158 |
gax.WithTimeout(60000 * time.Millisecond), |
| 159 |
gax.WithRetry(func() gax.Retryer { |
| 160 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 161 |
Initial: 1000 * time.Millisecond, |
| 162 |
Max: 10000 * time.Millisecond, |
| 163 |
Multiplier: 1.30, |
| 164 |
}, |
| 165 |
http.StatusServiceUnavailable) |
| 166 |
}), |
| 167 |
}, |
| 168 |
ApproveAccountService: []gax.CallOption{ |
| 169 |
gax.WithTimeout(60000 * time.Millisecond), |
| 170 |
gax.WithRetry(func() gax.Retryer { |
| 171 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 172 |
Initial: 1000 * time.Millisecond, |
| 173 |
Max: 10000 * time.Millisecond, |
| 174 |
Multiplier: 1.30, |
| 175 |
}, |
| 176 |
http.StatusServiceUnavailable) |
| 177 |
}), |
| 178 |
}, |
| 179 |
RejectAccountService: []gax.CallOption{ |
| 180 |
gax.WithTimeout(60000 * time.Millisecond), |
| 181 |
gax.WithRetry(func() gax.Retryer { |
| 182 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 183 |
Initial: 1000 * time.Millisecond, |
| 184 |
Max: 10000 * time.Millisecond, |
| 185 |
Multiplier: 1.30, |
| 186 |
}, |
| 187 |
http.StatusServiceUnavailable) |
| 188 |
}), |
| 189 |
}, |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
// internalAccountServicesClient is an interface that defines the methods available from Merchant API. |
| 194 |
type internalAccountServicesClient interface { |
| 195 |
Close() error |
| 196 |
setGoogleClientInfo(...string) |
| 197 |
Connection() *grpc.ClientConn |
| 198 |
GetAccountService(context.Context, *accountspb.GetAccountServiceRequest, ...gax.CallOption) (*accountspb.AccountService, error) |
| 199 |
ListAccountServices(context.Context, *accountspb.ListAccountServicesRequest, ...gax.CallOption) *AccountServiceIterator |
| 200 |
ProposeAccountService(context.Context, *accountspb.ProposeAccountServiceRequest, ...gax.CallOption) (*accountspb.AccountService, error) |
| 201 |
ApproveAccountService(context.Context, *accountspb.ApproveAccountServiceRequest, ...gax.CallOption) (*accountspb.AccountService, error) |
| 202 |
RejectAccountService(context.Context, *accountspb.RejectAccountServiceRequest, ...gax.CallOption) error |
| 203 |
} |
| 204 |
|
| 205 |
// AccountServicesClient is a client for interacting with Merchant API. |
| 206 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 207 |
// |
| 208 |
// Service to support AccountService API. |
| 209 |
type AccountServicesClient struct { |
| 210 |
// The internal transport-dependent client. |
| 211 |
internalClient internalAccountServicesClient |
| 212 |
|
| 213 |
// The call options for this service. |
| 214 |
CallOptions *AccountServicesCallOptions |
| 215 |
} |
| 216 |
|
| 217 |
// Wrapper methods routed to the internal client. |
| 218 |
|
| 219 |
// Close closes the connection to the API service. The user should invoke this when |
| 220 |
// the client is no longer required. |
| 221 |
func (c *AccountServicesClient) Close() error { |
| 222 |
return c.internalClient.Close() |
| 223 |
} |
| 224 |
|
| 225 |
// setGoogleClientInfo sets the name and version of the application in |
| 226 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 227 |
// use by Google-written clients. |
| 228 |
func (c *AccountServicesClient) setGoogleClientInfo(keyval ...string) { |
| 229 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 230 |
} |
| 231 |
|
| 232 |
// Connection returns a connection to the API service. |
| 233 |
// |
| 234 |
// Deprecated: Connections are now pooled so this method does not always |
| 235 |
// return the same resource. |
| 236 |
func (c *AccountServicesClient) Connection() *grpc.ClientConn { |
| 237 |
return c.internalClient.Connection() |
| 238 |
} |
| 239 |
|
| 240 |
// GetAccountService retrieve an account service. |
| 241 |
func (c *AccountServicesClient) GetAccountService(ctx context.Context, req *accountspb.GetAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 242 |
return c.internalClient.GetAccountService(ctx, req, opts...) |
| 243 |
} |
| 244 |
|
| 245 |
// ListAccountServices list account services for the specified accounts. Supports filtering. |
| 246 |
func (c *AccountServicesClient) ListAccountServices(ctx context.Context, req *accountspb.ListAccountServicesRequest, opts ...gax.CallOption) *AccountServiceIterator { |
| 247 |
return c.internalClient.ListAccountServices(ctx, req, opts...) |
| 248 |
} |
| 249 |
|
| 250 |
// ProposeAccountService propose an account service. |
| 251 |
func (c *AccountServicesClient) ProposeAccountService(ctx context.Context, req *accountspb.ProposeAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 252 |
return c.internalClient.ProposeAccountService(ctx, req, opts...) |
| 253 |
} |
| 254 |
|
| 255 |
// ApproveAccountService approve an account service proposal. |
| 256 |
func (c *AccountServicesClient) ApproveAccountService(ctx context.Context, req *accountspb.ApproveAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 257 |
return c.internalClient.ApproveAccountService(ctx, req, opts...) |
| 258 |
} |
| 259 |
|
| 260 |
// RejectAccountService reject an account service (both proposed and approve services can be |
| 261 |
// rejected). |
| 262 |
func (c *AccountServicesClient) RejectAccountService(ctx context.Context, req *accountspb.RejectAccountServiceRequest, opts ...gax.CallOption) error { |
| 263 |
return c.internalClient.RejectAccountService(ctx, req, opts...) |
| 264 |
} |
| 265 |
|
| 266 |
// accountServicesGRPCClient is a client for interacting with Merchant API over gRPC transport. |
| 267 |
// |
| 268 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 269 |
type accountServicesGRPCClient struct { |
| 270 |
// Connection pool of gRPC connections to the service. |
| 271 |
connPool gtransport.ConnPool |
| 272 |
|
| 273 |
// Points back to the CallOptions field of the containing AccountServicesClient |
| 274 |
CallOptions **AccountServicesCallOptions |
| 275 |
|
| 276 |
// The gRPC API client. |
| 277 |
accountServicesClient accountspb.AccountServicesServiceClient |
| 278 |
|
| 279 |
// The x-goog-* metadata to be sent with each request. |
| 280 |
xGoogHeaders []string |
| 281 |
|
| 282 |
logger *slog.Logger |
| 283 |
} |
| 284 |
|
| 285 |
// NewAccountServicesClient creates a new account services service client based on gRPC. |
| 286 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 287 |
// |
| 288 |
// Service to support AccountService API. |
| 289 |
func NewAccountServicesClient(ctx context.Context, opts ...option.ClientOption) (*AccountServicesClient, error) { |
| 290 |
clientOpts := defaultAccountServicesGRPCClientOptions() |
| 291 |
if newAccountServicesClientHook != nil { |
| 292 |
hookOpts, err := newAccountServicesClientHook(ctx, clientHookParams{}) |
| 293 |
if err != nil { |
| 294 |
return nil, err |
| 295 |
} |
| 296 |
clientOpts = append(clientOpts, hookOpts...) |
| 297 |
} |
| 298 |
|
| 299 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 300 |
if err != nil { |
| 301 |
return nil, err |
| 302 |
} |
| 303 |
client := AccountServicesClient{CallOptions: defaultAccountServicesCallOptions()} |
| 304 |
|
| 305 |
c := &accountServicesGRPCClient{ |
| 306 |
connPool: connPool, |
| 307 |
accountServicesClient: accountspb.NewAccountServicesServiceClient(connPool), |
| 308 |
CallOptions: &client.CallOptions, |
| 309 |
logger: internaloption.GetLogger(opts), |
| 310 |
} |
| 311 |
c.setGoogleClientInfo() |
| 312 |
|
| 313 |
client.internalClient = c |
| 314 |
|
| 315 |
return &client, nil |
| 316 |
} |
| 317 |
|
| 318 |
// Connection returns a connection to the API service. |
| 319 |
// |
| 320 |
// Deprecated: Connections are now pooled so this method does not always |
| 321 |
// return the same resource. |
| 322 |
func (c *accountServicesGRPCClient) Connection() *grpc.ClientConn { |
| 323 |
return c.connPool.Conn() |
| 324 |
} |
| 325 |
|
| 326 |
// setGoogleClientInfo sets the name and version of the application in |
| 327 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 328 |
// use by Google-written clients. |
| 329 |
func (c *accountServicesGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 330 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 331 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 332 |
c.xGoogHeaders = []string{ |
| 333 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
// Close closes the connection to the API service. The user should invoke this when |
| 338 |
// the client is no longer required. |
| 339 |
func (c *accountServicesGRPCClient) Close() error { |
| 340 |
return c.connPool.Close() |
| 341 |
} |
| 342 |
|
| 343 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 344 |
type accountServicesRESTClient struct { |
| 345 |
// The http endpoint to connect to. |
| 346 |
endpoint string |
| 347 |
|
| 348 |
// The http client. |
| 349 |
httpClient *http.Client |
| 350 |
|
| 351 |
// The x-goog-* headers to be sent with each request. |
| 352 |
xGoogHeaders []string |
| 353 |
|
| 354 |
// Points back to the CallOptions field of the containing AccountServicesClient |
| 355 |
CallOptions **AccountServicesCallOptions |
| 356 |
|
| 357 |
logger *slog.Logger |
| 358 |
} |
| 359 |
|
| 360 |
// NewAccountServicesRESTClient creates a new account services service rest client. |
| 361 |
// |
| 362 |
// Service to support AccountService API. |
| 363 |
func NewAccountServicesRESTClient(ctx context.Context, opts ...option.ClientOption) (*AccountServicesClient, error) { |
| 364 |
clientOpts := append(defaultAccountServicesRESTClientOptions(), opts...) |
| 365 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 366 |
if err != nil { |
| 367 |
return nil, err |
| 368 |
} |
| 369 |
|
| 370 |
callOpts := defaultAccountServicesRESTCallOptions() |
| 371 |
c := &accountServicesRESTClient{ |
| 372 |
endpoint: endpoint, |
| 373 |
httpClient: httpClient, |
| 374 |
CallOptions: &callOpts, |
| 375 |
logger: internaloption.GetLogger(opts), |
| 376 |
} |
| 377 |
c.setGoogleClientInfo() |
| 378 |
|
| 379 |
return &AccountServicesClient{internalClient: c, CallOptions: callOpts}, nil |
| 380 |
} |
| 381 |
|
| 382 |
func defaultAccountServicesRESTClientOptions() []option.ClientOption { |
| 383 |
return []option.ClientOption{ |
| 384 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 385 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 386 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 387 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 388 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 389 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 390 |
internaloption.EnableNewAuthLibrary(), |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
// setGoogleClientInfo sets the name and version of the application in |
| 395 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 396 |
// use by Google-written clients. |
| 397 |
func (c *accountServicesRESTClient) setGoogleClientInfo(keyval ...string) { |
| 398 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 399 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 400 |
c.xGoogHeaders = []string{ |
| 401 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
// Close closes the connection to the API service. The user should invoke this when |
| 406 |
// the client is no longer required. |
| 407 |
func (c *accountServicesRESTClient) Close() error { |
| 408 |
// Replace httpClient with nil to force cleanup. |
| 409 |
c.httpClient = nil |
| 410 |
return nil |
| 411 |
} |
| 412 |
|
| 413 |
// Connection returns a connection to the API service. |
| 414 |
// |
| 415 |
// Deprecated: This method always returns nil. |
| 416 |
func (c *accountServicesRESTClient) Connection() *grpc.ClientConn { |
| 417 |
return nil |
| 418 |
} |
| 419 |
func (c *accountServicesGRPCClient) GetAccountService(ctx context.Context, req *accountspb.GetAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 420 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 421 |
|
| 422 |
hds = append(c.xGoogHeaders, hds...) |
| 423 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 424 |
opts = append((*c.CallOptions).GetAccountService[0:len((*c.CallOptions).GetAccountService):len((*c.CallOptions).GetAccountService)], opts...) |
| 425 |
var resp *accountspb.AccountService |
| 426 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 427 |
var err error |
| 428 |
resp, err = executeRPC(ctx, c.accountServicesClient.GetAccountService, req, settings.GRPC, c.logger, "GetAccountService") |
| 429 |
return err |
| 430 |
}, opts...) |
| 431 |
if err != nil { |
| 432 |
return nil, err |
| 433 |
} |
| 434 |
return resp, nil |
| 435 |
} |
| 436 |
|
| 437 |
func (c *accountServicesGRPCClient) ListAccountServices(ctx context.Context, req *accountspb.ListAccountServicesRequest, opts ...gax.CallOption) *AccountServiceIterator { |
| 438 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 439 |
|
| 440 |
hds = append(c.xGoogHeaders, hds...) |
| 441 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 442 |
opts = append((*c.CallOptions).ListAccountServices[0:len((*c.CallOptions).ListAccountServices):len((*c.CallOptions).ListAccountServices)], opts...) |
| 443 |
it := &AccountServiceIterator{} |
| 444 |
req = proto.Clone(req).(*accountspb.ListAccountServicesRequest) |
| 445 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountService, string, error) { |
| 446 |
resp := &accountspb.ListAccountServicesResponse{} |
| 447 |
if pageToken != "" { |
| 448 |
req.PageToken = pageToken |
| 449 |
} |
| 450 |
if pageSize > math.MaxInt32 { |
| 451 |
req.PageSize = math.MaxInt32 |
| 452 |
} else if pageSize != 0 { |
| 453 |
req.PageSize = int32(pageSize) |
| 454 |
} |
| 455 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 456 |
var err error |
| 457 |
resp, err = executeRPC(ctx, c.accountServicesClient.ListAccountServices, req, settings.GRPC, c.logger, "ListAccountServices") |
| 458 |
return err |
| 459 |
}, opts...) |
| 460 |
if err != nil { |
| 461 |
return nil, "", err |
| 462 |
} |
| 463 |
|
| 464 |
it.Response = resp |
| 465 |
return resp.GetAccountServices(), resp.GetNextPageToken(), nil |
| 466 |
} |
| 467 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 468 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 469 |
if err != nil { |
| 470 |
return "", err |
| 471 |
} |
| 472 |
it.items = append(it.items, items...) |
| 473 |
return nextPageToken, nil |
| 474 |
} |
| 475 |
|
| 476 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 477 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 478 |
it.pageInfo.Token = req.GetPageToken() |
| 479 |
|
| 480 |
return it |
| 481 |
} |
| 482 |
|
| 483 |
func (c *accountServicesGRPCClient) ProposeAccountService(ctx context.Context, req *accountspb.ProposeAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 484 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 485 |
|
| 486 |
hds = append(c.xGoogHeaders, hds...) |
| 487 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 488 |
opts = append((*c.CallOptions).ProposeAccountService[0:len((*c.CallOptions).ProposeAccountService):len((*c.CallOptions).ProposeAccountService)], opts...) |
| 489 |
var resp *accountspb.AccountService |
| 490 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 491 |
var err error |
| 492 |
resp, err = executeRPC(ctx, c.accountServicesClient.ProposeAccountService, req, settings.GRPC, c.logger, "ProposeAccountService") |
| 493 |
return err |
| 494 |
}, opts...) |
| 495 |
if err != nil { |
| 496 |
return nil, err |
| 497 |
} |
| 498 |
return resp, nil |
| 499 |
} |
| 500 |
|
| 501 |
func (c *accountServicesGRPCClient) ApproveAccountService(ctx context.Context, req *accountspb.ApproveAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 502 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 503 |
|
| 504 |
hds = append(c.xGoogHeaders, hds...) |
| 505 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 506 |
opts = append((*c.CallOptions).ApproveAccountService[0:len((*c.CallOptions).ApproveAccountService):len((*c.CallOptions).ApproveAccountService)], opts...) |
| 507 |
var resp *accountspb.AccountService |
| 508 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 509 |
var err error |
| 510 |
resp, err = executeRPC(ctx, c.accountServicesClient.ApproveAccountService, req, settings.GRPC, c.logger, "ApproveAccountService") |
| 511 |
return err |
| 512 |
}, opts...) |
| 513 |
if err != nil { |
| 514 |
return nil, err |
| 515 |
} |
| 516 |
return resp, nil |
| 517 |
} |
| 518 |
|
| 519 |
func (c *accountServicesGRPCClient) RejectAccountService(ctx context.Context, req *accountspb.RejectAccountServiceRequest, opts ...gax.CallOption) error { |
| 520 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 521 |
|
| 522 |
hds = append(c.xGoogHeaders, hds...) |
| 523 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 524 |
opts = append((*c.CallOptions).RejectAccountService[0:len((*c.CallOptions).RejectAccountService):len((*c.CallOptions).RejectAccountService)], opts...) |
| 525 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 526 |
var err error |
| 527 |
_, err = executeRPC(ctx, c.accountServicesClient.RejectAccountService, req, settings.GRPC, c.logger, "RejectAccountService") |
| 528 |
return err |
| 529 |
}, opts...) |
| 530 |
return err |
| 531 |
} |
| 532 |
|
| 533 |
// GetAccountService retrieve an account service. |
| 534 |
func (c *accountServicesRESTClient) GetAccountService(ctx context.Context, req *accountspb.GetAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 535 |
baseUrl, err := url.Parse(c.endpoint) |
| 536 |
if err != nil { |
| 537 |
return nil, err |
| 538 |
} |
| 539 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v", req.GetName()) |
| 540 |
|
| 541 |
params := url.Values{} |
| 542 |
params.Add("$alt", "json;enum-encoding=int") |
| 543 |
|
| 544 |
baseUrl.RawQuery = params.Encode() |
| 545 |
|
| 546 |
// Build HTTP headers from client and context metadata. |
| 547 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 548 |
|
| 549 |
hds = append(c.xGoogHeaders, hds...) |
| 550 |
hds = append(hds, "Content-Type", "application/json") |
| 551 |
headers := gax.BuildHeaders(ctx, hds...) |
| 552 |
opts = append((*c.CallOptions).GetAccountService[0:len((*c.CallOptions).GetAccountService):len((*c.CallOptions).GetAccountService)], opts...) |
| 553 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 554 |
resp := &accountspb.AccountService{} |
| 555 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 556 |
if settings.Path != "" { |
| 557 |
baseUrl.Path = settings.Path |
| 558 |
} |
| 559 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 560 |
if err != nil { |
| 561 |
return err |
| 562 |
} |
| 563 |
httpReq = httpReq.WithContext(ctx) |
| 564 |
httpReq.Header = headers |
| 565 |
|
| 566 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAccountService") |
| 567 |
if err != nil { |
| 568 |
return err |
| 569 |
} |
| 570 |
|
| 571 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 572 |
return err |
| 573 |
} |
| 574 |
|
| 575 |
return nil |
| 576 |
}, opts...) |
| 577 |
if e != nil { |
| 578 |
return nil, e |
| 579 |
} |
| 580 |
return resp, nil |
| 581 |
} |
| 582 |
|
| 583 |
// ListAccountServices list account services for the specified accounts. Supports filtering. |
| 584 |
func (c *accountServicesRESTClient) ListAccountServices(ctx context.Context, req *accountspb.ListAccountServicesRequest, opts ...gax.CallOption) *AccountServiceIterator { |
| 585 |
it := &AccountServiceIterator{} |
| 586 |
req = proto.Clone(req).(*accountspb.ListAccountServicesRequest) |
| 587 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 588 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.AccountService, string, error) { |
| 589 |
resp := &accountspb.ListAccountServicesResponse{} |
| 590 |
if pageToken != "" { |
| 591 |
req.PageToken = pageToken |
| 592 |
} |
| 593 |
if pageSize > math.MaxInt32 { |
| 594 |
req.PageSize = math.MaxInt32 |
| 595 |
} else if pageSize != 0 { |
| 596 |
req.PageSize = int32(pageSize) |
| 597 |
} |
| 598 |
baseUrl, err := url.Parse(c.endpoint) |
| 599 |
if err != nil { |
| 600 |
return nil, "", err |
| 601 |
} |
| 602 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/services", req.GetParent()) |
| 603 |
|
| 604 |
params := url.Values{} |
| 605 |
params.Add("$alt", "json;enum-encoding=int") |
| 606 |
if req.GetPageSize() != 0 { |
| 607 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 608 |
} |
| 609 |
if req.GetPageToken() != "" { |
| 610 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 611 |
} |
| 612 |
|
| 613 |
baseUrl.RawQuery = params.Encode() |
| 614 |
|
| 615 |
// Build HTTP headers from client and context metadata. |
| 616 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 617 |
headers := gax.BuildHeaders(ctx, hds...) |
| 618 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 619 |
if settings.Path != "" { |
| 620 |
baseUrl.Path = settings.Path |
| 621 |
} |
| 622 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 623 |
if err != nil { |
| 624 |
return err |
| 625 |
} |
| 626 |
httpReq.Header = headers |
| 627 |
|
| 628 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccountServices") |
| 629 |
if err != nil { |
| 630 |
return err |
| 631 |
} |
| 632 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 633 |
return err |
| 634 |
} |
| 635 |
|
| 636 |
return nil |
| 637 |
}, opts...) |
| 638 |
if e != nil { |
| 639 |
return nil, "", e |
| 640 |
} |
| 641 |
it.Response = resp |
| 642 |
return resp.GetAccountServices(), resp.GetNextPageToken(), nil |
| 643 |
} |
| 644 |
|
| 645 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 646 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 647 |
if err != nil { |
| 648 |
return "", err |
| 649 |
} |
| 650 |
it.items = append(it.items, items...) |
| 651 |
return nextPageToken, nil |
| 652 |
} |
| 653 |
|
| 654 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 655 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 656 |
it.pageInfo.Token = req.GetPageToken() |
| 657 |
|
| 658 |
return it |
| 659 |
} |
| 660 |
|
| 661 |
// ProposeAccountService propose an account service. |
| 662 |
func (c *accountServicesRESTClient) ProposeAccountService(ctx context.Context, req *accountspb.ProposeAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 663 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 664 |
jsonReq, err := m.Marshal(req) |
| 665 |
if err != nil { |
| 666 |
return nil, err |
| 667 |
} |
| 668 |
|
| 669 |
baseUrl, err := url.Parse(c.endpoint) |
| 670 |
if err != nil { |
| 671 |
return nil, err |
| 672 |
} |
| 673 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v/services:propose", req.GetParent()) |
| 674 |
|
| 675 |
params := url.Values{} |
| 676 |
params.Add("$alt", "json;enum-encoding=int") |
| 677 |
|
| 678 |
baseUrl.RawQuery = params.Encode() |
| 679 |
|
| 680 |
// Build HTTP headers from client and context metadata. |
| 681 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 682 |
|
| 683 |
hds = append(c.xGoogHeaders, hds...) |
| 684 |
hds = append(hds, "Content-Type", "application/json") |
| 685 |
headers := gax.BuildHeaders(ctx, hds...) |
| 686 |
opts = append((*c.CallOptions).ProposeAccountService[0:len((*c.CallOptions).ProposeAccountService):len((*c.CallOptions).ProposeAccountService)], opts...) |
| 687 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 688 |
resp := &accountspb.AccountService{} |
| 689 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 690 |
if settings.Path != "" { |
| 691 |
baseUrl.Path = settings.Path |
| 692 |
} |
| 693 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 694 |
if err != nil { |
| 695 |
return err |
| 696 |
} |
| 697 |
httpReq = httpReq.WithContext(ctx) |
| 698 |
httpReq.Header = headers |
| 699 |
|
| 700 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ProposeAccountService") |
| 701 |
if err != nil { |
| 702 |
return err |
| 703 |
} |
| 704 |
|
| 705 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 706 |
return err |
| 707 |
} |
| 708 |
|
| 709 |
return nil |
| 710 |
}, opts...) |
| 711 |
if e != nil { |
| 712 |
return nil, e |
| 713 |
} |
| 714 |
return resp, nil |
| 715 |
} |
| 716 |
|
| 717 |
// ApproveAccountService approve an account service proposal. |
| 718 |
func (c *accountServicesRESTClient) ApproveAccountService(ctx context.Context, req *accountspb.ApproveAccountServiceRequest, opts ...gax.CallOption) (*accountspb.AccountService, error) { |
| 719 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 720 |
jsonReq, err := m.Marshal(req) |
| 721 |
if err != nil { |
| 722 |
return nil, err |
| 723 |
} |
| 724 |
|
| 725 |
baseUrl, err := url.Parse(c.endpoint) |
| 726 |
if err != nil { |
| 727 |
return nil, err |
| 728 |
} |
| 729 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v:approve", req.GetName()) |
| 730 |
|
| 731 |
params := url.Values{} |
| 732 |
params.Add("$alt", "json;enum-encoding=int") |
| 733 |
|
| 734 |
baseUrl.RawQuery = params.Encode() |
| 735 |
|
| 736 |
// Build HTTP headers from client and context metadata. |
| 737 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 738 |
|
| 739 |
hds = append(c.xGoogHeaders, hds...) |
| 740 |
hds = append(hds, "Content-Type", "application/json") |
| 741 |
headers := gax.BuildHeaders(ctx, hds...) |
| 742 |
opts = append((*c.CallOptions).ApproveAccountService[0:len((*c.CallOptions).ApproveAccountService):len((*c.CallOptions).ApproveAccountService)], opts...) |
| 743 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 744 |
resp := &accountspb.AccountService{} |
| 745 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 746 |
if settings.Path != "" { |
| 747 |
baseUrl.Path = settings.Path |
| 748 |
} |
| 749 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 750 |
if err != nil { |
| 751 |
return err |
| 752 |
} |
| 753 |
httpReq = httpReq.WithContext(ctx) |
| 754 |
httpReq.Header = headers |
| 755 |
|
| 756 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ApproveAccountService") |
| 757 |
if err != nil { |
| 758 |
return err |
| 759 |
} |
| 760 |
|
| 761 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 762 |
return err |
| 763 |
} |
| 764 |
|
| 765 |
return nil |
| 766 |
}, opts...) |
| 767 |
if e != nil { |
| 768 |
return nil, e |
| 769 |
} |
| 770 |
return resp, nil |
| 771 |
} |
| 772 |
|
| 773 |
// RejectAccountService reject an account service (both proposed and approve services can be |
| 774 |
// rejected). |
| 775 |
func (c *accountServicesRESTClient) RejectAccountService(ctx context.Context, req *accountspb.RejectAccountServiceRequest, opts ...gax.CallOption) error { |
| 776 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 777 |
jsonReq, err := m.Marshal(req) |
| 778 |
if err != nil { |
| 779 |
return err |
| 780 |
} |
| 781 |
|
| 782 |
baseUrl, err := url.Parse(c.endpoint) |
| 783 |
if err != nil { |
| 784 |
return err |
| 785 |
} |
| 786 |
baseUrl.Path += fmt.Sprintf("/accounts/v1/%v:reject", req.GetName()) |
| 787 |
|
| 788 |
params := url.Values{} |
| 789 |
params.Add("$alt", "json;enum-encoding=int") |
| 790 |
|
| 791 |
baseUrl.RawQuery = params.Encode() |
| 792 |
|
| 793 |
// Build HTTP headers from client and context metadata. |
| 794 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 795 |
|
| 796 |
hds = append(c.xGoogHeaders, hds...) |
| 797 |
hds = append(hds, "Content-Type", "application/json") |
| 798 |
headers := gax.BuildHeaders(ctx, hds...) |
| 799 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 800 |
if settings.Path != "" { |
| 801 |
baseUrl.Path = settings.Path |
| 802 |
} |
| 803 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 804 |
if err != nil { |
| 805 |
return err |
| 806 |
} |
| 807 |
httpReq = httpReq.WithContext(ctx) |
| 808 |
httpReq.Header = headers |
| 809 |
|
| 810 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RejectAccountService") |
| 811 |
return err |
| 812 |
}, opts...) |
| 813 |
} |