| 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/apiv1beta/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 newClientHook clientHook |
| 43 |
|
| 44 |
// CallOptions contains the retry settings for each method of Client. |
| 45 |
type CallOptions struct { |
| 46 |
GetAccount []gax.CallOption |
| 47 |
CreateAndConfigureAccount []gax.CallOption |
| 48 |
DeleteAccount []gax.CallOption |
| 49 |
UpdateAccount []gax.CallOption |
| 50 |
ListAccounts []gax.CallOption |
| 51 |
ListSubAccounts []gax.CallOption |
| 52 |
} |
| 53 |
|
| 54 |
func defaultGRPCClientOptions() []option.ClientOption { |
| 55 |
return []option.ClientOption{ |
| 56 |
internaloption.WithDefaultEndpoint("merchantapi.googleapis.com:443"), |
| 57 |
internaloption.WithDefaultEndpointTemplate("merchantapi.UNIVERSE_DOMAIN:443"), |
| 58 |
internaloption.WithDefaultMTLSEndpoint("merchantapi.mtls.googleapis.com:443"), |
| 59 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 60 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 61 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 62 |
internaloption.EnableJwtWithScope(), |
| 63 |
internaloption.EnableNewAuthLibrary(), |
| 64 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 65 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
func defaultCallOptions() *CallOptions { |
| 70 |
return &CallOptions{ |
| 71 |
GetAccount: []gax.CallOption{ |
| 72 |
gax.WithTimeout(60000 * time.Millisecond), |
| 73 |
gax.WithRetry(func() gax.Retryer { |
| 74 |
return gax.OnCodes([]codes.Code{ |
| 75 |
codes.Unavailable, |
| 76 |
}, gax.Backoff{ |
| 77 |
Initial: 1000 * time.Millisecond, |
| 78 |
Max: 10000 * time.Millisecond, |
| 79 |
Multiplier: 1.30, |
| 80 |
}) |
| 81 |
}), |
| 82 |
}, |
| 83 |
CreateAndConfigureAccount: []gax.CallOption{ |
| 84 |
gax.WithTimeout(60000 * time.Millisecond), |
| 85 |
gax.WithRetry(func() gax.Retryer { |
| 86 |
return gax.OnCodes([]codes.Code{ |
| 87 |
codes.Unavailable, |
| 88 |
}, gax.Backoff{ |
| 89 |
Initial: 1000 * time.Millisecond, |
| 90 |
Max: 10000 * time.Millisecond, |
| 91 |
Multiplier: 1.30, |
| 92 |
}) |
| 93 |
}), |
| 94 |
}, |
| 95 |
DeleteAccount: []gax.CallOption{ |
| 96 |
gax.WithTimeout(60000 * time.Millisecond), |
| 97 |
gax.WithRetry(func() gax.Retryer { |
| 98 |
return gax.OnCodes([]codes.Code{ |
| 99 |
codes.Unavailable, |
| 100 |
}, gax.Backoff{ |
| 101 |
Initial: 1000 * time.Millisecond, |
| 102 |
Max: 10000 * time.Millisecond, |
| 103 |
Multiplier: 1.30, |
| 104 |
}) |
| 105 |
}), |
| 106 |
}, |
| 107 |
UpdateAccount: []gax.CallOption{ |
| 108 |
gax.WithTimeout(60000 * time.Millisecond), |
| 109 |
gax.WithRetry(func() gax.Retryer { |
| 110 |
return gax.OnCodes([]codes.Code{ |
| 111 |
codes.Unavailable, |
| 112 |
}, gax.Backoff{ |
| 113 |
Initial: 1000 * time.Millisecond, |
| 114 |
Max: 10000 * time.Millisecond, |
| 115 |
Multiplier: 1.30, |
| 116 |
}) |
| 117 |
}), |
| 118 |
}, |
| 119 |
ListAccounts: []gax.CallOption{ |
| 120 |
gax.WithTimeout(60000 * time.Millisecond), |
| 121 |
gax.WithRetry(func() gax.Retryer { |
| 122 |
return gax.OnCodes([]codes.Code{ |
| 123 |
codes.Unavailable, |
| 124 |
}, gax.Backoff{ |
| 125 |
Initial: 1000 * time.Millisecond, |
| 126 |
Max: 10000 * time.Millisecond, |
| 127 |
Multiplier: 1.30, |
| 128 |
}) |
| 129 |
}), |
| 130 |
}, |
| 131 |
ListSubAccounts: []gax.CallOption{ |
| 132 |
gax.WithTimeout(60000 * time.Millisecond), |
| 133 |
gax.WithRetry(func() gax.Retryer { |
| 134 |
return gax.OnCodes([]codes.Code{ |
| 135 |
codes.Unavailable, |
| 136 |
}, gax.Backoff{ |
| 137 |
Initial: 1000 * time.Millisecond, |
| 138 |
Max: 10000 * time.Millisecond, |
| 139 |
Multiplier: 1.30, |
| 140 |
}) |
| 141 |
}), |
| 142 |
}, |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
func defaultRESTCallOptions() *CallOptions { |
| 147 |
return &CallOptions{ |
| 148 |
GetAccount: []gax.CallOption{ |
| 149 |
gax.WithTimeout(60000 * time.Millisecond), |
| 150 |
gax.WithRetry(func() gax.Retryer { |
| 151 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 152 |
Initial: 1000 * time.Millisecond, |
| 153 |
Max: 10000 * time.Millisecond, |
| 154 |
Multiplier: 1.30, |
| 155 |
}, |
| 156 |
http.StatusServiceUnavailable) |
| 157 |
}), |
| 158 |
}, |
| 159 |
CreateAndConfigureAccount: []gax.CallOption{ |
| 160 |
gax.WithTimeout(60000 * time.Millisecond), |
| 161 |
gax.WithRetry(func() gax.Retryer { |
| 162 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 163 |
Initial: 1000 * time.Millisecond, |
| 164 |
Max: 10000 * time.Millisecond, |
| 165 |
Multiplier: 1.30, |
| 166 |
}, |
| 167 |
http.StatusServiceUnavailable) |
| 168 |
}), |
| 169 |
}, |
| 170 |
DeleteAccount: []gax.CallOption{ |
| 171 |
gax.WithTimeout(60000 * time.Millisecond), |
| 172 |
gax.WithRetry(func() gax.Retryer { |
| 173 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 174 |
Initial: 1000 * time.Millisecond, |
| 175 |
Max: 10000 * time.Millisecond, |
| 176 |
Multiplier: 1.30, |
| 177 |
}, |
| 178 |
http.StatusServiceUnavailable) |
| 179 |
}), |
| 180 |
}, |
| 181 |
UpdateAccount: []gax.CallOption{ |
| 182 |
gax.WithTimeout(60000 * time.Millisecond), |
| 183 |
gax.WithRetry(func() gax.Retryer { |
| 184 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 185 |
Initial: 1000 * time.Millisecond, |
| 186 |
Max: 10000 * time.Millisecond, |
| 187 |
Multiplier: 1.30, |
| 188 |
}, |
| 189 |
http.StatusServiceUnavailable) |
| 190 |
}), |
| 191 |
}, |
| 192 |
ListAccounts: []gax.CallOption{ |
| 193 |
gax.WithTimeout(60000 * time.Millisecond), |
| 194 |
gax.WithRetry(func() gax.Retryer { |
| 195 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 196 |
Initial: 1000 * time.Millisecond, |
| 197 |
Max: 10000 * time.Millisecond, |
| 198 |
Multiplier: 1.30, |
| 199 |
}, |
| 200 |
http.StatusServiceUnavailable) |
| 201 |
}), |
| 202 |
}, |
| 203 |
ListSubAccounts: []gax.CallOption{ |
| 204 |
gax.WithTimeout(60000 * time.Millisecond), |
| 205 |
gax.WithRetry(func() gax.Retryer { |
| 206 |
return gax.OnHTTPCodes(gax.Backoff{ |
| 207 |
Initial: 1000 * time.Millisecond, |
| 208 |
Max: 10000 * time.Millisecond, |
| 209 |
Multiplier: 1.30, |
| 210 |
}, |
| 211 |
http.StatusServiceUnavailable) |
| 212 |
}), |
| 213 |
}, |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
// internalClient is an interface that defines the methods available from Merchant API. |
| 218 |
type internalClient interface { |
| 219 |
Close() error |
| 220 |
setGoogleClientInfo(...string) |
| 221 |
Connection() *grpc.ClientConn |
| 222 |
GetAccount(context.Context, *accountspb.GetAccountRequest, ...gax.CallOption) (*accountspb.Account, error) |
| 223 |
CreateAndConfigureAccount(context.Context, *accountspb.CreateAndConfigureAccountRequest, ...gax.CallOption) (*accountspb.Account, error) |
| 224 |
DeleteAccount(context.Context, *accountspb.DeleteAccountRequest, ...gax.CallOption) error |
| 225 |
UpdateAccount(context.Context, *accountspb.UpdateAccountRequest, ...gax.CallOption) (*accountspb.Account, error) |
| 226 |
ListAccounts(context.Context, *accountspb.ListAccountsRequest, ...gax.CallOption) *AccountIterator |
| 227 |
ListSubAccounts(context.Context, *accountspb.ListSubAccountsRequest, ...gax.CallOption) *AccountIterator |
| 228 |
} |
| 229 |
|
| 230 |
// Client is a client for interacting with Merchant API. |
| 231 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 232 |
// |
| 233 |
// Service to support Accounts API. |
| 234 |
type Client struct { |
| 235 |
// The internal transport-dependent client. |
| 236 |
internalClient internalClient |
| 237 |
|
| 238 |
// The call options for this service. |
| 239 |
CallOptions *CallOptions |
| 240 |
} |
| 241 |
|
| 242 |
// Wrapper methods routed to the internal client. |
| 243 |
|
| 244 |
// Close closes the connection to the API service. The user should invoke this when |
| 245 |
// the client is no longer required. |
| 246 |
func (c *Client) Close() error { |
| 247 |
return c.internalClient.Close() |
| 248 |
} |
| 249 |
|
| 250 |
// setGoogleClientInfo sets the name and version of the application in |
| 251 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 252 |
// use by Google-written clients. |
| 253 |
func (c *Client) setGoogleClientInfo(keyval ...string) { |
| 254 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 255 |
} |
| 256 |
|
| 257 |
// Connection returns a connection to the API service. |
| 258 |
// |
| 259 |
// Deprecated: Connections are now pooled so this method does not always |
| 260 |
// return the same resource. |
| 261 |
func (c *Client) Connection() *grpc.ClientConn { |
| 262 |
return c.internalClient.Connection() |
| 263 |
} |
| 264 |
|
| 265 |
// GetAccount retrieves an account from your Merchant Center account. |
| 266 |
// After inserting, updating, or deleting an account, it may take several |
| 267 |
// minutes before changes take effect. |
| 268 |
func (c *Client) GetAccount(ctx context.Context, req *accountspb.GetAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 269 |
return c.internalClient.GetAccount(ctx, req, opts...) |
| 270 |
} |
| 271 |
|
| 272 |
// CreateAndConfigureAccount creates a standalone Merchant Center account with additional configuration. |
| 273 |
// Adds the user that makes the request as an admin for the new account. |
| 274 |
func (c *Client) CreateAndConfigureAccount(ctx context.Context, req *accountspb.CreateAndConfigureAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 275 |
return c.internalClient.CreateAndConfigureAccount(ctx, req, opts...) |
| 276 |
} |
| 277 |
|
| 278 |
// DeleteAccount deletes the specified account regardless of its type: standalone, MCA or |
| 279 |
// sub-account. Deleting an MCA leads to the deletion of all of its |
| 280 |
// sub-accounts. Executing this method requires admin access. |
| 281 |
// The deletion succeeds only if the account does not provide services |
| 282 |
// to any other account and has no processed offers. You can use the force |
| 283 |
// parameter to override this. |
| 284 |
func (c *Client) DeleteAccount(ctx context.Context, req *accountspb.DeleteAccountRequest, opts ...gax.CallOption) error { |
| 285 |
return c.internalClient.DeleteAccount(ctx, req, opts...) |
| 286 |
} |
| 287 |
|
| 288 |
// UpdateAccount updates an account regardless of its type: standalone, MCA or sub-account. |
| 289 |
// Executing this method requires admin access. |
| 290 |
func (c *Client) UpdateAccount(ctx context.Context, req *accountspb.UpdateAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 291 |
return c.internalClient.UpdateAccount(ctx, req, opts...) |
| 292 |
} |
| 293 |
|
| 294 |
// ListAccounts lists accounts accessible to the calling user and matching the |
| 295 |
// constraints of the request such as page size or filters. |
| 296 |
// This is not just listing the sub-accounts of an MCA, but all accounts the |
| 297 |
// calling user has access to including other MCAs, linked accounts, |
| 298 |
// standalone accounts and so on. If no filter is provided, then it returns |
| 299 |
// accounts the user is directly added to. |
| 300 |
func (c *Client) ListAccounts(ctx context.Context, req *accountspb.ListAccountsRequest, opts ...gax.CallOption) *AccountIterator { |
| 301 |
return c.internalClient.ListAccounts(ctx, req, opts...) |
| 302 |
} |
| 303 |
|
| 304 |
// ListSubAccounts list all sub-accounts for a given multi client account. This is a |
| 305 |
// convenience wrapper for the more powerful ListAccounts method. This |
| 306 |
// method will produce the same results as calling ListsAccounts with the |
| 307 |
// following filter: |
| 308 |
// relationship(providerId={parent} AND service(type="ACCOUNT_AGGREGATION")) |
| 309 |
func (c *Client) ListSubAccounts(ctx context.Context, req *accountspb.ListSubAccountsRequest, opts ...gax.CallOption) *AccountIterator { |
| 310 |
return c.internalClient.ListSubAccounts(ctx, req, opts...) |
| 311 |
} |
| 312 |
|
| 313 |
// gRPCClient is a client for interacting with Merchant API over gRPC transport. |
| 314 |
// |
| 315 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 316 |
type gRPCClient struct { |
| 317 |
// Connection pool of gRPC connections to the service. |
| 318 |
connPool gtransport.ConnPool |
| 319 |
|
| 320 |
// Points back to the CallOptions field of the containing Client |
| 321 |
CallOptions **CallOptions |
| 322 |
|
| 323 |
// The gRPC API client. |
| 324 |
client accountspb.AccountsServiceClient |
| 325 |
|
| 326 |
// The x-goog-* metadata to be sent with each request. |
| 327 |
xGoogHeaders []string |
| 328 |
|
| 329 |
logger *slog.Logger |
| 330 |
} |
| 331 |
|
| 332 |
// NewClient creates a new accounts service client based on gRPC. |
| 333 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 334 |
// |
| 335 |
// Service to support Accounts API. |
| 336 |
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 337 |
clientOpts := defaultGRPCClientOptions() |
| 338 |
if newClientHook != nil { |
| 339 |
hookOpts, err := newClientHook(ctx, clientHookParams{}) |
| 340 |
if err != nil { |
| 341 |
return nil, err |
| 342 |
} |
| 343 |
clientOpts = append(clientOpts, hookOpts...) |
| 344 |
} |
| 345 |
|
| 346 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 347 |
if err != nil { |
| 348 |
return nil, err |
| 349 |
} |
| 350 |
client := Client{CallOptions: defaultCallOptions()} |
| 351 |
|
| 352 |
c := &gRPCClient{ |
| 353 |
connPool: connPool, |
| 354 |
client: accountspb.NewAccountsServiceClient(connPool), |
| 355 |
CallOptions: &client.CallOptions, |
| 356 |
logger: internaloption.GetLogger(opts), |
| 357 |
} |
| 358 |
c.setGoogleClientInfo() |
| 359 |
|
| 360 |
client.internalClient = c |
| 361 |
|
| 362 |
return &client, nil |
| 363 |
} |
| 364 |
|
| 365 |
// Connection returns a connection to the API service. |
| 366 |
// |
| 367 |
// Deprecated: Connections are now pooled so this method does not always |
| 368 |
// return the same resource. |
| 369 |
func (c *gRPCClient) Connection() *grpc.ClientConn { |
| 370 |
return c.connPool.Conn() |
| 371 |
} |
| 372 |
|
| 373 |
// setGoogleClientInfo sets the name and version of the application in |
| 374 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 375 |
// use by Google-written clients. |
| 376 |
func (c *gRPCClient) setGoogleClientInfo(keyval ...string) { |
| 377 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 378 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 379 |
c.xGoogHeaders = []string{ |
| 380 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
// Close closes the connection to the API service. The user should invoke this when |
| 385 |
// the client is no longer required. |
| 386 |
func (c *gRPCClient) Close() error { |
| 387 |
return c.connPool.Close() |
| 388 |
} |
| 389 |
|
| 390 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 391 |
type restClient struct { |
| 392 |
// The http endpoint to connect to. |
| 393 |
endpoint string |
| 394 |
|
| 395 |
// The http client. |
| 396 |
httpClient *http.Client |
| 397 |
|
| 398 |
// The x-goog-* headers to be sent with each request. |
| 399 |
xGoogHeaders []string |
| 400 |
|
| 401 |
// Points back to the CallOptions field of the containing Client |
| 402 |
CallOptions **CallOptions |
| 403 |
|
| 404 |
logger *slog.Logger |
| 405 |
} |
| 406 |
|
| 407 |
// NewRESTClient creates a new accounts service rest client. |
| 408 |
// |
| 409 |
// Service to support Accounts API. |
| 410 |
func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { |
| 411 |
clientOpts := append(defaultRESTClientOptions(), opts...) |
| 412 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 413 |
if err != nil { |
| 414 |
return nil, err |
| 415 |
} |
| 416 |
|
| 417 |
callOpts := defaultRESTCallOptions() |
| 418 |
c := &restClient{ |
| 419 |
endpoint: endpoint, |
| 420 |
httpClient: httpClient, |
| 421 |
CallOptions: &callOpts, |
| 422 |
logger: internaloption.GetLogger(opts), |
| 423 |
} |
| 424 |
c.setGoogleClientInfo() |
| 425 |
|
| 426 |
return &Client{internalClient: c, CallOptions: callOpts}, nil |
| 427 |
} |
| 428 |
|
| 429 |
func defaultRESTClientOptions() []option.ClientOption { |
| 430 |
return []option.ClientOption{ |
| 431 |
internaloption.WithDefaultEndpoint("https://merchantapi.googleapis.com"), |
| 432 |
internaloption.WithDefaultEndpointTemplate("https://merchantapi.UNIVERSE_DOMAIN"), |
| 433 |
internaloption.WithDefaultMTLSEndpoint("https://merchantapi.mtls.googleapis.com"), |
| 434 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 435 |
internaloption.WithDefaultAudience("https://merchantapi.googleapis.com/"), |
| 436 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 437 |
internaloption.EnableNewAuthLibrary(), |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
// setGoogleClientInfo sets the name and version of the application in |
| 442 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 443 |
// use by Google-written clients. |
| 444 |
func (c *restClient) setGoogleClientInfo(keyval ...string) { |
| 445 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 446 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 447 |
c.xGoogHeaders = []string{ |
| 448 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
// Close closes the connection to the API service. The user should invoke this when |
| 453 |
// the client is no longer required. |
| 454 |
func (c *restClient) Close() error { |
| 455 |
// Replace httpClient with nil to force cleanup. |
| 456 |
c.httpClient = nil |
| 457 |
return nil |
| 458 |
} |
| 459 |
|
| 460 |
// Connection returns a connection to the API service. |
| 461 |
// |
| 462 |
// Deprecated: This method always returns nil. |
| 463 |
func (c *restClient) Connection() *grpc.ClientConn { |
| 464 |
return nil |
| 465 |
} |
| 466 |
func (c *gRPCClient) GetAccount(ctx context.Context, req *accountspb.GetAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 467 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 468 |
|
| 469 |
hds = append(c.xGoogHeaders, hds...) |
| 470 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 471 |
opts = append((*c.CallOptions).GetAccount[0:len((*c.CallOptions).GetAccount):len((*c.CallOptions).GetAccount)], opts...) |
| 472 |
var resp *accountspb.Account |
| 473 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 474 |
var err error |
| 475 |
resp, err = executeRPC(ctx, c.client.GetAccount, req, settings.GRPC, c.logger, "GetAccount") |
| 476 |
return err |
| 477 |
}, opts...) |
| 478 |
if err != nil { |
| 479 |
return nil, err |
| 480 |
} |
| 481 |
return resp, nil |
| 482 |
} |
| 483 |
|
| 484 |
func (c *gRPCClient) CreateAndConfigureAccount(ctx context.Context, req *accountspb.CreateAndConfigureAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 485 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 486 |
opts = append((*c.CallOptions).CreateAndConfigureAccount[0:len((*c.CallOptions).CreateAndConfigureAccount):len((*c.CallOptions).CreateAndConfigureAccount)], opts...) |
| 487 |
var resp *accountspb.Account |
| 488 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 489 |
var err error |
| 490 |
resp, err = executeRPC(ctx, c.client.CreateAndConfigureAccount, req, settings.GRPC, c.logger, "CreateAndConfigureAccount") |
| 491 |
return err |
| 492 |
}, opts...) |
| 493 |
if err != nil { |
| 494 |
return nil, err |
| 495 |
} |
| 496 |
return resp, nil |
| 497 |
} |
| 498 |
|
| 499 |
func (c *gRPCClient) DeleteAccount(ctx context.Context, req *accountspb.DeleteAccountRequest, opts ...gax.CallOption) error { |
| 500 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 501 |
|
| 502 |
hds = append(c.xGoogHeaders, hds...) |
| 503 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 504 |
opts = append((*c.CallOptions).DeleteAccount[0:len((*c.CallOptions).DeleteAccount):len((*c.CallOptions).DeleteAccount)], opts...) |
| 505 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 506 |
var err error |
| 507 |
_, err = executeRPC(ctx, c.client.DeleteAccount, req, settings.GRPC, c.logger, "DeleteAccount") |
| 508 |
return err |
| 509 |
}, opts...) |
| 510 |
return err |
| 511 |
} |
| 512 |
|
| 513 |
func (c *gRPCClient) UpdateAccount(ctx context.Context, req *accountspb.UpdateAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 514 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account.name", url.QueryEscape(req.GetAccount().GetName()))} |
| 515 |
|
| 516 |
hds = append(c.xGoogHeaders, hds...) |
| 517 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 518 |
opts = append((*c.CallOptions).UpdateAccount[0:len((*c.CallOptions).UpdateAccount):len((*c.CallOptions).UpdateAccount)], opts...) |
| 519 |
var resp *accountspb.Account |
| 520 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 521 |
var err error |
| 522 |
resp, err = executeRPC(ctx, c.client.UpdateAccount, req, settings.GRPC, c.logger, "UpdateAccount") |
| 523 |
return err |
| 524 |
}, opts...) |
| 525 |
if err != nil { |
| 526 |
return nil, err |
| 527 |
} |
| 528 |
return resp, nil |
| 529 |
} |
| 530 |
|
| 531 |
func (c *gRPCClient) ListAccounts(ctx context.Context, req *accountspb.ListAccountsRequest, opts ...gax.CallOption) *AccountIterator { |
| 532 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...) |
| 533 |
opts = append((*c.CallOptions).ListAccounts[0:len((*c.CallOptions).ListAccounts):len((*c.CallOptions).ListAccounts)], opts...) |
| 534 |
it := &AccountIterator{} |
| 535 |
req = proto.Clone(req).(*accountspb.ListAccountsRequest) |
| 536 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) { |
| 537 |
resp := &accountspb.ListAccountsResponse{} |
| 538 |
if pageToken != "" { |
| 539 |
req.PageToken = pageToken |
| 540 |
} |
| 541 |
if pageSize > math.MaxInt32 { |
| 542 |
req.PageSize = math.MaxInt32 |
| 543 |
} else if pageSize != 0 { |
| 544 |
req.PageSize = int32(pageSize) |
| 545 |
} |
| 546 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 547 |
var err error |
| 548 |
resp, err = executeRPC(ctx, c.client.ListAccounts, req, settings.GRPC, c.logger, "ListAccounts") |
| 549 |
return err |
| 550 |
}, opts...) |
| 551 |
if err != nil { |
| 552 |
return nil, "", err |
| 553 |
} |
| 554 |
|
| 555 |
it.Response = resp |
| 556 |
return resp.GetAccounts(), resp.GetNextPageToken(), nil |
| 557 |
} |
| 558 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 559 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 560 |
if err != nil { |
| 561 |
return "", err |
| 562 |
} |
| 563 |
it.items = append(it.items, items...) |
| 564 |
return nextPageToken, nil |
| 565 |
} |
| 566 |
|
| 567 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 568 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 569 |
it.pageInfo.Token = req.GetPageToken() |
| 570 |
|
| 571 |
return it |
| 572 |
} |
| 573 |
|
| 574 |
func (c *gRPCClient) ListSubAccounts(ctx context.Context, req *accountspb.ListSubAccountsRequest, opts ...gax.CallOption) *AccountIterator { |
| 575 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "provider", url.QueryEscape(req.GetProvider()))} |
| 576 |
|
| 577 |
hds = append(c.xGoogHeaders, hds...) |
| 578 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 579 |
opts = append((*c.CallOptions).ListSubAccounts[0:len((*c.CallOptions).ListSubAccounts):len((*c.CallOptions).ListSubAccounts)], opts...) |
| 580 |
it := &AccountIterator{} |
| 581 |
req = proto.Clone(req).(*accountspb.ListSubAccountsRequest) |
| 582 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) { |
| 583 |
resp := &accountspb.ListSubAccountsResponse{} |
| 584 |
if pageToken != "" { |
| 585 |
req.PageToken = pageToken |
| 586 |
} |
| 587 |
if pageSize > math.MaxInt32 { |
| 588 |
req.PageSize = math.MaxInt32 |
| 589 |
} else if pageSize != 0 { |
| 590 |
req.PageSize = int32(pageSize) |
| 591 |
} |
| 592 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 593 |
var err error |
| 594 |
resp, err = executeRPC(ctx, c.client.ListSubAccounts, req, settings.GRPC, c.logger, "ListSubAccounts") |
| 595 |
return err |
| 596 |
}, opts...) |
| 597 |
if err != nil { |
| 598 |
return nil, "", err |
| 599 |
} |
| 600 |
|
| 601 |
it.Response = resp |
| 602 |
return resp.GetAccounts(), resp.GetNextPageToken(), nil |
| 603 |
} |
| 604 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 605 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 606 |
if err != nil { |
| 607 |
return "", err |
| 608 |
} |
| 609 |
it.items = append(it.items, items...) |
| 610 |
return nextPageToken, nil |
| 611 |
} |
| 612 |
|
| 613 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 614 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 615 |
it.pageInfo.Token = req.GetPageToken() |
| 616 |
|
| 617 |
return it |
| 618 |
} |
| 619 |
|
| 620 |
// GetAccount retrieves an account from your Merchant Center account. |
| 621 |
// After inserting, updating, or deleting an account, it may take several |
| 622 |
// minutes before changes take effect. |
| 623 |
func (c *restClient) GetAccount(ctx context.Context, req *accountspb.GetAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 624 |
baseUrl, err := url.Parse(c.endpoint) |
| 625 |
if err != nil { |
| 626 |
return nil, err |
| 627 |
} |
| 628 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName()) |
| 629 |
|
| 630 |
params := url.Values{} |
| 631 |
params.Add("$alt", "json;enum-encoding=int") |
| 632 |
|
| 633 |
baseUrl.RawQuery = params.Encode() |
| 634 |
|
| 635 |
// Build HTTP headers from client and context metadata. |
| 636 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 637 |
|
| 638 |
hds = append(c.xGoogHeaders, hds...) |
| 639 |
hds = append(hds, "Content-Type", "application/json") |
| 640 |
headers := gax.BuildHeaders(ctx, hds...) |
| 641 |
opts = append((*c.CallOptions).GetAccount[0:len((*c.CallOptions).GetAccount):len((*c.CallOptions).GetAccount)], opts...) |
| 642 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 643 |
resp := &accountspb.Account{} |
| 644 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 645 |
if settings.Path != "" { |
| 646 |
baseUrl.Path = settings.Path |
| 647 |
} |
| 648 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 649 |
if err != nil { |
| 650 |
return err |
| 651 |
} |
| 652 |
httpReq = httpReq.WithContext(ctx) |
| 653 |
httpReq.Header = headers |
| 654 |
|
| 655 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAccount") |
| 656 |
if err != nil { |
| 657 |
return err |
| 658 |
} |
| 659 |
|
| 660 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 661 |
return err |
| 662 |
} |
| 663 |
|
| 664 |
return nil |
| 665 |
}, opts...) |
| 666 |
if e != nil { |
| 667 |
return nil, e |
| 668 |
} |
| 669 |
return resp, nil |
| 670 |
} |
| 671 |
|
| 672 |
// CreateAndConfigureAccount creates a standalone Merchant Center account with additional configuration. |
| 673 |
// Adds the user that makes the request as an admin for the new account. |
| 674 |
func (c *restClient) CreateAndConfigureAccount(ctx context.Context, req *accountspb.CreateAndConfigureAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 675 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 676 |
jsonReq, err := m.Marshal(req) |
| 677 |
if err != nil { |
| 678 |
return nil, err |
| 679 |
} |
| 680 |
|
| 681 |
baseUrl, err := url.Parse(c.endpoint) |
| 682 |
if err != nil { |
| 683 |
return nil, err |
| 684 |
} |
| 685 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/accounts:createAndConfigure") |
| 686 |
|
| 687 |
params := url.Values{} |
| 688 |
params.Add("$alt", "json;enum-encoding=int") |
| 689 |
|
| 690 |
baseUrl.RawQuery = params.Encode() |
| 691 |
|
| 692 |
// Build HTTP headers from client and context metadata. |
| 693 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 694 |
headers := gax.BuildHeaders(ctx, hds...) |
| 695 |
opts = append((*c.CallOptions).CreateAndConfigureAccount[0:len((*c.CallOptions).CreateAndConfigureAccount):len((*c.CallOptions).CreateAndConfigureAccount)], opts...) |
| 696 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 697 |
resp := &accountspb.Account{} |
| 698 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 699 |
if settings.Path != "" { |
| 700 |
baseUrl.Path = settings.Path |
| 701 |
} |
| 702 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 703 |
if err != nil { |
| 704 |
return err |
| 705 |
} |
| 706 |
httpReq = httpReq.WithContext(ctx) |
| 707 |
httpReq.Header = headers |
| 708 |
|
| 709 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAndConfigureAccount") |
| 710 |
if err != nil { |
| 711 |
return err |
| 712 |
} |
| 713 |
|
| 714 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 715 |
return err |
| 716 |
} |
| 717 |
|
| 718 |
return nil |
| 719 |
}, opts...) |
| 720 |
if e != nil { |
| 721 |
return nil, e |
| 722 |
} |
| 723 |
return resp, nil |
| 724 |
} |
| 725 |
|
| 726 |
// DeleteAccount deletes the specified account regardless of its type: standalone, MCA or |
| 727 |
// sub-account. Deleting an MCA leads to the deletion of all of its |
| 728 |
// sub-accounts. Executing this method requires admin access. |
| 729 |
// The deletion succeeds only if the account does not provide services |
| 730 |
// to any other account and has no processed offers. You can use the force |
| 731 |
// parameter to override this. |
| 732 |
func (c *restClient) DeleteAccount(ctx context.Context, req *accountspb.DeleteAccountRequest, opts ...gax.CallOption) error { |
| 733 |
baseUrl, err := url.Parse(c.endpoint) |
| 734 |
if err != nil { |
| 735 |
return err |
| 736 |
} |
| 737 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetName()) |
| 738 |
|
| 739 |
params := url.Values{} |
| 740 |
params.Add("$alt", "json;enum-encoding=int") |
| 741 |
if req.GetForce() { |
| 742 |
params.Add("force", fmt.Sprintf("%v", req.GetForce())) |
| 743 |
} |
| 744 |
|
| 745 |
baseUrl.RawQuery = params.Encode() |
| 746 |
|
| 747 |
// Build HTTP headers from client and context metadata. |
| 748 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 749 |
|
| 750 |
hds = append(c.xGoogHeaders, hds...) |
| 751 |
hds = append(hds, "Content-Type", "application/json") |
| 752 |
headers := gax.BuildHeaders(ctx, hds...) |
| 753 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 754 |
if settings.Path != "" { |
| 755 |
baseUrl.Path = settings.Path |
| 756 |
} |
| 757 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 758 |
if err != nil { |
| 759 |
return err |
| 760 |
} |
| 761 |
httpReq = httpReq.WithContext(ctx) |
| 762 |
httpReq.Header = headers |
| 763 |
|
| 764 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAccount") |
| 765 |
return err |
| 766 |
}, opts...) |
| 767 |
} |
| 768 |
|
| 769 |
// UpdateAccount updates an account regardless of its type: standalone, MCA or sub-account. |
| 770 |
// Executing this method requires admin access. |
| 771 |
func (c *restClient) UpdateAccount(ctx context.Context, req *accountspb.UpdateAccountRequest, opts ...gax.CallOption) (*accountspb.Account, error) { |
| 772 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 773 |
body := req.GetAccount() |
| 774 |
jsonReq, err := m.Marshal(body) |
| 775 |
if err != nil { |
| 776 |
return nil, err |
| 777 |
} |
| 778 |
|
| 779 |
baseUrl, err := url.Parse(c.endpoint) |
| 780 |
if err != nil { |
| 781 |
return nil, err |
| 782 |
} |
| 783 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v", req.GetAccount().GetName()) |
| 784 |
|
| 785 |
params := url.Values{} |
| 786 |
params.Add("$alt", "json;enum-encoding=int") |
| 787 |
if req.GetUpdateMask() != nil { |
| 788 |
field, err := protojson.Marshal(req.GetUpdateMask()) |
| 789 |
if err != nil { |
| 790 |
return nil, err |
| 791 |
} |
| 792 |
params.Add("updateMask", string(field[1:len(field)-1])) |
| 793 |
} |
| 794 |
|
| 795 |
baseUrl.RawQuery = params.Encode() |
| 796 |
|
| 797 |
// Build HTTP headers from client and context metadata. |
| 798 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account.name", url.QueryEscape(req.GetAccount().GetName()))} |
| 799 |
|
| 800 |
hds = append(c.xGoogHeaders, hds...) |
| 801 |
hds = append(hds, "Content-Type", "application/json") |
| 802 |
headers := gax.BuildHeaders(ctx, hds...) |
| 803 |
opts = append((*c.CallOptions).UpdateAccount[0:len((*c.CallOptions).UpdateAccount):len((*c.CallOptions).UpdateAccount)], opts...) |
| 804 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 805 |
resp := &accountspb.Account{} |
| 806 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 807 |
if settings.Path != "" { |
| 808 |
baseUrl.Path = settings.Path |
| 809 |
} |
| 810 |
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 811 |
if err != nil { |
| 812 |
return err |
| 813 |
} |
| 814 |
httpReq = httpReq.WithContext(ctx) |
| 815 |
httpReq.Header = headers |
| 816 |
|
| 817 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAccount") |
| 818 |
if err != nil { |
| 819 |
return err |
| 820 |
} |
| 821 |
|
| 822 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 823 |
return err |
| 824 |
} |
| 825 |
|
| 826 |
return nil |
| 827 |
}, opts...) |
| 828 |
if e != nil { |
| 829 |
return nil, e |
| 830 |
} |
| 831 |
return resp, nil |
| 832 |
} |
| 833 |
|
| 834 |
// ListAccounts lists accounts accessible to the calling user and matching the |
| 835 |
// constraints of the request such as page size or filters. |
| 836 |
// This is not just listing the sub-accounts of an MCA, but all accounts the |
| 837 |
// calling user has access to including other MCAs, linked accounts, |
| 838 |
// standalone accounts and so on. If no filter is provided, then it returns |
| 839 |
// accounts the user is directly added to. |
| 840 |
func (c *restClient) ListAccounts(ctx context.Context, req *accountspb.ListAccountsRequest, opts ...gax.CallOption) *AccountIterator { |
| 841 |
it := &AccountIterator{} |
| 842 |
req = proto.Clone(req).(*accountspb.ListAccountsRequest) |
| 843 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 844 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) { |
| 845 |
resp := &accountspb.ListAccountsResponse{} |
| 846 |
if pageToken != "" { |
| 847 |
req.PageToken = pageToken |
| 848 |
} |
| 849 |
if pageSize > math.MaxInt32 { |
| 850 |
req.PageSize = math.MaxInt32 |
| 851 |
} else if pageSize != 0 { |
| 852 |
req.PageSize = int32(pageSize) |
| 853 |
} |
| 854 |
baseUrl, err := url.Parse(c.endpoint) |
| 855 |
if err != nil { |
| 856 |
return nil, "", err |
| 857 |
} |
| 858 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/accounts") |
| 859 |
|
| 860 |
params := url.Values{} |
| 861 |
params.Add("$alt", "json;enum-encoding=int") |
| 862 |
if req.GetFilter() != "" { |
| 863 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 864 |
} |
| 865 |
if req.GetPageSize() != 0 { |
| 866 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 867 |
} |
| 868 |
if req.GetPageToken() != "" { |
| 869 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 870 |
} |
| 871 |
|
| 872 |
baseUrl.RawQuery = params.Encode() |
| 873 |
|
| 874 |
// Build HTTP headers from client and context metadata. |
| 875 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 876 |
headers := gax.BuildHeaders(ctx, hds...) |
| 877 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 878 |
if settings.Path != "" { |
| 879 |
baseUrl.Path = settings.Path |
| 880 |
} |
| 881 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 882 |
if err != nil { |
| 883 |
return err |
| 884 |
} |
| 885 |
httpReq.Header = headers |
| 886 |
|
| 887 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccounts") |
| 888 |
if err != nil { |
| 889 |
return err |
| 890 |
} |
| 891 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 892 |
return err |
| 893 |
} |
| 894 |
|
| 895 |
return nil |
| 896 |
}, opts...) |
| 897 |
if e != nil { |
| 898 |
return nil, "", e |
| 899 |
} |
| 900 |
it.Response = resp |
| 901 |
return resp.GetAccounts(), resp.GetNextPageToken(), nil |
| 902 |
} |
| 903 |
|
| 904 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 905 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 906 |
if err != nil { |
| 907 |
return "", err |
| 908 |
} |
| 909 |
it.items = append(it.items, items...) |
| 910 |
return nextPageToken, nil |
| 911 |
} |
| 912 |
|
| 913 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 914 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 915 |
it.pageInfo.Token = req.GetPageToken() |
| 916 |
|
| 917 |
return it |
| 918 |
} |
| 919 |
|
| 920 |
// ListSubAccounts list all sub-accounts for a given multi client account. This is a |
| 921 |
// convenience wrapper for the more powerful ListAccounts method. This |
| 922 |
// method will produce the same results as calling ListsAccounts with the |
| 923 |
// following filter: |
| 924 |
// relationship(providerId={parent} AND service(type="ACCOUNT_AGGREGATION")) |
| 925 |
func (c *restClient) ListSubAccounts(ctx context.Context, req *accountspb.ListSubAccountsRequest, opts ...gax.CallOption) *AccountIterator { |
| 926 |
it := &AccountIterator{} |
| 927 |
req = proto.Clone(req).(*accountspb.ListSubAccountsRequest) |
| 928 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 929 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*accountspb.Account, string, error) { |
| 930 |
resp := &accountspb.ListSubAccountsResponse{} |
| 931 |
if pageToken != "" { |
| 932 |
req.PageToken = pageToken |
| 933 |
} |
| 934 |
if pageSize > math.MaxInt32 { |
| 935 |
req.PageSize = math.MaxInt32 |
| 936 |
} else if pageSize != 0 { |
| 937 |
req.PageSize = int32(pageSize) |
| 938 |
} |
| 939 |
baseUrl, err := url.Parse(c.endpoint) |
| 940 |
if err != nil { |
| 941 |
return nil, "", err |
| 942 |
} |
| 943 |
baseUrl.Path += fmt.Sprintf("/accounts/v1beta/%v:listSubaccounts", req.GetProvider()) |
| 944 |
|
| 945 |
params := url.Values{} |
| 946 |
params.Add("$alt", "json;enum-encoding=int") |
| 947 |
if req.GetPageSize() != 0 { |
| 948 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 949 |
} |
| 950 |
if req.GetPageToken() != "" { |
| 951 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 952 |
} |
| 953 |
|
| 954 |
baseUrl.RawQuery = params.Encode() |
| 955 |
|
| 956 |
// Build HTTP headers from client and context metadata. |
| 957 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 958 |
headers := gax.BuildHeaders(ctx, hds...) |
| 959 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 960 |
if settings.Path != "" { |
| 961 |
baseUrl.Path = settings.Path |
| 962 |
} |
| 963 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 964 |
if err != nil { |
| 965 |
return err |
| 966 |
} |
| 967 |
httpReq.Header = headers |
| 968 |
|
| 969 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListSubAccounts") |
| 970 |
if err != nil { |
| 971 |
return err |
| 972 |
} |
| 973 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 974 |
return err |
| 975 |
} |
| 976 |
|
| 977 |
return nil |
| 978 |
}, opts...) |
| 979 |
if e != nil { |
| 980 |
return nil, "", e |
| 981 |
} |
| 982 |
it.Response = resp |
| 983 |
return resp.GetAccounts(), resp.GetNextPageToken(), nil |
| 984 |
} |
| 985 |
|
| 986 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 987 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 988 |
if err != nil { |
| 989 |
return "", err |
| 990 |
} |
| 991 |
it.items = append(it.items, items...) |
| 992 |
return nextPageToken, nil |
| 993 |
} |
| 994 |
|
| 995 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 996 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 997 |
it.pageInfo.Token = req.GetPageToken() |
| 998 |
|
| 999 |
return it |
| 1000 |
} |