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