...

Source file src/cloud.google.com/go/kms/apiv1/ekm_client_example_test.go

Documentation: cloud.google.com/go/kms/apiv1

     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 kms_test
    18  
    19  import (
    20  	"context"
    21  
    22  	iampb "cloud.google.com/go/iam/apiv1/iampb"
    23  	kms "cloud.google.com/go/kms/apiv1"
    24  	kmspb "cloud.google.com/go/kms/apiv1/kmspb"
    25  	longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
    26  	"google.golang.org/api/iterator"
    27  	locationpb "google.golang.org/genproto/googleapis/cloud/location"
    28  )
    29  
    30  func ExampleNewEkmClient() {
    31  	ctx := context.Background()
    32  	// This snippet has been automatically generated and should be regarded as a code template only.
    33  	// It will require modifications to work:
    34  	// - It may require correct/in-range values for request initialization.
    35  	// - It may require specifying regional endpoints when creating the service client as shown in:
    36  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    37  	c, err := kms.NewEkmClient(ctx)
    38  	if err != nil {
    39  		// TODO: Handle error.
    40  	}
    41  	defer c.Close()
    42  
    43  	// TODO: Use client.
    44  	_ = c
    45  }
    46  
    47  func ExampleNewEkmRESTClient() {
    48  	ctx := context.Background()
    49  	// This snippet has been automatically generated and should be regarded as a code template only.
    50  	// It will require modifications to work:
    51  	// - It may require correct/in-range values for request initialization.
    52  	// - It may require specifying regional endpoints when creating the service client as shown in:
    53  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    54  	c, err := kms.NewEkmRESTClient(ctx)
    55  	if err != nil {
    56  		// TODO: Handle error.
    57  	}
    58  	defer c.Close()
    59  
    60  	// TODO: Use client.
    61  	_ = c
    62  }
    63  
    64  func ExampleEkmClient_CreateEkmConnection() {
    65  	ctx := context.Background()
    66  	// This snippet has been automatically generated and should be regarded as a code template only.
    67  	// It will require modifications to work:
    68  	// - It may require correct/in-range values for request initialization.
    69  	// - It may require specifying regional endpoints when creating the service client as shown in:
    70  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    71  	c, err := kms.NewEkmClient(ctx)
    72  	if err != nil {
    73  		// TODO: Handle error.
    74  	}
    75  	defer c.Close()
    76  
    77  	req := &kmspb.CreateEkmConnectionRequest{
    78  		// TODO: Fill request struct fields.
    79  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#CreateEkmConnectionRequest.
    80  	}
    81  	resp, err := c.CreateEkmConnection(ctx, req)
    82  	if err != nil {
    83  		// TODO: Handle error.
    84  	}
    85  	// TODO: Use resp.
    86  	_ = resp
    87  }
    88  
    89  func ExampleEkmClient_GetEkmConfig() {
    90  	ctx := context.Background()
    91  	// This snippet has been automatically generated and should be regarded as a code template only.
    92  	// It will require modifications to work:
    93  	// - It may require correct/in-range values for request initialization.
    94  	// - It may require specifying regional endpoints when creating the service client as shown in:
    95  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    96  	c, err := kms.NewEkmClient(ctx)
    97  	if err != nil {
    98  		// TODO: Handle error.
    99  	}
   100  	defer c.Close()
   101  
   102  	req := &kmspb.GetEkmConfigRequest{
   103  		// TODO: Fill request struct fields.
   104  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#GetEkmConfigRequest.
   105  	}
   106  	resp, err := c.GetEkmConfig(ctx, req)
   107  	if err != nil {
   108  		// TODO: Handle error.
   109  	}
   110  	// TODO: Use resp.
   111  	_ = resp
   112  }
   113  
   114  func ExampleEkmClient_GetEkmConnection() {
   115  	ctx := context.Background()
   116  	// This snippet has been automatically generated and should be regarded as a code template only.
   117  	// It will require modifications to work:
   118  	// - It may require correct/in-range values for request initialization.
   119  	// - It may require specifying regional endpoints when creating the service client as shown in:
   120  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   121  	c, err := kms.NewEkmClient(ctx)
   122  	if err != nil {
   123  		// TODO: Handle error.
   124  	}
   125  	defer c.Close()
   126  
   127  	req := &kmspb.GetEkmConnectionRequest{
   128  		// TODO: Fill request struct fields.
   129  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#GetEkmConnectionRequest.
   130  	}
   131  	resp, err := c.GetEkmConnection(ctx, req)
   132  	if err != nil {
   133  		// TODO: Handle error.
   134  	}
   135  	// TODO: Use resp.
   136  	_ = resp
   137  }
   138  
   139  func ExampleEkmClient_ListEkmConnections() {
   140  	ctx := context.Background()
   141  	// This snippet has been automatically generated and should be regarded as a code template only.
   142  	// It will require modifications to work:
   143  	// - It may require correct/in-range values for request initialization.
   144  	// - It may require specifying regional endpoints when creating the service client as shown in:
   145  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   146  	c, err := kms.NewEkmClient(ctx)
   147  	if err != nil {
   148  		// TODO: Handle error.
   149  	}
   150  	defer c.Close()
   151  
   152  	req := &kmspb.ListEkmConnectionsRequest{
   153  		// TODO: Fill request struct fields.
   154  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#ListEkmConnectionsRequest.
   155  	}
   156  	it := c.ListEkmConnections(ctx, req)
   157  	for {
   158  		resp, err := it.Next()
   159  		if err == iterator.Done {
   160  			break
   161  		}
   162  		if err != nil {
   163  			// TODO: Handle error.
   164  		}
   165  		// TODO: Use resp.
   166  		_ = resp
   167  
   168  		// If you need to access the underlying RPC response,
   169  		// you can do so by casting the `Response` as below.
   170  		// Otherwise, remove this line. Only populated after
   171  		// first call to Next(). Not safe for concurrent access.
   172  		_ = it.Response.(*kmspb.ListEkmConnectionsResponse)
   173  	}
   174  }
   175  
   176  func ExampleEkmClient_UpdateEkmConfig() {
   177  	ctx := context.Background()
   178  	// This snippet has been automatically generated and should be regarded as a code template only.
   179  	// It will require modifications to work:
   180  	// - It may require correct/in-range values for request initialization.
   181  	// - It may require specifying regional endpoints when creating the service client as shown in:
   182  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   183  	c, err := kms.NewEkmClient(ctx)
   184  	if err != nil {
   185  		// TODO: Handle error.
   186  	}
   187  	defer c.Close()
   188  
   189  	req := &kmspb.UpdateEkmConfigRequest{
   190  		// TODO: Fill request struct fields.
   191  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#UpdateEkmConfigRequest.
   192  	}
   193  	resp, err := c.UpdateEkmConfig(ctx, req)
   194  	if err != nil {
   195  		// TODO: Handle error.
   196  	}
   197  	// TODO: Use resp.
   198  	_ = resp
   199  }
   200  
   201  func ExampleEkmClient_UpdateEkmConnection() {
   202  	ctx := context.Background()
   203  	// This snippet has been automatically generated and should be regarded as a code template only.
   204  	// It will require modifications to work:
   205  	// - It may require correct/in-range values for request initialization.
   206  	// - It may require specifying regional endpoints when creating the service client as shown in:
   207  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   208  	c, err := kms.NewEkmClient(ctx)
   209  	if err != nil {
   210  		// TODO: Handle error.
   211  	}
   212  	defer c.Close()
   213  
   214  	req := &kmspb.UpdateEkmConnectionRequest{
   215  		// TODO: Fill request struct fields.
   216  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#UpdateEkmConnectionRequest.
   217  	}
   218  	resp, err := c.UpdateEkmConnection(ctx, req)
   219  	if err != nil {
   220  		// TODO: Handle error.
   221  	}
   222  	// TODO: Use resp.
   223  	_ = resp
   224  }
   225  
   226  func ExampleEkmClient_VerifyConnectivity() {
   227  	ctx := context.Background()
   228  	// This snippet has been automatically generated and should be regarded as a code template only.
   229  	// It will require modifications to work:
   230  	// - It may require correct/in-range values for request initialization.
   231  	// - It may require specifying regional endpoints when creating the service client as shown in:
   232  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   233  	c, err := kms.NewEkmClient(ctx)
   234  	if err != nil {
   235  		// TODO: Handle error.
   236  	}
   237  	defer c.Close()
   238  
   239  	req := &kmspb.VerifyConnectivityRequest{
   240  		// TODO: Fill request struct fields.
   241  		// See https://pkg.go.dev/cloud.google.com/go/kms/apiv1/kmspb#VerifyConnectivityRequest.
   242  	}
   243  	resp, err := c.VerifyConnectivity(ctx, req)
   244  	if err != nil {
   245  		// TODO: Handle error.
   246  	}
   247  	// TODO: Use resp.
   248  	_ = resp
   249  }
   250  
   251  func ExampleEkmClient_GetLocation() {
   252  	ctx := context.Background()
   253  	// This snippet has been automatically generated and should be regarded as a code template only.
   254  	// It will require modifications to work:
   255  	// - It may require correct/in-range values for request initialization.
   256  	// - It may require specifying regional endpoints when creating the service client as shown in:
   257  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   258  	c, err := kms.NewEkmClient(ctx)
   259  	if err != nil {
   260  		// TODO: Handle error.
   261  	}
   262  	defer c.Close()
   263  
   264  	req := &locationpb.GetLocationRequest{
   265  		// TODO: Fill request struct fields.
   266  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.
   267  	}
   268  	resp, err := c.GetLocation(ctx, req)
   269  	if err != nil {
   270  		// TODO: Handle error.
   271  	}
   272  	// TODO: Use resp.
   273  	_ = resp
   274  }
   275  
   276  func ExampleEkmClient_ListLocations() {
   277  	ctx := context.Background()
   278  	// This snippet has been automatically generated and should be regarded as a code template only.
   279  	// It will require modifications to work:
   280  	// - It may require correct/in-range values for request initialization.
   281  	// - It may require specifying regional endpoints when creating the service client as shown in:
   282  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   283  	c, err := kms.NewEkmClient(ctx)
   284  	if err != nil {
   285  		// TODO: Handle error.
   286  	}
   287  	defer c.Close()
   288  
   289  	req := &locationpb.ListLocationsRequest{
   290  		// TODO: Fill request struct fields.
   291  		// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.
   292  	}
   293  	it := c.ListLocations(ctx, req)
   294  	for {
   295  		resp, err := it.Next()
   296  		if err == iterator.Done {
   297  			break
   298  		}
   299  		if err != nil {
   300  			// TODO: Handle error.
   301  		}
   302  		// TODO: Use resp.
   303  		_ = resp
   304  
   305  		// If you need to access the underlying RPC response,
   306  		// you can do so by casting the `Response` as below.
   307  		// Otherwise, remove this line. Only populated after
   308  		// first call to Next(). Not safe for concurrent access.
   309  		_ = it.Response.(*locationpb.ListLocationsResponse)
   310  	}
   311  }
   312  
   313  func ExampleEkmClient_GetIamPolicy() {
   314  	ctx := context.Background()
   315  	// This snippet has been automatically generated and should be regarded as a code template only.
   316  	// It will require modifications to work:
   317  	// - It may require correct/in-range values for request initialization.
   318  	// - It may require specifying regional endpoints when creating the service client as shown in:
   319  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   320  	c, err := kms.NewEkmClient(ctx)
   321  	if err != nil {
   322  		// TODO: Handle error.
   323  	}
   324  	defer c.Close()
   325  
   326  	req := &iampb.GetIamPolicyRequest{
   327  		// TODO: Fill request struct fields.
   328  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
   329  	}
   330  	resp, err := c.GetIamPolicy(ctx, req)
   331  	if err != nil {
   332  		// TODO: Handle error.
   333  	}
   334  	// TODO: Use resp.
   335  	_ = resp
   336  }
   337  
   338  func ExampleEkmClient_SetIamPolicy() {
   339  	ctx := context.Background()
   340  	// This snippet has been automatically generated and should be regarded as a code template only.
   341  	// It will require modifications to work:
   342  	// - It may require correct/in-range values for request initialization.
   343  	// - It may require specifying regional endpoints when creating the service client as shown in:
   344  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   345  	c, err := kms.NewEkmClient(ctx)
   346  	if err != nil {
   347  		// TODO: Handle error.
   348  	}
   349  	defer c.Close()
   350  
   351  	req := &iampb.SetIamPolicyRequest{
   352  		// TODO: Fill request struct fields.
   353  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
   354  	}
   355  	resp, err := c.SetIamPolicy(ctx, req)
   356  	if err != nil {
   357  		// TODO: Handle error.
   358  	}
   359  	// TODO: Use resp.
   360  	_ = resp
   361  }
   362  
   363  func ExampleEkmClient_TestIamPermissions() {
   364  	ctx := context.Background()
   365  	// This snippet has been automatically generated and should be regarded as a code template only.
   366  	// It will require modifications to work:
   367  	// - It may require correct/in-range values for request initialization.
   368  	// - It may require specifying regional endpoints when creating the service client as shown in:
   369  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   370  	c, err := kms.NewEkmClient(ctx)
   371  	if err != nil {
   372  		// TODO: Handle error.
   373  	}
   374  	defer c.Close()
   375  
   376  	req := &iampb.TestIamPermissionsRequest{
   377  		// TODO: Fill request struct fields.
   378  		// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
   379  	}
   380  	resp, err := c.TestIamPermissions(ctx, req)
   381  	if err != nil {
   382  		// TODO: Handle error.
   383  	}
   384  	// TODO: Use resp.
   385  	_ = resp
   386  }
   387  
   388  func ExampleEkmClient_GetOperation() {
   389  	ctx := context.Background()
   390  	// This snippet has been automatically generated and should be regarded as a code template only.
   391  	// It will require modifications to work:
   392  	// - It may require correct/in-range values for request initialization.
   393  	// - It may require specifying regional endpoints when creating the service client as shown in:
   394  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   395  	c, err := kms.NewEkmClient(ctx)
   396  	if err != nil {
   397  		// TODO: Handle error.
   398  	}
   399  	defer c.Close()
   400  
   401  	req := &longrunningpb.GetOperationRequest{
   402  		// TODO: Fill request struct fields.
   403  		// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
   404  	}
   405  	resp, err := c.GetOperation(ctx, req)
   406  	if err != nil {
   407  		// TODO: Handle error.
   408  	}
   409  	// TODO: Use resp.
   410  	_ = resp
   411  }
   412  

View as plain text