Debian Codegraph @

bigquery/datapolicies/apiv2/data_policy_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package datapolicies
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 datapoliciespb "cloud.google.com/go/bigquery/datapolicies/apiv2/datapoliciespb"
30 iampb "cloud.google.com/go/iam/apiv1/iampb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newDataPolicyClientHook clientHook
44
45 // DataPolicyCallOptions contains the retry settings for each method of DataPolicyClient.
46 type DataPolicyCallOptions struct {
47 CreateDataPolicy []gax.CallOption
48 AddGrantees []gax.CallOption
49 RemoveGrantees []gax.CallOption
50 UpdateDataPolicy []gax.CallOption
51 DeleteDataPolicy []gax.CallOption
52 GetDataPolicy []gax.CallOption
53 ListDataPolicies []gax.CallOption
54 GetIamPolicy []gax.CallOption
55 SetIamPolicy []gax.CallOption
56 TestIamPermissions []gax.CallOption
57 }
58
59 func defaultDataPolicyGRPCClientOptions() []option.ClientOption {
60 return []option.ClientOption{
61 internaloption.WithDefaultEndpoint("bigquerydatapolicy.googleapis.com:443"),
62 internaloption.WithDefaultEndpointTemplate("bigquerydatapolicy.UNIVERSE_DOMAIN:443"),
63 internaloption.WithDefaultMTLSEndpoint("bigquerydatapolicy.mtls.googleapis.com:443"),
64 internaloption.WithDefaultUniverseDomain("googleapis.com"),
65 internaloption.WithDefaultAudience("https://bigquerydatapolicy.googleapis.com/"),
66 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
67 internaloption.EnableJwtWithScope(),
68 internaloption.EnableNewAuthLibrary(),
69 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
70 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
71 }
72 }
73
74 func defaultDataPolicyCallOptions() *DataPolicyCallOptions {
75 return &DataPolicyCallOptions{
76 CreateDataPolicy: []gax.CallOption{
77 gax.WithTimeout(64000 * time.Millisecond),
78 gax.WithRetry(func() gax.Retryer {
79 return gax.OnCodes([]codes.Code{
80 codes.DeadlineExceeded,
81 codes.Unavailable,
82 codes.ResourceExhausted,
83 }, gax.Backoff{
84 Initial: 1000 * time.Millisecond,
85 Max: 60000 * time.Millisecond,
86 Multiplier: 1.30,
87 })
88 }),
89 },
90 AddGrantees: []gax.CallOption{
91 gax.WithTimeout(64000 * time.Millisecond),
92 gax.WithRetry(func() gax.Retryer {
93 return gax.OnCodes([]codes.Code{
94 codes.DeadlineExceeded,
95 codes.Unavailable,
96 codes.ResourceExhausted,
97 }, gax.Backoff{
98 Initial: 1000 * time.Millisecond,
99 Max: 60000 * time.Millisecond,
100 Multiplier: 1.30,
101 })
102 }),
103 },
104 RemoveGrantees: []gax.CallOption{
105 gax.WithTimeout(64000 * time.Millisecond),
106 gax.WithRetry(func() gax.Retryer {
107 return gax.OnCodes([]codes.Code{
108 codes.DeadlineExceeded,
109 codes.Unavailable,
110 codes.ResourceExhausted,
111 }, gax.Backoff{
112 Initial: 1000 * time.Millisecond,
113 Max: 60000 * time.Millisecond,
114 Multiplier: 1.30,
115 })
116 }),
117 },
118 UpdateDataPolicy: []gax.CallOption{
119 gax.WithTimeout(64000 * time.Millisecond),
120 gax.WithRetry(func() gax.Retryer {
121 return gax.OnCodes([]codes.Code{
122 codes.DeadlineExceeded,
123 codes.Unavailable,
124 codes.ResourceExhausted,
125 }, gax.Backoff{
126 Initial: 1000 * time.Millisecond,
127 Max: 60000 * time.Millisecond,
128 Multiplier: 1.30,
129 })
130 }),
131 },
132 DeleteDataPolicy: []gax.CallOption{
133 gax.WithTimeout(64000 * time.Millisecond),
134 gax.WithRetry(func() gax.Retryer {
135 return gax.OnCodes([]codes.Code{
136 codes.DeadlineExceeded,
137 codes.Unavailable,
138 codes.ResourceExhausted,
139 }, gax.Backoff{
140 Initial: 1000 * time.Millisecond,
141 Max: 60000 * time.Millisecond,
142 Multiplier: 1.30,
143 })
144 }),
145 },
146 GetDataPolicy: []gax.CallOption{
147 gax.WithTimeout(64000 * time.Millisecond),
148 gax.WithRetry(func() gax.Retryer {
149 return gax.OnCodes([]codes.Code{
150 codes.DeadlineExceeded,
151 codes.Unavailable,
152 codes.ResourceExhausted,
153 }, gax.Backoff{
154 Initial: 1000 * time.Millisecond,
155 Max: 60000 * time.Millisecond,
156 Multiplier: 1.30,
157 })
158 }),
159 },
160 ListDataPolicies: []gax.CallOption{
161 gax.WithTimeout(64000 * time.Millisecond),
162 gax.WithRetry(func() gax.Retryer {
163 return gax.OnCodes([]codes.Code{
164 codes.DeadlineExceeded,
165 codes.Unavailable,
166 codes.ResourceExhausted,
167 }, gax.Backoff{
168 Initial: 1000 * time.Millisecond,
169 Max: 60000 * time.Millisecond,
170 Multiplier: 1.30,
171 })
172 }),
173 },
174 GetIamPolicy: []gax.CallOption{
175 gax.WithTimeout(64000 * time.Millisecond),
176 gax.WithRetry(func() gax.Retryer {
177 return gax.OnCodes([]codes.Code{
178 codes.DeadlineExceeded,
179 codes.Unavailable,
180 codes.ResourceExhausted,
181 }, gax.Backoff{
182 Initial: 1000 * time.Millisecond,
183 Max: 60000 * time.Millisecond,
184 Multiplier: 1.30,
185 })
186 }),
187 },
188 SetIamPolicy: []gax.CallOption{
189 gax.WithTimeout(64000 * time.Millisecond),
190 gax.WithRetry(func() gax.Retryer {
191 return gax.OnCodes([]codes.Code{
192 codes.DeadlineExceeded,
193 codes.Unavailable,
194 codes.ResourceExhausted,
195 }, gax.Backoff{
196 Initial: 1000 * time.Millisecond,
197 Max: 60000 * time.Millisecond,
198 Multiplier: 1.30,
199 })
200 }),
201 },
202 TestIamPermissions: []gax.CallOption{
203 gax.WithTimeout(64000 * time.Millisecond),
204 gax.WithRetry(func() gax.Retryer {
205 return gax.OnCodes([]codes.Code{
206 codes.DeadlineExceeded,
207 codes.Unavailable,
208 codes.ResourceExhausted,
209 }, gax.Backoff{
210 Initial: 1000 * time.Millisecond,
211 Max: 60000 * time.Millisecond,
212 Multiplier: 1.30,
213 })
214 }),
215 },
216 }
217 }
218
219 func defaultDataPolicyRESTCallOptions() *DataPolicyCallOptions {
220 return &DataPolicyCallOptions{
221 CreateDataPolicy: []gax.CallOption{
222 gax.WithTimeout(64000 * time.Millisecond),
223 gax.WithRetry(func() gax.Retryer {
224 return gax.OnHTTPCodes(gax.Backoff{
225 Initial: 1000 * time.Millisecond,
226 Max: 60000 * time.Millisecond,
227 Multiplier: 1.30,
228 },
229 http.StatusGatewayTimeout,
230 http.StatusServiceUnavailable,
231 http.StatusTooManyRequests)
232 }),
233 },
234 AddGrantees: []gax.CallOption{
235 gax.WithTimeout(64000 * time.Millisecond),
236 gax.WithRetry(func() gax.Retryer {
237 return gax.OnHTTPCodes(gax.Backoff{
238 Initial: 1000 * time.Millisecond,
239 Max: 60000 * time.Millisecond,
240 Multiplier: 1.30,
241 },
242 http.StatusGatewayTimeout,
243 http.StatusServiceUnavailable,
244 http.StatusTooManyRequests)
245 }),
246 },
247 RemoveGrantees: []gax.CallOption{
248 gax.WithTimeout(64000 * time.Millisecond),
249 gax.WithRetry(func() gax.Retryer {
250 return gax.OnHTTPCodes(gax.Backoff{
251 Initial: 1000 * time.Millisecond,
252 Max: 60000 * time.Millisecond,
253 Multiplier: 1.30,
254 },
255 http.StatusGatewayTimeout,
256 http.StatusServiceUnavailable,
257 http.StatusTooManyRequests)
258 }),
259 },
260 UpdateDataPolicy: []gax.CallOption{
261 gax.WithTimeout(64000 * time.Millisecond),
262 gax.WithRetry(func() gax.Retryer {
263 return gax.OnHTTPCodes(gax.Backoff{
264 Initial: 1000 * time.Millisecond,
265 Max: 60000 * time.Millisecond,
266 Multiplier: 1.30,
267 },
268 http.StatusGatewayTimeout,
269 http.StatusServiceUnavailable,
270 http.StatusTooManyRequests)
271 }),
272 },
273 DeleteDataPolicy: []gax.CallOption{
274 gax.WithTimeout(64000 * time.Millisecond),
275 gax.WithRetry(func() gax.Retryer {
276 return gax.OnHTTPCodes(gax.Backoff{
277 Initial: 1000 * time.Millisecond,
278 Max: 60000 * time.Millisecond,
279 Multiplier: 1.30,
280 },
281 http.StatusGatewayTimeout,
282 http.StatusServiceUnavailable,
283 http.StatusTooManyRequests)
284 }),
285 },
286 GetDataPolicy: []gax.CallOption{
287 gax.WithTimeout(64000 * time.Millisecond),
288 gax.WithRetry(func() gax.Retryer {
289 return gax.OnHTTPCodes(gax.Backoff{
290 Initial: 1000 * time.Millisecond,
291 Max: 60000 * time.Millisecond,
292 Multiplier: 1.30,
293 },
294 http.StatusGatewayTimeout,
295 http.StatusServiceUnavailable,
296 http.StatusTooManyRequests)
297 }),
298 },
299 ListDataPolicies: []gax.CallOption{
300 gax.WithTimeout(64000 * time.Millisecond),
301 gax.WithRetry(func() gax.Retryer {
302 return gax.OnHTTPCodes(gax.Backoff{
303 Initial: 1000 * time.Millisecond,
304 Max: 60000 * time.Millisecond,
305 Multiplier: 1.30,
306 },
307 http.StatusGatewayTimeout,
308 http.StatusServiceUnavailable,
309 http.StatusTooManyRequests)
310 }),
311 },
312 GetIamPolicy: []gax.CallOption{
313 gax.WithTimeout(64000 * time.Millisecond),
314 gax.WithRetry(func() gax.Retryer {
315 return gax.OnHTTPCodes(gax.Backoff{
316 Initial: 1000 * time.Millisecond,
317 Max: 60000 * time.Millisecond,
318 Multiplier: 1.30,
319 },
320 http.StatusGatewayTimeout,
321 http.StatusServiceUnavailable,
322 http.StatusTooManyRequests)
323 }),
324 },
325 SetIamPolicy: []gax.CallOption{
326 gax.WithTimeout(64000 * time.Millisecond),
327 gax.WithRetry(func() gax.Retryer {
328 return gax.OnHTTPCodes(gax.Backoff{
329 Initial: 1000 * time.Millisecond,
330 Max: 60000 * time.Millisecond,
331 Multiplier: 1.30,
332 },
333 http.StatusGatewayTimeout,
334 http.StatusServiceUnavailable,
335 http.StatusTooManyRequests)
336 }),
337 },
338 TestIamPermissions: []gax.CallOption{
339 gax.WithTimeout(64000 * time.Millisecond),
340 gax.WithRetry(func() gax.Retryer {
341 return gax.OnHTTPCodes(gax.Backoff{
342 Initial: 1000 * time.Millisecond,
343 Max: 60000 * time.Millisecond,
344 Multiplier: 1.30,
345 },
346 http.StatusGatewayTimeout,
347 http.StatusServiceUnavailable,
348 http.StatusTooManyRequests)
349 }),
350 },
351 }
352 }
353
354 // internalDataPolicyClient is an interface that defines the methods available from BigQuery Data Policy API.
355 type internalDataPolicyClient interface {
356 Close() error
357 setGoogleClientInfo(...string)
358 Connection() *grpc.ClientConn
359 CreateDataPolicy(context.Context, *datapoliciespb.CreateDataPolicyRequest, ...gax.CallOption) (*datapoliciespb.DataPolicy, error)
360 AddGrantees(context.Context, *datapoliciespb.AddGranteesRequest, ...gax.CallOption) (*datapoliciespb.DataPolicy, error)
361 RemoveGrantees(context.Context, *datapoliciespb.RemoveGranteesRequest, ...gax.CallOption) (*datapoliciespb.DataPolicy, error)
362 UpdateDataPolicy(context.Context, *datapoliciespb.UpdateDataPolicyRequest, ...gax.CallOption) (*datapoliciespb.DataPolicy, error)
363 DeleteDataPolicy(context.Context, *datapoliciespb.DeleteDataPolicyRequest, ...gax.CallOption) error
364 GetDataPolicy(context.Context, *datapoliciespb.GetDataPolicyRequest, ...gax.CallOption) (*datapoliciespb.DataPolicy, error)
365 ListDataPolicies(context.Context, *datapoliciespb.ListDataPoliciesRequest, ...gax.CallOption) *DataPolicyIterator
366 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
367 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
368 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
369 }
370
371 // DataPolicyClient is a client for interacting with BigQuery Data Policy API.
372 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
373 //
374 // Data Policy Service provides APIs for managing the BigQuery Data Policy.
375 type DataPolicyClient struct {
376 // The internal transport-dependent client.
377 internalClient internalDataPolicyClient
378
379 // The call options for this service.
380 CallOptions *DataPolicyCallOptions
381 }
382
383 // Wrapper methods routed to the internal client.
384
385 // Close closes the connection to the API service. The user should invoke this when
386 // the client is no longer required.
387 func (c *DataPolicyClient) Close() error {
388 return c.internalClient.Close()
389 }
390
391 // setGoogleClientInfo sets the name and version of the application in
392 // the `x-goog-api-client` header passed on each request. Intended for
393 // use by Google-written clients.
394 func (c *DataPolicyClient) setGoogleClientInfo(keyval ...string) {
395 c.internalClient.setGoogleClientInfo(keyval...)
396 }
397
398 // Connection returns a connection to the API service.
399 //
400 // Deprecated: Connections are now pooled so this method does not always
401 // return the same resource.
402 func (c *DataPolicyClient) Connection() *grpc.ClientConn {
403 return c.internalClient.Connection()
404 }
405
406 // CreateDataPolicy creates a new data policy under a project with the given data_policy_id
407 // (used as the display name), and data policy type.
408 func (c *DataPolicyClient) CreateDataPolicy(ctx context.Context, req *datapoliciespb.CreateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
409 return c.internalClient.CreateDataPolicy(ctx, req, opts...)
410 }
411
412 // AddGrantees adds new grantees to a data policy.
413 // The new grantees will be added to the existing grantees.
414 // If the request contains a duplicate grantee, the grantee will be ignored.
415 // If the request contains a grantee that already exists, the grantee will be
416 // ignored.
417 func (c *DataPolicyClient) AddGrantees(ctx context.Context, req *datapoliciespb.AddGranteesRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
418 return c.internalClient.AddGrantees(ctx, req, opts...)
419 }
420
421 // RemoveGrantees removes grantees from a data policy.
422 // The grantees will be removed from the existing grantees.
423 // If the request contains a grantee that does not exist, the grantee will be
424 // ignored.
425 func (c *DataPolicyClient) RemoveGrantees(ctx context.Context, req *datapoliciespb.RemoveGranteesRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
426 return c.internalClient.RemoveGrantees(ctx, req, opts...)
427 }
428
429 // UpdateDataPolicy updates the metadata for an existing data policy. The target data policy
430 // can be specified by the resource name.
431 func (c *DataPolicyClient) UpdateDataPolicy(ctx context.Context, req *datapoliciespb.UpdateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
432 return c.internalClient.UpdateDataPolicy(ctx, req, opts...)
433 }
434
435 // DeleteDataPolicy deletes the data policy specified by its resource name.
436 func (c *DataPolicyClient) DeleteDataPolicy(ctx context.Context, req *datapoliciespb.DeleteDataPolicyRequest, opts ...gax.CallOption) error {
437 return c.internalClient.DeleteDataPolicy(ctx, req, opts...)
438 }
439
440 // GetDataPolicy gets the data policy specified by its resource name.
441 func (c *DataPolicyClient) GetDataPolicy(ctx context.Context, req *datapoliciespb.GetDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
442 return c.internalClient.GetDataPolicy(ctx, req, opts...)
443 }
444
445 // ListDataPolicies list all of the data policies in the specified parent project.
446 func (c *DataPolicyClient) ListDataPolicies(ctx context.Context, req *datapoliciespb.ListDataPoliciesRequest, opts ...gax.CallOption) *DataPolicyIterator {
447 return c.internalClient.ListDataPolicies(ctx, req, opts...)
448 }
449
450 // GetIamPolicy gets the IAM policy for the specified data policy.
451 func (c *DataPolicyClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
452 return c.internalClient.GetIamPolicy(ctx, req, opts...)
453 }
454
455 // SetIamPolicy sets the IAM policy for the specified data policy.
456 func (c *DataPolicyClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
457 return c.internalClient.SetIamPolicy(ctx, req, opts...)
458 }
459
460 // TestIamPermissions returns the caller’s permission on the specified data policy resource.
461 func (c *DataPolicyClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
462 return c.internalClient.TestIamPermissions(ctx, req, opts...)
463 }
464
465 // dataPolicyGRPCClient is a client for interacting with BigQuery Data Policy API over gRPC transport.
466 //
467 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
468 type dataPolicyGRPCClient struct {
469 // Connection pool of gRPC connections to the service.
470 connPool gtransport.ConnPool
471
472 // Points back to the CallOptions field of the containing DataPolicyClient
473 CallOptions **DataPolicyCallOptions
474
475 // The gRPC API client.
476 dataPolicyClient datapoliciespb.DataPolicyServiceClient
477
478 // The x-goog-* metadata to be sent with each request.
479 xGoogHeaders []string
480
481 logger *slog.Logger
482 }
483
484 // NewDataPolicyClient creates a new data policy service client based on gRPC.
485 // The returned client must be Closed when it is done being used to clean up its underlying connections.
486 //
487 // Data Policy Service provides APIs for managing the BigQuery Data Policy.
488 func NewDataPolicyClient(ctx context.Context, opts ...option.ClientOption) (*DataPolicyClient, error) {
489 clientOpts := defaultDataPolicyGRPCClientOptions()
490 if newDataPolicyClientHook != nil {
491 hookOpts, err := newDataPolicyClientHook(ctx, clientHookParams{})
492 if err != nil {
493 return nil, err
494 }
495 clientOpts = append(clientOpts, hookOpts...)
496 }
497
498 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
499 if err != nil {
500 return nil, err
501 }
502 client := DataPolicyClient{CallOptions: defaultDataPolicyCallOptions()}
503
504 c := &dataPolicyGRPCClient{
505 connPool: connPool,
506 dataPolicyClient: datapoliciespb.NewDataPolicyServiceClient(connPool),
507 CallOptions: &client.CallOptions,
508 logger: internaloption.GetLogger(opts),
509 }
510 c.setGoogleClientInfo()
511
512 client.internalClient = c
513
514 return &client, nil
515 }
516
517 // Connection returns a connection to the API service.
518 //
519 // Deprecated: Connections are now pooled so this method does not always
520 // return the same resource.
521 func (c *dataPolicyGRPCClient) Connection() *grpc.ClientConn {
522 return c.connPool.Conn()
523 }
524
525 // setGoogleClientInfo sets the name and version of the application in
526 // the `x-goog-api-client` header passed on each request. Intended for
527 // use by Google-written clients.
528 func (c *dataPolicyGRPCClient) setGoogleClientInfo(keyval ...string) {
529 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
530 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
531 c.xGoogHeaders = []string{
532 "x-goog-api-client", gax.XGoogHeader(kv...),
533 }
534 }
535
536 // Close closes the connection to the API service. The user should invoke this when
537 // the client is no longer required.
538 func (c *dataPolicyGRPCClient) Close() error {
539 return c.connPool.Close()
540 }
541
542 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
543 type dataPolicyRESTClient struct {
544 // The http endpoint to connect to.
545 endpoint string
546
547 // The http client.
548 httpClient *http.Client
549
550 // The x-goog-* headers to be sent with each request.
551 xGoogHeaders []string
552
553 // Points back to the CallOptions field of the containing DataPolicyClient
554 CallOptions **DataPolicyCallOptions
555
556 logger *slog.Logger
557 }
558
559 // NewDataPolicyRESTClient creates a new data policy service rest client.
560 //
561 // Data Policy Service provides APIs for managing the BigQuery Data Policy.
562 func NewDataPolicyRESTClient(ctx context.Context, opts ...option.ClientOption) (*DataPolicyClient, error) {
563 clientOpts := append(defaultDataPolicyRESTClientOptions(), opts...)
564 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
565 if err != nil {
566 return nil, err
567 }
568
569 callOpts := defaultDataPolicyRESTCallOptions()
570 c := &dataPolicyRESTClient{
571 endpoint: endpoint,
572 httpClient: httpClient,
573 CallOptions: &callOpts,
574 logger: internaloption.GetLogger(opts),
575 }
576 c.setGoogleClientInfo()
577
578 return &DataPolicyClient{internalClient: c, CallOptions: callOpts}, nil
579 }
580
581 func defaultDataPolicyRESTClientOptions() []option.ClientOption {
582 return []option.ClientOption{
583 internaloption.WithDefaultEndpoint("https://bigquerydatapolicy.googleapis.com"),
584 internaloption.WithDefaultEndpointTemplate("https://bigquerydatapolicy.UNIVERSE_DOMAIN"),
585 internaloption.WithDefaultMTLSEndpoint("https://bigquerydatapolicy.mtls.googleapis.com"),
586 internaloption.WithDefaultUniverseDomain("googleapis.com"),
587 internaloption.WithDefaultAudience("https://bigquerydatapolicy.googleapis.com/"),
588 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
589 internaloption.EnableNewAuthLibrary(),
590 }
591 }
592
593 // setGoogleClientInfo sets the name and version of the application in
594 // the `x-goog-api-client` header passed on each request. Intended for
595 // use by Google-written clients.
596 func (c *dataPolicyRESTClient) setGoogleClientInfo(keyval ...string) {
597 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
598 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
599 c.xGoogHeaders = []string{
600 "x-goog-api-client", gax.XGoogHeader(kv...),
601 }
602 }
603
604 // Close closes the connection to the API service. The user should invoke this when
605 // the client is no longer required.
606 func (c *dataPolicyRESTClient) Close() error {
607 // Replace httpClient with nil to force cleanup.
608 c.httpClient = nil
609 return nil
610 }
611
612 // Connection returns a connection to the API service.
613 //
614 // Deprecated: This method always returns nil.
615 func (c *dataPolicyRESTClient) Connection() *grpc.ClientConn {
616 return nil
617 }
618 func (c *dataPolicyGRPCClient) CreateDataPolicy(ctx context.Context, req *datapoliciespb.CreateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
619 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
620
621 hds = append(c.xGoogHeaders, hds...)
622 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
623 opts = append((*c.CallOptions).CreateDataPolicy[0:len((*c.CallOptions).CreateDataPolicy):len((*c.CallOptions).CreateDataPolicy)], opts...)
624 var resp *datapoliciespb.DataPolicy
625 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
626 var err error
627 resp, err = executeRPC(ctx, c.dataPolicyClient.CreateDataPolicy, req, settings.GRPC, c.logger, "CreateDataPolicy")
628 return err
629 }, opts...)
630 if err != nil {
631 return nil, err
632 }
633 return resp, nil
634 }
635
636 func (c *dataPolicyGRPCClient) AddGrantees(ctx context.Context, req *datapoliciespb.AddGranteesRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
637 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy", url.QueryEscape(req.GetDataPolicy()))}
638
639 hds = append(c.xGoogHeaders, hds...)
640 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
641 opts = append((*c.CallOptions).AddGrantees[0:len((*c.CallOptions).AddGrantees):len((*c.CallOptions).AddGrantees)], opts...)
642 var resp *datapoliciespb.DataPolicy
643 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
644 var err error
645 resp, err = executeRPC(ctx, c.dataPolicyClient.AddGrantees, req, settings.GRPC, c.logger, "AddGrantees")
646 return err
647 }, opts...)
648 if err != nil {
649 return nil, err
650 }
651 return resp, nil
652 }
653
654 func (c *dataPolicyGRPCClient) RemoveGrantees(ctx context.Context, req *datapoliciespb.RemoveGranteesRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
655 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy", url.QueryEscape(req.GetDataPolicy()))}
656
657 hds = append(c.xGoogHeaders, hds...)
658 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
659 opts = append((*c.CallOptions).RemoveGrantees[0:len((*c.CallOptions).RemoveGrantees):len((*c.CallOptions).RemoveGrantees)], opts...)
660 var resp *datapoliciespb.DataPolicy
661 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
662 var err error
663 resp, err = executeRPC(ctx, c.dataPolicyClient.RemoveGrantees, req, settings.GRPC, c.logger, "RemoveGrantees")
664 return err
665 }, opts...)
666 if err != nil {
667 return nil, err
668 }
669 return resp, nil
670 }
671
672 func (c *dataPolicyGRPCClient) UpdateDataPolicy(ctx context.Context, req *datapoliciespb.UpdateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
673 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy.name", url.QueryEscape(req.GetDataPolicy().GetName()))}
674
675 hds = append(c.xGoogHeaders, hds...)
676 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
677 opts = append((*c.CallOptions).UpdateDataPolicy[0:len((*c.CallOptions).UpdateDataPolicy):len((*c.CallOptions).UpdateDataPolicy)], opts...)
678 var resp *datapoliciespb.DataPolicy
679 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
680 var err error
681 resp, err = executeRPC(ctx, c.dataPolicyClient.UpdateDataPolicy, req, settings.GRPC, c.logger, "UpdateDataPolicy")
682 return err
683 }, opts...)
684 if err != nil {
685 return nil, err
686 }
687 return resp, nil
688 }
689
690 func (c *dataPolicyGRPCClient) DeleteDataPolicy(ctx context.Context, req *datapoliciespb.DeleteDataPolicyRequest, opts ...gax.CallOption) error {
691 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
692
693 hds = append(c.xGoogHeaders, hds...)
694 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
695 opts = append((*c.CallOptions).DeleteDataPolicy[0:len((*c.CallOptions).DeleteDataPolicy):len((*c.CallOptions).DeleteDataPolicy)], opts...)
696 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
697 var err error
698 _, err = executeRPC(ctx, c.dataPolicyClient.DeleteDataPolicy, req, settings.GRPC, c.logger, "DeleteDataPolicy")
699 return err
700 }, opts...)
701 return err
702 }
703
704 func (c *dataPolicyGRPCClient) GetDataPolicy(ctx context.Context, req *datapoliciespb.GetDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
705 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
706
707 hds = append(c.xGoogHeaders, hds...)
708 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
709 opts = append((*c.CallOptions).GetDataPolicy[0:len((*c.CallOptions).GetDataPolicy):len((*c.CallOptions).GetDataPolicy)], opts...)
710 var resp *datapoliciespb.DataPolicy
711 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
712 var err error
713 resp, err = executeRPC(ctx, c.dataPolicyClient.GetDataPolicy, req, settings.GRPC, c.logger, "GetDataPolicy")
714 return err
715 }, opts...)
716 if err != nil {
717 return nil, err
718 }
719 return resp, nil
720 }
721
722 func (c *dataPolicyGRPCClient) ListDataPolicies(ctx context.Context, req *datapoliciespb.ListDataPoliciesRequest, opts ...gax.CallOption) *DataPolicyIterator {
723 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
724
725 hds = append(c.xGoogHeaders, hds...)
726 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
727 opts = append((*c.CallOptions).ListDataPolicies[0:len((*c.CallOptions).ListDataPolicies):len((*c.CallOptions).ListDataPolicies)], opts...)
728 it := &DataPolicyIterator{}
729 req = proto.Clone(req).(*datapoliciespb.ListDataPoliciesRequest)
730 it.InternalFetch = func(pageSize int, pageToken string) ([]*datapoliciespb.DataPolicy, string, error) {
731 resp := &datapoliciespb.ListDataPoliciesResponse{}
732 if pageToken != "" {
733 req.PageToken = pageToken
734 }
735 if pageSize > math.MaxInt32 {
736 req.PageSize = math.MaxInt32
737 } else if pageSize != 0 {
738 req.PageSize = int32(pageSize)
739 }
740 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
741 var err error
742 resp, err = executeRPC(ctx, c.dataPolicyClient.ListDataPolicies, req, settings.GRPC, c.logger, "ListDataPolicies")
743 return err
744 }, opts...)
745 if err != nil {
746 return nil, "", err
747 }
748
749 it.Response = resp
750 return resp.GetDataPolicies(), resp.GetNextPageToken(), nil
751 }
752 fetch := func(pageSize int, pageToken string) (string, error) {
753 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
754 if err != nil {
755 return "", err
756 }
757 it.items = append(it.items, items...)
758 return nextPageToken, nil
759 }
760
761 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
762 it.pageInfo.MaxSize = int(req.GetPageSize())
763 it.pageInfo.Token = req.GetPageToken()
764
765 return it
766 }
767
768 func (c *dataPolicyGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
769 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
770
771 hds = append(c.xGoogHeaders, hds...)
772 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
773 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
774 var resp *iampb.Policy
775 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
776 var err error
777 resp, err = executeRPC(ctx, c.dataPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
778 return err
779 }, opts...)
780 if err != nil {
781 return nil, err
782 }
783 return resp, nil
784 }
785
786 func (c *dataPolicyGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
787 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
788
789 hds = append(c.xGoogHeaders, hds...)
790 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
791 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
792 var resp *iampb.Policy
793 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
794 var err error
795 resp, err = executeRPC(ctx, c.dataPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
796 return err
797 }, opts...)
798 if err != nil {
799 return nil, err
800 }
801 return resp, nil
802 }
803
804 func (c *dataPolicyGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
805 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
806
807 hds = append(c.xGoogHeaders, hds...)
808 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
809 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
810 var resp *iampb.TestIamPermissionsResponse
811 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
812 var err error
813 resp, err = executeRPC(ctx, c.dataPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
814 return err
815 }, opts...)
816 if err != nil {
817 return nil, err
818 }
819 return resp, nil
820 }
821
822 // CreateDataPolicy creates a new data policy under a project with the given data_policy_id
823 // (used as the display name), and data policy type.
824 func (c *dataPolicyRESTClient) CreateDataPolicy(ctx context.Context, req *datapoliciespb.CreateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
825 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
826 jsonReq, err := m.Marshal(req)
827 if err != nil {
828 return nil, err
829 }
830
831 baseUrl, err := url.Parse(c.endpoint)
832 if err != nil {
833 return nil, err
834 }
835 baseUrl.Path += fmt.Sprintf("/v2/%v/dataPolicies", req.GetParent())
836
837 params := url.Values{}
838 params.Add("$alt", "json;enum-encoding=int")
839
840 baseUrl.RawQuery = params.Encode()
841
842 // Build HTTP headers from client and context metadata.
843 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
844
845 hds = append(c.xGoogHeaders, hds...)
846 hds = append(hds, "Content-Type", "application/json")
847 headers := gax.BuildHeaders(ctx, hds...)
848 opts = append((*c.CallOptions).CreateDataPolicy[0:len((*c.CallOptions).CreateDataPolicy):len((*c.CallOptions).CreateDataPolicy)], opts...)
849 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
850 resp := &datapoliciespb.DataPolicy{}
851 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
852 if settings.Path != "" {
853 baseUrl.Path = settings.Path
854 }
855 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
856 if err != nil {
857 return err
858 }
859 httpReq = httpReq.WithContext(ctx)
860 httpReq.Header = headers
861
862 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDataPolicy")
863 if err != nil {
864 return err
865 }
866
867 if err := unm.Unmarshal(buf, resp); err != nil {
868 return err
869 }
870
871 return nil
872 }, opts...)
873 if e != nil {
874 return nil, e
875 }
876 return resp, nil
877 }
878
879 // AddGrantees adds new grantees to a data policy.
880 // The new grantees will be added to the existing grantees.
881 // If the request contains a duplicate grantee, the grantee will be ignored.
882 // If the request contains a grantee that already exists, the grantee will be
883 // ignored.
884 func (c *dataPolicyRESTClient) AddGrantees(ctx context.Context, req *datapoliciespb.AddGranteesRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
885 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
886 jsonReq, err := m.Marshal(req)
887 if err != nil {
888 return nil, err
889 }
890
891 baseUrl, err := url.Parse(c.endpoint)
892 if err != nil {
893 return nil, err
894 }
895 baseUrl.Path += fmt.Sprintf("/v2/%v:addGrantees", req.GetDataPolicy())
896
897 params := url.Values{}
898 params.Add("$alt", "json;enum-encoding=int")
899
900 baseUrl.RawQuery = params.Encode()
901
902 // Build HTTP headers from client and context metadata.
903 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy", url.QueryEscape(req.GetDataPolicy()))}
904
905 hds = append(c.xGoogHeaders, hds...)
906 hds = append(hds, "Content-Type", "application/json")
907 headers := gax.BuildHeaders(ctx, hds...)
908 opts = append((*c.CallOptions).AddGrantees[0:len((*c.CallOptions).AddGrantees):len((*c.CallOptions).AddGrantees)], opts...)
909 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
910 resp := &datapoliciespb.DataPolicy{}
911 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
912 if settings.Path != "" {
913 baseUrl.Path = settings.Path
914 }
915 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
916 if err != nil {
917 return err
918 }
919 httpReq = httpReq.WithContext(ctx)
920 httpReq.Header = headers
921
922 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "AddGrantees")
923 if err != nil {
924 return err
925 }
926
927 if err := unm.Unmarshal(buf, resp); err != nil {
928 return err
929 }
930
931 return nil
932 }, opts...)
933 if e != nil {
934 return nil, e
935 }
936 return resp, nil
937 }
938
939 // RemoveGrantees removes grantees from a data policy.
940 // The grantees will be removed from the existing grantees.
941 // If the request contains a grantee that does not exist, the grantee will be
942 // ignored.
943 func (c *dataPolicyRESTClient) RemoveGrantees(ctx context.Context, req *datapoliciespb.RemoveGranteesRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
944 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
945 jsonReq, err := m.Marshal(req)
946 if err != nil {
947 return nil, err
948 }
949
950 baseUrl, err := url.Parse(c.endpoint)
951 if err != nil {
952 return nil, err
953 }
954 baseUrl.Path += fmt.Sprintf("/v2/%v:removeGrantees", req.GetDataPolicy())
955
956 params := url.Values{}
957 params.Add("$alt", "json;enum-encoding=int")
958
959 baseUrl.RawQuery = params.Encode()
960
961 // Build HTTP headers from client and context metadata.
962 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy", url.QueryEscape(req.GetDataPolicy()))}
963
964 hds = append(c.xGoogHeaders, hds...)
965 hds = append(hds, "Content-Type", "application/json")
966 headers := gax.BuildHeaders(ctx, hds...)
967 opts = append((*c.CallOptions).RemoveGrantees[0:len((*c.CallOptions).RemoveGrantees):len((*c.CallOptions).RemoveGrantees)], opts...)
968 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
969 resp := &datapoliciespb.DataPolicy{}
970 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
971 if settings.Path != "" {
972 baseUrl.Path = settings.Path
973 }
974 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
975 if err != nil {
976 return err
977 }
978 httpReq = httpReq.WithContext(ctx)
979 httpReq.Header = headers
980
981 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RemoveGrantees")
982 if err != nil {
983 return err
984 }
985
986 if err := unm.Unmarshal(buf, resp); err != nil {
987 return err
988 }
989
990 return nil
991 }, opts...)
992 if e != nil {
993 return nil, e
994 }
995 return resp, nil
996 }
997
998 // UpdateDataPolicy updates the metadata for an existing data policy. The target data policy
999 // can be specified by the resource name.
1000 func (c *dataPolicyRESTClient) UpdateDataPolicy(ctx context.Context, req *datapoliciespb.UpdateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
1001 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1002 body := req.GetDataPolicy()
1003 jsonReq, err := m.Marshal(body)
1004 if err != nil {
1005 return nil, err
1006 }
1007
1008 baseUrl, err := url.Parse(c.endpoint)
1009 if err != nil {
1010 return nil, err
1011 }
1012 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetDataPolicy().GetName())
1013
1014 params := url.Values{}
1015 params.Add("$alt", "json;enum-encoding=int")
1016 if req.GetAllowMissing() {
1017 params.Add("allowMissing", fmt.Sprintf("%v", req.GetAllowMissing()))
1018 }
1019 if req.GetUpdateMask() != nil {
1020 field, err := protojson.Marshal(req.GetUpdateMask())
1021 if err != nil {
1022 return nil, err
1023 }
1024 params.Add("updateMask", string(field[1:len(field)-1]))
1025 }
1026
1027 baseUrl.RawQuery = params.Encode()
1028
1029 // Build HTTP headers from client and context metadata.
1030 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy.name", url.QueryEscape(req.GetDataPolicy().GetName()))}
1031
1032 hds = append(c.xGoogHeaders, hds...)
1033 hds = append(hds, "Content-Type", "application/json")
1034 headers := gax.BuildHeaders(ctx, hds...)
1035 opts = append((*c.CallOptions).UpdateDataPolicy[0:len((*c.CallOptions).UpdateDataPolicy):len((*c.CallOptions).UpdateDataPolicy)], opts...)
1036 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1037 resp := &datapoliciespb.DataPolicy{}
1038 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1039 if settings.Path != "" {
1040 baseUrl.Path = settings.Path
1041 }
1042 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1043 if err != nil {
1044 return err
1045 }
1046 httpReq = httpReq.WithContext(ctx)
1047 httpReq.Header = headers
1048
1049 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateDataPolicy")
1050 if err != nil {
1051 return err
1052 }
1053
1054 if err := unm.Unmarshal(buf, resp); err != nil {
1055 return err
1056 }
1057
1058 return nil
1059 }, opts...)
1060 if e != nil {
1061 return nil, e
1062 }
1063 return resp, nil
1064 }
1065
1066 // DeleteDataPolicy deletes the data policy specified by its resource name.
1067 func (c *dataPolicyRESTClient) DeleteDataPolicy(ctx context.Context, req *datapoliciespb.DeleteDataPolicyRequest, opts ...gax.CallOption) error {
1068 baseUrl, err := url.Parse(c.endpoint)
1069 if err != nil {
1070 return err
1071 }
1072 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName())
1073
1074 params := url.Values{}
1075 params.Add("$alt", "json;enum-encoding=int")
1076
1077 baseUrl.RawQuery = params.Encode()
1078
1079 // Build HTTP headers from client and context metadata.
1080 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1081
1082 hds = append(c.xGoogHeaders, hds...)
1083 hds = append(hds, "Content-Type", "application/json")
1084 headers := gax.BuildHeaders(ctx, hds...)
1085 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1086 if settings.Path != "" {
1087 baseUrl.Path = settings.Path
1088 }
1089 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1090 if err != nil {
1091 return err
1092 }
1093 httpReq = httpReq.WithContext(ctx)
1094 httpReq.Header = headers
1095
1096 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDataPolicy")
1097 return err
1098 }, opts...)
1099 }
1100
1101 // GetDataPolicy gets the data policy specified by its resource name.
1102 func (c *dataPolicyRESTClient) GetDataPolicy(ctx context.Context, req *datapoliciespb.GetDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
1103 baseUrl, err := url.Parse(c.endpoint)
1104 if err != nil {
1105 return nil, err
1106 }
1107 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName())
1108
1109 params := url.Values{}
1110 params.Add("$alt", "json;enum-encoding=int")
1111
1112 baseUrl.RawQuery = params.Encode()
1113
1114 // Build HTTP headers from client and context metadata.
1115 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1116
1117 hds = append(c.xGoogHeaders, hds...)
1118 hds = append(hds, "Content-Type", "application/json")
1119 headers := gax.BuildHeaders(ctx, hds...)
1120 opts = append((*c.CallOptions).GetDataPolicy[0:len((*c.CallOptions).GetDataPolicy):len((*c.CallOptions).GetDataPolicy)], opts...)
1121 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1122 resp := &datapoliciespb.DataPolicy{}
1123 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1124 if settings.Path != "" {
1125 baseUrl.Path = settings.Path
1126 }
1127 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1128 if err != nil {
1129 return err
1130 }
1131 httpReq = httpReq.WithContext(ctx)
1132 httpReq.Header = headers
1133
1134 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDataPolicy")
1135 if err != nil {
1136 return err
1137 }
1138
1139 if err := unm.Unmarshal(buf, resp); err != nil {
1140 return err
1141 }
1142
1143 return nil
1144 }, opts...)
1145 if e != nil {
1146 return nil, e
1147 }
1148 return resp, nil
1149 }
1150
1151 // ListDataPolicies list all of the data policies in the specified parent project.
1152 func (c *dataPolicyRESTClient) ListDataPolicies(ctx context.Context, req *datapoliciespb.ListDataPoliciesRequest, opts ...gax.CallOption) *DataPolicyIterator {
1153 it := &DataPolicyIterator{}
1154 req = proto.Clone(req).(*datapoliciespb.ListDataPoliciesRequest)
1155 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1156 it.InternalFetch = func(pageSize int, pageToken string) ([]*datapoliciespb.DataPolicy, string, error) {
1157 resp := &datapoliciespb.ListDataPoliciesResponse{}
1158 if pageToken != "" {
1159 req.PageToken = pageToken
1160 }
1161 if pageSize > math.MaxInt32 {
1162 req.PageSize = math.MaxInt32
1163 } else if pageSize != 0 {
1164 req.PageSize = int32(pageSize)
1165 }
1166 baseUrl, err := url.Parse(c.endpoint)
1167 if err != nil {
1168 return nil, "", err
1169 }
1170 baseUrl.Path += fmt.Sprintf("/v2/%v/dataPolicies", req.GetParent())
1171
1172 params := url.Values{}
1173 params.Add("$alt", "json;enum-encoding=int")
1174 if req.GetFilter() != "" {
1175 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1176 }
1177 if req.GetPageSize() != 0 {
1178 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1179 }
1180 if req.GetPageToken() != "" {
1181 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1182 }
1183
1184 baseUrl.RawQuery = params.Encode()
1185
1186 // Build HTTP headers from client and context metadata.
1187 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1188 headers := gax.BuildHeaders(ctx, hds...)
1189 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1190 if settings.Path != "" {
1191 baseUrl.Path = settings.Path
1192 }
1193 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1194 if err != nil {
1195 return err
1196 }
1197 httpReq.Header = headers
1198
1199 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDataPolicies")
1200 if err != nil {
1201 return err
1202 }
1203 if err := unm.Unmarshal(buf, resp); err != nil {
1204 return err
1205 }
1206
1207 return nil
1208 }, opts...)
1209 if e != nil {
1210 return nil, "", e
1211 }
1212 it.Response = resp
1213 return resp.GetDataPolicies(), resp.GetNextPageToken(), nil
1214 }
1215
1216 fetch := func(pageSize int, pageToken string) (string, error) {
1217 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1218 if err != nil {
1219 return "", err
1220 }
1221 it.items = append(it.items, items...)
1222 return nextPageToken, nil
1223 }
1224
1225 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1226 it.pageInfo.MaxSize = int(req.GetPageSize())
1227 it.pageInfo.Token = req.GetPageToken()
1228
1229 return it
1230 }
1231
1232 // GetIamPolicy gets the IAM policy for the specified data policy.
1233 func (c *dataPolicyRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1234 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1235 jsonReq, err := m.Marshal(req)
1236 if err != nil {
1237 return nil, err
1238 }
1239
1240 baseUrl, err := url.Parse(c.endpoint)
1241 if err != nil {
1242 return nil, err
1243 }
1244 baseUrl.Path += fmt.Sprintf("/v2/%v:getIamPolicy", req.GetResource())
1245
1246 params := url.Values{}
1247 params.Add("$alt", "json;enum-encoding=int")
1248
1249 baseUrl.RawQuery = params.Encode()
1250
1251 // Build HTTP headers from client and context metadata.
1252 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1253
1254 hds = append(c.xGoogHeaders, hds...)
1255 hds = append(hds, "Content-Type", "application/json")
1256 headers := gax.BuildHeaders(ctx, hds...)
1257 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1258 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1259 resp := &iampb.Policy{}
1260 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1261 if settings.Path != "" {
1262 baseUrl.Path = settings.Path
1263 }
1264 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1265 if err != nil {
1266 return err
1267 }
1268 httpReq = httpReq.WithContext(ctx)
1269 httpReq.Header = headers
1270
1271 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
1272 if err != nil {
1273 return err
1274 }
1275
1276 if err := unm.Unmarshal(buf, resp); err != nil {
1277 return err
1278 }
1279
1280 return nil
1281 }, opts...)
1282 if e != nil {
1283 return nil, e
1284 }
1285 return resp, nil
1286 }
1287
1288 // SetIamPolicy sets the IAM policy for the specified data policy.
1289 func (c *dataPolicyRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1290 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1291 jsonReq, err := m.Marshal(req)
1292 if err != nil {
1293 return nil, err
1294 }
1295
1296 baseUrl, err := url.Parse(c.endpoint)
1297 if err != nil {
1298 return nil, err
1299 }
1300 baseUrl.Path += fmt.Sprintf("/v2/%v:setIamPolicy", req.GetResource())
1301
1302 params := url.Values{}
1303 params.Add("$alt", "json;enum-encoding=int")
1304
1305 baseUrl.RawQuery = params.Encode()
1306
1307 // Build HTTP headers from client and context metadata.
1308 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1309
1310 hds = append(c.xGoogHeaders, hds...)
1311 hds = append(hds, "Content-Type", "application/json")
1312 headers := gax.BuildHeaders(ctx, hds...)
1313 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1314 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1315 resp := &iampb.Policy{}
1316 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1317 if settings.Path != "" {
1318 baseUrl.Path = settings.Path
1319 }
1320 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1321 if err != nil {
1322 return err
1323 }
1324 httpReq = httpReq.WithContext(ctx)
1325 httpReq.Header = headers
1326
1327 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
1328 if err != nil {
1329 return err
1330 }
1331
1332 if err := unm.Unmarshal(buf, resp); err != nil {
1333 return err
1334 }
1335
1336 return nil
1337 }, opts...)
1338 if e != nil {
1339 return nil, e
1340 }
1341 return resp, nil
1342 }
1343
1344 // TestIamPermissions returns the caller’s permission on the specified data policy resource.
1345 func (c *dataPolicyRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1346 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1347 jsonReq, err := m.Marshal(req)
1348 if err != nil {
1349 return nil, err
1350 }
1351
1352 baseUrl, err := url.Parse(c.endpoint)
1353 if err != nil {
1354 return nil, err
1355 }
1356 baseUrl.Path += fmt.Sprintf("/v2/%v:testIamPermissions", req.GetResource())
1357
1358 params := url.Values{}
1359 params.Add("$alt", "json;enum-encoding=int")
1360
1361 baseUrl.RawQuery = params.Encode()
1362
1363 // Build HTTP headers from client and context metadata.
1364 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1365
1366 hds = append(c.xGoogHeaders, hds...)
1367 hds = append(hds, "Content-Type", "application/json")
1368 headers := gax.BuildHeaders(ctx, hds...)
1369 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1370 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1371 resp := &iampb.TestIamPermissionsResponse{}
1372 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1373 if settings.Path != "" {
1374 baseUrl.Path = settings.Path
1375 }
1376 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1377 if err != nil {
1378 return err
1379 }
1380 httpReq = httpReq.WithContext(ctx)
1381 httpReq.Header = headers
1382
1383 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
1384 if err != nil {
1385 return err
1386 }
1387
1388 if err := unm.Unmarshal(buf, resp); err != nil {
1389 return err
1390 }
1391
1392 return nil
1393 }, opts...)
1394 if e != nil {
1395 return nil, e
1396 }
1397 return resp, nil
1398 }