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