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