1 // Copyright 2024 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 secretmanager_test 18 19 import ( 20 "context" 21 22 iampb "cloud.google.com/go/iam/apiv1/iampb" 23 secretmanager "cloud.google.com/go/secretmanager/apiv1beta2" 24 secretmanagerpb "cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb" 25 "google.golang.org/api/iterator" 26 locationpb "google.golang.org/genproto/googleapis/cloud/location" 27 ) 28 29 func ExampleNewClient() { 30 ctx := context.Background() 31 // This snippet has been automatically generated and should be regarded as a code template only. 32 // It will require modifications to work: 33 // - It may require correct/in-range values for request initialization. 34 // - It may require specifying regional endpoints when creating the service client as shown in: 35 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 36 c, err := secretmanager.NewClient(ctx) 37 if err != nil { 38 // TODO: Handle error. 39 } 40 defer c.Close() 41 42 // TODO: Use client. 43 _ = c 44 } 45 46 func ExampleNewRESTClient() { 47 ctx := context.Background() 48 // This snippet has been automatically generated and should be regarded as a code template only. 49 // It will require modifications to work: 50 // - It may require correct/in-range values for request initialization. 51 // - It may require specifying regional endpoints when creating the service client as shown in: 52 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 53 c, err := secretmanager.NewRESTClient(ctx) 54 if err != nil { 55 // TODO: Handle error. 56 } 57 defer c.Close() 58 59 // TODO: Use client. 60 _ = c 61 } 62 63 func ExampleClient_AccessSecretVersion() { 64 ctx := context.Background() 65 // This snippet has been automatically generated and should be regarded as a code template only. 66 // It will require modifications to work: 67 // - It may require correct/in-range values for request initialization. 68 // - It may require specifying regional endpoints when creating the service client as shown in: 69 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 70 c, err := secretmanager.NewClient(ctx) 71 if err != nil { 72 // TODO: Handle error. 73 } 74 defer c.Close() 75 76 req := &secretmanagerpb.AccessSecretVersionRequest{ 77 // TODO: Fill request struct fields. 78 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#AccessSecretVersionRequest. 79 } 80 resp, err := c.AccessSecretVersion(ctx, req) 81 if err != nil { 82 // TODO: Handle error. 83 } 84 // TODO: Use resp. 85 _ = resp 86 } 87 88 func ExampleClient_AddSecretVersion() { 89 ctx := context.Background() 90 // This snippet has been automatically generated and should be regarded as a code template only. 91 // It will require modifications to work: 92 // - It may require correct/in-range values for request initialization. 93 // - It may require specifying regional endpoints when creating the service client as shown in: 94 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 95 c, err := secretmanager.NewClient(ctx) 96 if err != nil { 97 // TODO: Handle error. 98 } 99 defer c.Close() 100 101 req := &secretmanagerpb.AddSecretVersionRequest{ 102 // TODO: Fill request struct fields. 103 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#AddSecretVersionRequest. 104 } 105 resp, err := c.AddSecretVersion(ctx, req) 106 if err != nil { 107 // TODO: Handle error. 108 } 109 // TODO: Use resp. 110 _ = resp 111 } 112 113 func ExampleClient_CreateSecret() { 114 ctx := context.Background() 115 // This snippet has been automatically generated and should be regarded as a code template only. 116 // It will require modifications to work: 117 // - It may require correct/in-range values for request initialization. 118 // - It may require specifying regional endpoints when creating the service client as shown in: 119 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 120 c, err := secretmanager.NewClient(ctx) 121 if err != nil { 122 // TODO: Handle error. 123 } 124 defer c.Close() 125 126 req := &secretmanagerpb.CreateSecretRequest{ 127 // TODO: Fill request struct fields. 128 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#CreateSecretRequest. 129 } 130 resp, err := c.CreateSecret(ctx, req) 131 if err != nil { 132 // TODO: Handle error. 133 } 134 // TODO: Use resp. 135 _ = resp 136 } 137 138 func ExampleClient_DeleteSecret() { 139 ctx := context.Background() 140 // This snippet has been automatically generated and should be regarded as a code template only. 141 // It will require modifications to work: 142 // - It may require correct/in-range values for request initialization. 143 // - It may require specifying regional endpoints when creating the service client as shown in: 144 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 145 c, err := secretmanager.NewClient(ctx) 146 if err != nil { 147 // TODO: Handle error. 148 } 149 defer c.Close() 150 151 req := &secretmanagerpb.DeleteSecretRequest{ 152 // TODO: Fill request struct fields. 153 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#DeleteSecretRequest. 154 } 155 err = c.DeleteSecret(ctx, req) 156 if err != nil { 157 // TODO: Handle error. 158 } 159 } 160 161 func ExampleClient_DestroySecretVersion() { 162 ctx := context.Background() 163 // This snippet has been automatically generated and should be regarded as a code template only. 164 // It will require modifications to work: 165 // - It may require correct/in-range values for request initialization. 166 // - It may require specifying regional endpoints when creating the service client as shown in: 167 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 168 c, err := secretmanager.NewClient(ctx) 169 if err != nil { 170 // TODO: Handle error. 171 } 172 defer c.Close() 173 174 req := &secretmanagerpb.DestroySecretVersionRequest{ 175 // TODO: Fill request struct fields. 176 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#DestroySecretVersionRequest. 177 } 178 resp, err := c.DestroySecretVersion(ctx, req) 179 if err != nil { 180 // TODO: Handle error. 181 } 182 // TODO: Use resp. 183 _ = resp 184 } 185 186 func ExampleClient_DisableSecretVersion() { 187 ctx := context.Background() 188 // This snippet has been automatically generated and should be regarded as a code template only. 189 // It will require modifications to work: 190 // - It may require correct/in-range values for request initialization. 191 // - It may require specifying regional endpoints when creating the service client as shown in: 192 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 193 c, err := secretmanager.NewClient(ctx) 194 if err != nil { 195 // TODO: Handle error. 196 } 197 defer c.Close() 198 199 req := &secretmanagerpb.DisableSecretVersionRequest{ 200 // TODO: Fill request struct fields. 201 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#DisableSecretVersionRequest. 202 } 203 resp, err := c.DisableSecretVersion(ctx, req) 204 if err != nil { 205 // TODO: Handle error. 206 } 207 // TODO: Use resp. 208 _ = resp 209 } 210 211 func ExampleClient_EnableSecretVersion() { 212 ctx := context.Background() 213 // This snippet has been automatically generated and should be regarded as a code template only. 214 // It will require modifications to work: 215 // - It may require correct/in-range values for request initialization. 216 // - It may require specifying regional endpoints when creating the service client as shown in: 217 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 218 c, err := secretmanager.NewClient(ctx) 219 if err != nil { 220 // TODO: Handle error. 221 } 222 defer c.Close() 223 224 req := &secretmanagerpb.EnableSecretVersionRequest{ 225 // TODO: Fill request struct fields. 226 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#EnableSecretVersionRequest. 227 } 228 resp, err := c.EnableSecretVersion(ctx, req) 229 if err != nil { 230 // TODO: Handle error. 231 } 232 // TODO: Use resp. 233 _ = resp 234 } 235 236 func ExampleClient_GetIamPolicy() { 237 ctx := context.Background() 238 // This snippet has been automatically generated and should be regarded as a code template only. 239 // It will require modifications to work: 240 // - It may require correct/in-range values for request initialization. 241 // - It may require specifying regional endpoints when creating the service client as shown in: 242 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 243 c, err := secretmanager.NewClient(ctx) 244 if err != nil { 245 // TODO: Handle error. 246 } 247 defer c.Close() 248 249 req := &iampb.GetIamPolicyRequest{ 250 // TODO: Fill request struct fields. 251 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest. 252 } 253 resp, err := c.GetIamPolicy(ctx, req) 254 if err != nil { 255 // TODO: Handle error. 256 } 257 // TODO: Use resp. 258 _ = resp 259 } 260 261 func ExampleClient_GetSecret() { 262 ctx := context.Background() 263 // This snippet has been automatically generated and should be regarded as a code template only. 264 // It will require modifications to work: 265 // - It may require correct/in-range values for request initialization. 266 // - It may require specifying regional endpoints when creating the service client as shown in: 267 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 268 c, err := secretmanager.NewClient(ctx) 269 if err != nil { 270 // TODO: Handle error. 271 } 272 defer c.Close() 273 274 req := &secretmanagerpb.GetSecretRequest{ 275 // TODO: Fill request struct fields. 276 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#GetSecretRequest. 277 } 278 resp, err := c.GetSecret(ctx, req) 279 if err != nil { 280 // TODO: Handle error. 281 } 282 // TODO: Use resp. 283 _ = resp 284 } 285 286 func ExampleClient_GetSecretVersion() { 287 ctx := context.Background() 288 // This snippet has been automatically generated and should be regarded as a code template only. 289 // It will require modifications to work: 290 // - It may require correct/in-range values for request initialization. 291 // - It may require specifying regional endpoints when creating the service client as shown in: 292 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 293 c, err := secretmanager.NewClient(ctx) 294 if err != nil { 295 // TODO: Handle error. 296 } 297 defer c.Close() 298 299 req := &secretmanagerpb.GetSecretVersionRequest{ 300 // TODO: Fill request struct fields. 301 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#GetSecretVersionRequest. 302 } 303 resp, err := c.GetSecretVersion(ctx, req) 304 if err != nil { 305 // TODO: Handle error. 306 } 307 // TODO: Use resp. 308 _ = resp 309 } 310 311 func ExampleClient_ListSecretVersions() { 312 ctx := context.Background() 313 // This snippet has been automatically generated and should be regarded as a code template only. 314 // It will require modifications to work: 315 // - It may require correct/in-range values for request initialization. 316 // - It may require specifying regional endpoints when creating the service client as shown in: 317 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 318 c, err := secretmanager.NewClient(ctx) 319 if err != nil { 320 // TODO: Handle error. 321 } 322 defer c.Close() 323 324 req := &secretmanagerpb.ListSecretVersionsRequest{ 325 // TODO: Fill request struct fields. 326 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#ListSecretVersionsRequest. 327 } 328 it := c.ListSecretVersions(ctx, req) 329 for { 330 resp, err := it.Next() 331 if err == iterator.Done { 332 break 333 } 334 if err != nil { 335 // TODO: Handle error. 336 } 337 // TODO: Use resp. 338 _ = resp 339 340 // If you need to access the underlying RPC response, 341 // you can do so by casting the `Response` as below. 342 // Otherwise, remove this line. Only populated after 343 // first call to Next(). Not safe for concurrent access. 344 _ = it.Response.(*secretmanagerpb.ListSecretVersionsResponse) 345 } 346 } 347 348 func ExampleClient_ListSecrets() { 349 ctx := context.Background() 350 // This snippet has been automatically generated and should be regarded as a code template only. 351 // It will require modifications to work: 352 // - It may require correct/in-range values for request initialization. 353 // - It may require specifying regional endpoints when creating the service client as shown in: 354 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 355 c, err := secretmanager.NewClient(ctx) 356 if err != nil { 357 // TODO: Handle error. 358 } 359 defer c.Close() 360 361 req := &secretmanagerpb.ListSecretsRequest{ 362 // TODO: Fill request struct fields. 363 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#ListSecretsRequest. 364 } 365 it := c.ListSecrets(ctx, req) 366 for { 367 resp, err := it.Next() 368 if err == iterator.Done { 369 break 370 } 371 if err != nil { 372 // TODO: Handle error. 373 } 374 // TODO: Use resp. 375 _ = resp 376 377 // If you need to access the underlying RPC response, 378 // you can do so by casting the `Response` as below. 379 // Otherwise, remove this line. Only populated after 380 // first call to Next(). Not safe for concurrent access. 381 _ = it.Response.(*secretmanagerpb.ListSecretsResponse) 382 } 383 } 384 385 func ExampleClient_SetIamPolicy() { 386 ctx := context.Background() 387 // This snippet has been automatically generated and should be regarded as a code template only. 388 // It will require modifications to work: 389 // - It may require correct/in-range values for request initialization. 390 // - It may require specifying regional endpoints when creating the service client as shown in: 391 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 392 c, err := secretmanager.NewClient(ctx) 393 if err != nil { 394 // TODO: Handle error. 395 } 396 defer c.Close() 397 398 req := &iampb.SetIamPolicyRequest{ 399 // TODO: Fill request struct fields. 400 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest. 401 } 402 resp, err := c.SetIamPolicy(ctx, req) 403 if err != nil { 404 // TODO: Handle error. 405 } 406 // TODO: Use resp. 407 _ = resp 408 } 409 410 func ExampleClient_TestIamPermissions() { 411 ctx := context.Background() 412 // This snippet has been automatically generated and should be regarded as a code template only. 413 // It will require modifications to work: 414 // - It may require correct/in-range values for request initialization. 415 // - It may require specifying regional endpoints when creating the service client as shown in: 416 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 417 c, err := secretmanager.NewClient(ctx) 418 if err != nil { 419 // TODO: Handle error. 420 } 421 defer c.Close() 422 423 req := &iampb.TestIamPermissionsRequest{ 424 // TODO: Fill request struct fields. 425 // See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest. 426 } 427 resp, err := c.TestIamPermissions(ctx, req) 428 if err != nil { 429 // TODO: Handle error. 430 } 431 // TODO: Use resp. 432 _ = resp 433 } 434 435 func ExampleClient_UpdateSecret() { 436 ctx := context.Background() 437 // This snippet has been automatically generated and should be regarded as a code template only. 438 // It will require modifications to work: 439 // - It may require correct/in-range values for request initialization. 440 // - It may require specifying regional endpoints when creating the service client as shown in: 441 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 442 c, err := secretmanager.NewClient(ctx) 443 if err != nil { 444 // TODO: Handle error. 445 } 446 defer c.Close() 447 448 req := &secretmanagerpb.UpdateSecretRequest{ 449 // TODO: Fill request struct fields. 450 // See https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1beta2/secretmanagerpb#UpdateSecretRequest. 451 } 452 resp, err := c.UpdateSecret(ctx, req) 453 if err != nil { 454 // TODO: Handle error. 455 } 456 // TODO: Use resp. 457 _ = resp 458 } 459 460 func ExampleClient_GetLocation() { 461 ctx := context.Background() 462 // This snippet has been automatically generated and should be regarded as a code template only. 463 // It will require modifications to work: 464 // - It may require correct/in-range values for request initialization. 465 // - It may require specifying regional endpoints when creating the service client as shown in: 466 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 467 c, err := secretmanager.NewClient(ctx) 468 if err != nil { 469 // TODO: Handle error. 470 } 471 defer c.Close() 472 473 req := &locationpb.GetLocationRequest{ 474 // TODO: Fill request struct fields. 475 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest. 476 } 477 resp, err := c.GetLocation(ctx, req) 478 if err != nil { 479 // TODO: Handle error. 480 } 481 // TODO: Use resp. 482 _ = resp 483 } 484 485 func ExampleClient_ListLocations() { 486 ctx := context.Background() 487 // This snippet has been automatically generated and should be regarded as a code template only. 488 // It will require modifications to work: 489 // - It may require correct/in-range values for request initialization. 490 // - It may require specifying regional endpoints when creating the service client as shown in: 491 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 492 c, err := secretmanager.NewClient(ctx) 493 if err != nil { 494 // TODO: Handle error. 495 } 496 defer c.Close() 497 498 req := &locationpb.ListLocationsRequest{ 499 // TODO: Fill request struct fields. 500 // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest. 501 } 502 it := c.ListLocations(ctx, req) 503 for { 504 resp, err := it.Next() 505 if err == iterator.Done { 506 break 507 } 508 if err != nil { 509 // TODO: Handle error. 510 } 511 // TODO: Use resp. 512 _ = resp 513 514 // If you need to access the underlying RPC response, 515 // you can do so by casting the `Response` as below. 516 // Otherwise, remove this line. Only populated after 517 // first call to Next(). Not safe for concurrent access. 518 _ = it.Response.(*locationpb.ListLocationsResponse) 519 } 520 } 521