Debian Codegraph @

bigquery/datapolicies/apiv1/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/apiv1/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 UpdateDataPolicy []gax.CallOption
49 RenameDataPolicy []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 internaloption.EnableNewAuthLibrary(),
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 // internalDataPolicyClient is an interface that defines the methods available from BigQuery Data Policy API.
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 // DataPolicyClient is a client for interacting with BigQuery Data Policy API.
307 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
308 //
309 // Data Policy Service provides APIs for managing the label-policy bindings.
310 type DataPolicyClient struct {
311 // The internal transport-dependent client.
312 internalClient internalDataPolicyClient
313
314 // The call options for this service.
315 CallOptions *DataPolicyCallOptions
316 }
317
318 // Wrapper methods routed to the internal client.
319
320 // Close closes the connection to the API service. The user should invoke this when
321 // the client is no longer required.
322 func (c *DataPolicyClient) Close() error {
323 return c.internalClient.Close()
324 }
325
326 // setGoogleClientInfo sets the name and version of the application in
327 // the `x-goog-api-client` header passed on each request. Intended for
328 // use by Google-written clients.
329 func (c *DataPolicyClient) setGoogleClientInfo(keyval ...string) {
330 c.internalClient.setGoogleClientInfo(keyval...)
331 }
332
333 // Connection returns a connection to the API service.
334 //
335 // Deprecated: Connections are now pooled so this method does not always
336 // return the same resource.
337 func (c *DataPolicyClient) Connection() *grpc.ClientConn {
338 return c.internalClient.Connection()
339 }
340
341 // CreateDataPolicy creates a new data policy under a project with the given dataPolicyId
342 // (used as the display name), policy tag, and data policy type.
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 // UpdateDataPolicy updates the metadata for an existing data policy. The target data policy
348 // can be specified by the resource name.
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 // RenameDataPolicy renames the id (display name) of the specified data policy.
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 // DeleteDataPolicy deletes the data policy specified by its resource name.
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 // GetDataPolicy gets the data policy specified by its resource name.
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 // ListDataPolicies list all of the data policies in the specified parent project.
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 // GetIamPolicy gets the IAM policy for the specified data policy.
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 // SetIamPolicy sets the IAM policy for the specified data policy.
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 // TestIamPermissions returns the caller’s permission on the specified data policy resource.
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 // dataPolicyGRPCClient is a client for interacting with BigQuery Data Policy API over gRPC transport.
389 //
390 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
391 type dataPolicyGRPCClient struct {
392 // Connection pool of gRPC connections to the service.
393 connPool gtransport.ConnPool
394
395 // Points back to the CallOptions field of the containing DataPolicyClient
396 CallOptions **DataPolicyCallOptions
397
398 // The gRPC API client.
399 dataPolicyClient datapoliciespb.DataPolicyServiceClient
400
401 // The x-goog-* metadata to be sent with each request.
402 xGoogHeaders []string
403
404 logger *slog.Logger
405 }
406
407 // NewDataPolicyClient creates a new data policy service client based on gRPC.
408 // The returned client must be Closed when it is done being used to clean up its underlying connections.
409 //
410 // Data Policy Service provides APIs for managing the label-policy bindings.
411 func NewDataPolicyClient(ctx context.Context, opts ...option.ClientOption) (*DataPolicyClient, error) {
412 clientOpts := defaultDataPolicyGRPCClientOptions()
413 if newDataPolicyClientHook != nil {
414 hookOpts, err := newDataPolicyClientHook(ctx, clientHookParams{})
415 if err != nil {
416 return nil, err
417 }
418 clientOpts = append(clientOpts, hookOpts...)
419 }
420
421 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
422 if err != nil {
423 return nil, err
424 }
425 client := DataPolicyClient{CallOptions: defaultDataPolicyCallOptions()}
426
427 c := &dataPolicyGRPCClient{
428 connPool: connPool,
429 dataPolicyClient: datapoliciespb.NewDataPolicyServiceClient(connPool),
430 CallOptions: &client.CallOptions,
431 logger: internaloption.GetLogger(opts),
432 }
433 c.setGoogleClientInfo()
434
435 client.internalClient = c
436
437 return &client, nil
438 }
439
440 // Connection returns a connection to the API service.
441 //
442 // Deprecated: Connections are now pooled so this method does not always
443 // return the same resource.
444 func (c *dataPolicyGRPCClient) Connection() *grpc.ClientConn {
445 return c.connPool.Conn()
446 }
447
448 // setGoogleClientInfo sets the name and version of the application in
449 // the `x-goog-api-client` header passed on each request. Intended for
450 // use by Google-written clients.
451 func (c *dataPolicyGRPCClient) setGoogleClientInfo(keyval ...string) {
452 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
453 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
454 c.xGoogHeaders = []string{
455 "x-goog-api-client", gax.XGoogHeader(kv...),
456 }
457 }
458
459 // Close closes the connection to the API service. The user should invoke this when
460 // the client is no longer required.
461 func (c *dataPolicyGRPCClient) Close() error {
462 return c.connPool.Close()
463 }
464
465 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
466 type dataPolicyRESTClient struct {
467 // The http endpoint to connect to.
468 endpoint string
469
470 // The http client.
471 httpClient *http.Client
472
473 // The x-goog-* headers to be sent with each request.
474 xGoogHeaders []string
475
476 // Points back to the CallOptions field of the containing DataPolicyClient
477 CallOptions **DataPolicyCallOptions
478
479 logger *slog.Logger
480 }
481
482 // NewDataPolicyRESTClient creates a new data policy service rest client.
483 //
484 // Data Policy Service provides APIs for managing the label-policy bindings.
485 func NewDataPolicyRESTClient(ctx context.Context, opts ...option.ClientOption) (*DataPolicyClient, error) {
486 clientOpts := append(defaultDataPolicyRESTClientOptions(), opts...)
487 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
488 if err != nil {
489 return nil, err
490 }
491
492 callOpts := defaultDataPolicyRESTCallOptions()
493 c := &dataPolicyRESTClient{
494 endpoint: endpoint,
495 httpClient: httpClient,
496 CallOptions: &callOpts,
497 logger: internaloption.GetLogger(opts),
498 }
499 c.setGoogleClientInfo()
500
501 return &DataPolicyClient{internalClient: c, CallOptions: callOpts}, nil
502 }
503
504 func defaultDataPolicyRESTClientOptions() []option.ClientOption {
505 return []option.ClientOption{
506 internaloption.WithDefaultEndpoint("https://bigquerydatapolicy.googleapis.com"),
507 internaloption.WithDefaultEndpointTemplate("https://bigquerydatapolicy.UNIVERSE_DOMAIN"),
508 internaloption.WithDefaultMTLSEndpoint("https://bigquerydatapolicy.mtls.googleapis.com"),
509 internaloption.WithDefaultUniverseDomain("googleapis.com"),
510 internaloption.WithDefaultAudience("https://bigquerydatapolicy.googleapis.com/"),
511 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
512 internaloption.EnableNewAuthLibrary(),
513 }
514 }
515
516 // setGoogleClientInfo sets the name and version of the application in
517 // the `x-goog-api-client` header passed on each request. Intended for
518 // use by Google-written clients.
519 func (c *dataPolicyRESTClient) setGoogleClientInfo(keyval ...string) {
520 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
521 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
522 c.xGoogHeaders = []string{
523 "x-goog-api-client", gax.XGoogHeader(kv...),
524 }
525 }
526
527 // Close closes the connection to the API service. The user should invoke this when
528 // the client is no longer required.
529 func (c *dataPolicyRESTClient) Close() error {
530 // Replace httpClient with nil to force cleanup.
531 c.httpClient = nil
532 return nil
533 }
534
535 // Connection returns a connection to the API service.
536 //
537 // Deprecated: This method always returns nil.
538 func (c *dataPolicyRESTClient) Connection() *grpc.ClientConn {
539 return nil
540 }
541 func (c *dataPolicyGRPCClient) CreateDataPolicy(ctx context.Context, req *datapoliciespb.CreateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
542 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
543
544 hds = append(c.xGoogHeaders, hds...)
545 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
546 opts = append((*c.CallOptions).CreateDataPolicy[0:len((*c.CallOptions).CreateDataPolicy):len((*c.CallOptions).CreateDataPolicy)], opts...)
547 var resp *datapoliciespb.DataPolicy
548 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
549 var err error
550 resp, err = executeRPC(ctx, c.dataPolicyClient.CreateDataPolicy, req, settings.GRPC, c.logger, "CreateDataPolicy")
551 return err
552 }, opts...)
553 if err != nil {
554 return nil, err
555 }
556 return resp, nil
557 }
558
559 func (c *dataPolicyGRPCClient) UpdateDataPolicy(ctx context.Context, req *datapoliciespb.UpdateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
560 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy.name", url.QueryEscape(req.GetDataPolicy().GetName()))}
561
562 hds = append(c.xGoogHeaders, hds...)
563 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
564 opts = append((*c.CallOptions).UpdateDataPolicy[0:len((*c.CallOptions).UpdateDataPolicy):len((*c.CallOptions).UpdateDataPolicy)], opts...)
565 var resp *datapoliciespb.DataPolicy
566 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
567 var err error
568 resp, err = executeRPC(ctx, c.dataPolicyClient.UpdateDataPolicy, req, settings.GRPC, c.logger, "UpdateDataPolicy")
569 return err
570 }, opts...)
571 if err != nil {
572 return nil, err
573 }
574 return resp, nil
575 }
576
577 func (c *dataPolicyGRPCClient) RenameDataPolicy(ctx context.Context, req *datapoliciespb.RenameDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
578 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
579
580 hds = append(c.xGoogHeaders, hds...)
581 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
582 opts = append((*c.CallOptions).RenameDataPolicy[0:len((*c.CallOptions).RenameDataPolicy):len((*c.CallOptions).RenameDataPolicy)], opts...)
583 var resp *datapoliciespb.DataPolicy
584 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
585 var err error
586 resp, err = executeRPC(ctx, c.dataPolicyClient.RenameDataPolicy, req, settings.GRPC, c.logger, "RenameDataPolicy")
587 return err
588 }, opts...)
589 if err != nil {
590 return nil, err
591 }
592 return resp, nil
593 }
594
595 func (c *dataPolicyGRPCClient) DeleteDataPolicy(ctx context.Context, req *datapoliciespb.DeleteDataPolicyRequest, opts ...gax.CallOption) error {
596 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
597
598 hds = append(c.xGoogHeaders, hds...)
599 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
600 opts = append((*c.CallOptions).DeleteDataPolicy[0:len((*c.CallOptions).DeleteDataPolicy):len((*c.CallOptions).DeleteDataPolicy)], opts...)
601 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
602 var err error
603 _, err = executeRPC(ctx, c.dataPolicyClient.DeleteDataPolicy, req, settings.GRPC, c.logger, "DeleteDataPolicy")
604 return err
605 }, opts...)
606 return err
607 }
608
609 func (c *dataPolicyGRPCClient) GetDataPolicy(ctx context.Context, req *datapoliciespb.GetDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
610 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
611
612 hds = append(c.xGoogHeaders, hds...)
613 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
614 opts = append((*c.CallOptions).GetDataPolicy[0:len((*c.CallOptions).GetDataPolicy):len((*c.CallOptions).GetDataPolicy)], opts...)
615 var resp *datapoliciespb.DataPolicy
616 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
617 var err error
618 resp, err = executeRPC(ctx, c.dataPolicyClient.GetDataPolicy, req, settings.GRPC, c.logger, "GetDataPolicy")
619 return err
620 }, opts...)
621 if err != nil {
622 return nil, err
623 }
624 return resp, nil
625 }
626
627 func (c *dataPolicyGRPCClient) ListDataPolicies(ctx context.Context, req *datapoliciespb.ListDataPoliciesRequest, opts ...gax.CallOption) *DataPolicyIterator {
628 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
629
630 hds = append(c.xGoogHeaders, hds...)
631 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
632 opts = append((*c.CallOptions).ListDataPolicies[0:len((*c.CallOptions).ListDataPolicies):len((*c.CallOptions).ListDataPolicies)], opts...)
633 it := &DataPolicyIterator{}
634 req = proto.Clone(req).(*datapoliciespb.ListDataPoliciesRequest)
635 it.InternalFetch = func(pageSize int, pageToken string) ([]*datapoliciespb.DataPolicy, string, error) {
636 resp := &datapoliciespb.ListDataPoliciesResponse{}
637 if pageToken != "" {
638 req.PageToken = pageToken
639 }
640 if pageSize > math.MaxInt32 {
641 req.PageSize = math.MaxInt32
642 } else if pageSize != 0 {
643 req.PageSize = int32(pageSize)
644 }
645 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
646 var err error
647 resp, err = executeRPC(ctx, c.dataPolicyClient.ListDataPolicies, req, settings.GRPC, c.logger, "ListDataPolicies")
648 return err
649 }, opts...)
650 if err != nil {
651 return nil, "", err
652 }
653
654 it.Response = resp
655 return resp.GetDataPolicies(), resp.GetNextPageToken(), nil
656 }
657 fetch := func(pageSize int, pageToken string) (string, error) {
658 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
659 if err != nil {
660 return "", err
661 }
662 it.items = append(it.items, items...)
663 return nextPageToken, nil
664 }
665
666 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
667 it.pageInfo.MaxSize = int(req.GetPageSize())
668 it.pageInfo.Token = req.GetPageToken()
669
670 return it
671 }
672
673 func (c *dataPolicyGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
674 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
675
676 hds = append(c.xGoogHeaders, hds...)
677 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
678 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
679 var resp *iampb.Policy
680 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
681 var err error
682 resp, err = executeRPC(ctx, c.dataPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
683 return err
684 }, opts...)
685 if err != nil {
686 return nil, err
687 }
688 return resp, nil
689 }
690
691 func (c *dataPolicyGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
692 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
693
694 hds = append(c.xGoogHeaders, hds...)
695 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
696 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
697 var resp *iampb.Policy
698 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
699 var err error
700 resp, err = executeRPC(ctx, c.dataPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
701 return err
702 }, opts...)
703 if err != nil {
704 return nil, err
705 }
706 return resp, nil
707 }
708
709 func (c *dataPolicyGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
710 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
711
712 hds = append(c.xGoogHeaders, hds...)
713 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
714 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
715 var resp *iampb.TestIamPermissionsResponse
716 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
717 var err error
718 resp, err = executeRPC(ctx, c.dataPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
719 return err
720 }, opts...)
721 if err != nil {
722 return nil, err
723 }
724 return resp, nil
725 }
726
727 // CreateDataPolicy creates a new data policy under a project with the given dataPolicyId
728 // (used as the display name), policy tag, and data policy type.
729 func (c *dataPolicyRESTClient) CreateDataPolicy(ctx context.Context, req *datapoliciespb.CreateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
730 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
731 body := req.GetDataPolicy()
732 jsonReq, err := m.Marshal(body)
733 if err != nil {
734 return nil, err
735 }
736
737 baseUrl, err := url.Parse(c.endpoint)
738 if err != nil {
739 return nil, err
740 }
741 baseUrl.Path += fmt.Sprintf("/v1/%v/dataPolicies", req.GetParent())
742
743 params := url.Values{}
744 params.Add("$alt", "json;enum-encoding=int")
745
746 baseUrl.RawQuery = params.Encode()
747
748 // Build HTTP headers from client and context metadata.
749 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
750
751 hds = append(c.xGoogHeaders, hds...)
752 hds = append(hds, "Content-Type", "application/json")
753 headers := gax.BuildHeaders(ctx, hds...)
754 opts = append((*c.CallOptions).CreateDataPolicy[0:len((*c.CallOptions).CreateDataPolicy):len((*c.CallOptions).CreateDataPolicy)], opts...)
755 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
756 resp := &datapoliciespb.DataPolicy{}
757 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
758 if settings.Path != "" {
759 baseUrl.Path = settings.Path
760 }
761 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
762 if err != nil {
763 return err
764 }
765 httpReq = httpReq.WithContext(ctx)
766 httpReq.Header = headers
767
768 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDataPolicy")
769 if err != nil {
770 return err
771 }
772
773 if err := unm.Unmarshal(buf, resp); err != nil {
774 return err
775 }
776
777 return nil
778 }, opts...)
779 if e != nil {
780 return nil, e
781 }
782 return resp, nil
783 }
784
785 // UpdateDataPolicy updates the metadata for an existing data policy. The target data policy
786 // can be specified by the resource name.
787 func (c *dataPolicyRESTClient) UpdateDataPolicy(ctx context.Context, req *datapoliciespb.UpdateDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
788 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
789 body := req.GetDataPolicy()
790 jsonReq, err := m.Marshal(body)
791 if err != nil {
792 return nil, err
793 }
794
795 baseUrl, err := url.Parse(c.endpoint)
796 if err != nil {
797 return nil, err
798 }
799 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetDataPolicy().GetName())
800
801 params := url.Values{}
802 params.Add("$alt", "json;enum-encoding=int")
803 if req.GetUpdateMask() != nil {
804 field, err := protojson.Marshal(req.GetUpdateMask())
805 if err != nil {
806 return nil, err
807 }
808 params.Add("updateMask", string(field[1:len(field)-1]))
809 }
810
811 baseUrl.RawQuery = params.Encode()
812
813 // Build HTTP headers from client and context metadata.
814 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "data_policy.name", url.QueryEscape(req.GetDataPolicy().GetName()))}
815
816 hds = append(c.xGoogHeaders, hds...)
817 hds = append(hds, "Content-Type", "application/json")
818 headers := gax.BuildHeaders(ctx, hds...)
819 opts = append((*c.CallOptions).UpdateDataPolicy[0:len((*c.CallOptions).UpdateDataPolicy):len((*c.CallOptions).UpdateDataPolicy)], opts...)
820 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
821 resp := &datapoliciespb.DataPolicy{}
822 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
823 if settings.Path != "" {
824 baseUrl.Path = settings.Path
825 }
826 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
827 if err != nil {
828 return err
829 }
830 httpReq = httpReq.WithContext(ctx)
831 httpReq.Header = headers
832
833 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateDataPolicy")
834 if err != nil {
835 return err
836 }
837
838 if err := unm.Unmarshal(buf, resp); err != nil {
839 return err
840 }
841
842 return nil
843 }, opts...)
844 if e != nil {
845 return nil, e
846 }
847 return resp, nil
848 }
849
850 // RenameDataPolicy renames the id (display name) of the specified data policy.
851 func (c *dataPolicyRESTClient) RenameDataPolicy(ctx context.Context, req *datapoliciespb.RenameDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
852 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
853 jsonReq, err := m.Marshal(req)
854 if err != nil {
855 return nil, err
856 }
857
858 baseUrl, err := url.Parse(c.endpoint)
859 if err != nil {
860 return nil, err
861 }
862 baseUrl.Path += fmt.Sprintf("/v1/%v:rename", req.GetName())
863
864 params := url.Values{}
865 params.Add("$alt", "json;enum-encoding=int")
866
867 baseUrl.RawQuery = params.Encode()
868
869 // Build HTTP headers from client and context metadata.
870 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
871
872 hds = append(c.xGoogHeaders, hds...)
873 hds = append(hds, "Content-Type", "application/json")
874 headers := gax.BuildHeaders(ctx, hds...)
875 opts = append((*c.CallOptions).RenameDataPolicy[0:len((*c.CallOptions).RenameDataPolicy):len((*c.CallOptions).RenameDataPolicy)], opts...)
876 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
877 resp := &datapoliciespb.DataPolicy{}
878 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
879 if settings.Path != "" {
880 baseUrl.Path = settings.Path
881 }
882 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
883 if err != nil {
884 return err
885 }
886 httpReq = httpReq.WithContext(ctx)
887 httpReq.Header = headers
888
889 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RenameDataPolicy")
890 if err != nil {
891 return err
892 }
893
894 if err := unm.Unmarshal(buf, resp); err != nil {
895 return err
896 }
897
898 return nil
899 }, opts...)
900 if e != nil {
901 return nil, e
902 }
903 return resp, nil
904 }
905
906 // DeleteDataPolicy deletes the data policy specified by its resource name.
907 func (c *dataPolicyRESTClient) DeleteDataPolicy(ctx context.Context, req *datapoliciespb.DeleteDataPolicyRequest, opts ...gax.CallOption) error {
908 baseUrl, err := url.Parse(c.endpoint)
909 if err != nil {
910 return err
911 }
912 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
913
914 params := url.Values{}
915 params.Add("$alt", "json;enum-encoding=int")
916
917 baseUrl.RawQuery = params.Encode()
918
919 // Build HTTP headers from client and context metadata.
920 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
921
922 hds = append(c.xGoogHeaders, hds...)
923 hds = append(hds, "Content-Type", "application/json")
924 headers := gax.BuildHeaders(ctx, hds...)
925 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
926 if settings.Path != "" {
927 baseUrl.Path = settings.Path
928 }
929 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
930 if err != nil {
931 return err
932 }
933 httpReq = httpReq.WithContext(ctx)
934 httpReq.Header = headers
935
936 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDataPolicy")
937 return err
938 }, opts...)
939 }
940
941 // GetDataPolicy gets the data policy specified by its resource name.
942 func (c *dataPolicyRESTClient) GetDataPolicy(ctx context.Context, req *datapoliciespb.GetDataPolicyRequest, opts ...gax.CallOption) (*datapoliciespb.DataPolicy, error) {
943 baseUrl, err := url.Parse(c.endpoint)
944 if err != nil {
945 return nil, err
946 }
947 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
948
949 params := url.Values{}
950 params.Add("$alt", "json;enum-encoding=int")
951
952 baseUrl.RawQuery = params.Encode()
953
954 // Build HTTP headers from client and context metadata.
955 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
956
957 hds = append(c.xGoogHeaders, hds...)
958 hds = append(hds, "Content-Type", "application/json")
959 headers := gax.BuildHeaders(ctx, hds...)
960 opts = append((*c.CallOptions).GetDataPolicy[0:len((*c.CallOptions).GetDataPolicy):len((*c.CallOptions).GetDataPolicy)], opts...)
961 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
962 resp := &datapoliciespb.DataPolicy{}
963 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
964 if settings.Path != "" {
965 baseUrl.Path = settings.Path
966 }
967 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
968 if err != nil {
969 return err
970 }
971 httpReq = httpReq.WithContext(ctx)
972 httpReq.Header = headers
973
974 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDataPolicy")
975 if err != nil {
976 return err
977 }
978
979 if err := unm.Unmarshal(buf, resp); err != nil {
980 return err
981 }
982
983 return nil
984 }, opts...)
985 if e != nil {
986 return nil, e
987 }
988 return resp, nil
989 }
990
991 // ListDataPolicies list all of the data policies in the specified parent project.
992 func (c *dataPolicyRESTClient) ListDataPolicies(ctx context.Context, req *datapoliciespb.ListDataPoliciesRequest, opts ...gax.CallOption) *DataPolicyIterator {
993 it := &DataPolicyIterator{}
994 req = proto.Clone(req).(*datapoliciespb.ListDataPoliciesRequest)
995 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
996 it.InternalFetch = func(pageSize int, pageToken string) ([]*datapoliciespb.DataPolicy, string, error) {
997 resp := &datapoliciespb.ListDataPoliciesResponse{}
998 if pageToken != "" {
999 req.PageToken = pageToken
1000 }
1001 if pageSize > math.MaxInt32 {
1002 req.PageSize = math.MaxInt32
1003 } else if pageSize != 0 {
1004 req.PageSize = int32(pageSize)
1005 }
1006 baseUrl, err := url.Parse(c.endpoint)
1007 if err != nil {
1008 return nil, "", err
1009 }
1010 baseUrl.Path += fmt.Sprintf("/v1/%v/dataPolicies", req.GetParent())
1011
1012 params := url.Values{}
1013 params.Add("$alt", "json;enum-encoding=int")
1014 if req.GetFilter() != "" {
1015 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1016 }
1017 if req.GetPageSize() != 0 {
1018 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1019 }
1020 if req.GetPageToken() != "" {
1021 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1022 }
1023
1024 baseUrl.RawQuery = params.Encode()
1025
1026 // Build HTTP headers from client and context metadata.
1027 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1028 headers := gax.BuildHeaders(ctx, hds...)
1029 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1030 if settings.Path != "" {
1031 baseUrl.Path = settings.Path
1032 }
1033 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1034 if err != nil {
1035 return err
1036 }
1037 httpReq.Header = headers
1038
1039 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDataPolicies")
1040 if err != nil {
1041 return err
1042 }
1043 if err := unm.Unmarshal(buf, resp); err != nil {
1044 return err
1045 }
1046
1047 return nil
1048 }, opts...)
1049 if e != nil {
1050 return nil, "", e
1051 }
1052 it.Response = resp
1053 return resp.GetDataPolicies(), resp.GetNextPageToken(), nil
1054 }
1055
1056 fetch := func(pageSize int, pageToken string) (string, error) {
1057 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1058 if err != nil {
1059 return "", err
1060 }
1061 it.items = append(it.items, items...)
1062 return nextPageToken, nil
1063 }
1064
1065 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1066 it.pageInfo.MaxSize = int(req.GetPageSize())
1067 it.pageInfo.Token = req.GetPageToken()
1068
1069 return it
1070 }
1071
1072 // GetIamPolicy gets the IAM policy for the specified data policy.
1073 func (c *dataPolicyRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1074 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1075 jsonReq, err := m.Marshal(req)
1076 if err != nil {
1077 return nil, err
1078 }
1079
1080 baseUrl, err := url.Parse(c.endpoint)
1081 if err != nil {
1082 return nil, err
1083 }
1084 baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
1085
1086 params := url.Values{}
1087 params.Add("$alt", "json;enum-encoding=int")
1088
1089 baseUrl.RawQuery = params.Encode()
1090
1091 // Build HTTP headers from client and context metadata.
1092 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1093
1094 hds = append(c.xGoogHeaders, hds...)
1095 hds = append(hds, "Content-Type", "application/json")
1096 headers := gax.BuildHeaders(ctx, hds...)
1097 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1098 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1099 resp := &iampb.Policy{}
1100 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1101 if settings.Path != "" {
1102 baseUrl.Path = settings.Path
1103 }
1104 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1105 if err != nil {
1106 return err
1107 }
1108 httpReq = httpReq.WithContext(ctx)
1109 httpReq.Header = headers
1110
1111 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
1112 if err != nil {
1113 return err
1114 }
1115
1116 if err := unm.Unmarshal(buf, resp); err != nil {
1117 return err
1118 }
1119
1120 return nil
1121 }, opts...)
1122 if e != nil {
1123 return nil, e
1124 }
1125 return resp, nil
1126 }
1127
1128 // SetIamPolicy sets the IAM policy for the specified data policy.
1129 func (c *dataPolicyRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1130 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1131 jsonReq, err := m.Marshal(req)
1132 if err != nil {
1133 return nil, err
1134 }
1135
1136 baseUrl, err := url.Parse(c.endpoint)
1137 if err != nil {
1138 return nil, err
1139 }
1140 baseUrl.Path += fmt.Sprintf("/v1/%v:setIamPolicy", req.GetResource())
1141
1142 params := url.Values{}
1143 params.Add("$alt", "json;enum-encoding=int")
1144
1145 baseUrl.RawQuery = params.Encode()
1146
1147 // Build HTTP headers from client and context metadata.
1148 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1149
1150 hds = append(c.xGoogHeaders, hds...)
1151 hds = append(hds, "Content-Type", "application/json")
1152 headers := gax.BuildHeaders(ctx, hds...)
1153 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1154 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1155 resp := &iampb.Policy{}
1156 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1157 if settings.Path != "" {
1158 baseUrl.Path = settings.Path
1159 }
1160 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1161 if err != nil {
1162 return err
1163 }
1164 httpReq = httpReq.WithContext(ctx)
1165 httpReq.Header = headers
1166
1167 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
1168 if err != nil {
1169 return err
1170 }
1171
1172 if err := unm.Unmarshal(buf, resp); err != nil {
1173 return err
1174 }
1175
1176 return nil
1177 }, opts...)
1178 if e != nil {
1179 return nil, e
1180 }
1181 return resp, nil
1182 }
1183
1184 // TestIamPermissions returns the caller’s permission on the specified data policy resource.
1185 func (c *dataPolicyRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1186 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1187 jsonReq, err := m.Marshal(req)
1188 if err != nil {
1189 return nil, err
1190 }
1191
1192 baseUrl, err := url.Parse(c.endpoint)
1193 if err != nil {
1194 return nil, err
1195 }
1196 baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
1197
1198 params := url.Values{}
1199 params.Add("$alt", "json;enum-encoding=int")
1200
1201 baseUrl.RawQuery = params.Encode()
1202
1203 // Build HTTP headers from client and context metadata.
1204 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1205
1206 hds = append(c.xGoogHeaders, hds...)
1207 hds = append(hds, "Content-Type", "application/json")
1208 headers := gax.BuildHeaders(ctx, hds...)
1209 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1210 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1211 resp := &iampb.TestIamPermissionsResponse{}
1212 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1213 if settings.Path != "" {
1214 baseUrl.Path = settings.Path
1215 }
1216 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1217 if err != nil {
1218 return err
1219 }
1220 httpReq = httpReq.WithContext(ctx)
1221 httpReq.Header = headers
1222
1223 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
1224 if err != nil {
1225 return err
1226 }
1227
1228 if err := unm.Unmarshal(buf, resp); err != nil {
1229 return err
1230 }
1231
1232 return nil
1233 }, opts...)
1234 if e != nil {
1235 return nil, e
1236 }
1237 return resp, nil
1238 }