...

Source file src/cloud.google.com/go/monitoring/apiv3/v2/notification_channel_client.go

Documentation: cloud.google.com/go/monitoring/apiv3/v2

     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 monitoring
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"math"
    23  	"net/url"
    24  	"time"
    25  
    26  	monitoringpb "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb"
    27  	gax "github.com/googleapis/gax-go/v2"
    28  	"google.golang.org/api/iterator"
    29  	"google.golang.org/api/option"
    30  	"google.golang.org/api/option/internaloption"
    31  	gtransport "google.golang.org/api/transport/grpc"
    32  	"google.golang.org/grpc"
    33  	"google.golang.org/grpc/codes"
    34  	"google.golang.org/protobuf/proto"
    35  )
    36  
    37  var newNotificationChannelClientHook clientHook
    38  
    39  // NotificationChannelCallOptions contains the retry settings for each method of NotificationChannelClient.
    40  type NotificationChannelCallOptions struct {
    41  	ListNotificationChannelDescriptors      []gax.CallOption
    42  	GetNotificationChannelDescriptor        []gax.CallOption
    43  	ListNotificationChannels                []gax.CallOption
    44  	GetNotificationChannel                  []gax.CallOption
    45  	CreateNotificationChannel               []gax.CallOption
    46  	UpdateNotificationChannel               []gax.CallOption
    47  	DeleteNotificationChannel               []gax.CallOption
    48  	SendNotificationChannelVerificationCode []gax.CallOption
    49  	GetNotificationChannelVerificationCode  []gax.CallOption
    50  	VerifyNotificationChannel               []gax.CallOption
    51  }
    52  
    53  func defaultNotificationChannelGRPCClientOptions() []option.ClientOption {
    54  	return []option.ClientOption{
    55  		internaloption.WithDefaultEndpoint("monitoring.googleapis.com:443"),
    56  		internaloption.WithDefaultEndpointTemplate("monitoring.UNIVERSE_DOMAIN:443"),
    57  		internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"),
    58  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    59  		internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"),
    60  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    61  		internaloption.EnableJwtWithScope(),
    62  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    63  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    64  	}
    65  }
    66  
    67  func defaultNotificationChannelCallOptions() *NotificationChannelCallOptions {
    68  	return &NotificationChannelCallOptions{
    69  		ListNotificationChannelDescriptors: []gax.CallOption{
    70  			gax.WithTimeout(30000 * time.Millisecond),
    71  			gax.WithRetry(func() gax.Retryer {
    72  				return gax.OnCodes([]codes.Code{
    73  					codes.Unavailable,
    74  				}, gax.Backoff{
    75  					Initial:    100 * time.Millisecond,
    76  					Max:        30000 * time.Millisecond,
    77  					Multiplier: 1.30,
    78  				})
    79  			}),
    80  		},
    81  		GetNotificationChannelDescriptor: []gax.CallOption{
    82  			gax.WithTimeout(30000 * time.Millisecond),
    83  			gax.WithRetry(func() gax.Retryer {
    84  				return gax.OnCodes([]codes.Code{
    85  					codes.Unavailable,
    86  				}, gax.Backoff{
    87  					Initial:    100 * time.Millisecond,
    88  					Max:        30000 * time.Millisecond,
    89  					Multiplier: 1.30,
    90  				})
    91  			}),
    92  		},
    93  		ListNotificationChannels: []gax.CallOption{
    94  			gax.WithTimeout(30000 * time.Millisecond),
    95  			gax.WithRetry(func() gax.Retryer {
    96  				return gax.OnCodes([]codes.Code{
    97  					codes.Unavailable,
    98  				}, gax.Backoff{
    99  					Initial:    100 * time.Millisecond,
   100  					Max:        30000 * time.Millisecond,
   101  					Multiplier: 1.30,
   102  				})
   103  			}),
   104  		},
   105  		GetNotificationChannel: []gax.CallOption{
   106  			gax.WithTimeout(30000 * time.Millisecond),
   107  			gax.WithRetry(func() gax.Retryer {
   108  				return gax.OnCodes([]codes.Code{
   109  					codes.Unavailable,
   110  				}, gax.Backoff{
   111  					Initial:    100 * time.Millisecond,
   112  					Max:        30000 * time.Millisecond,
   113  					Multiplier: 1.30,
   114  				})
   115  			}),
   116  		},
   117  		CreateNotificationChannel: []gax.CallOption{
   118  			gax.WithTimeout(30000 * time.Millisecond),
   119  		},
   120  		UpdateNotificationChannel: []gax.CallOption{
   121  			gax.WithTimeout(30000 * time.Millisecond),
   122  		},
   123  		DeleteNotificationChannel: []gax.CallOption{
   124  			gax.WithTimeout(30000 * time.Millisecond),
   125  			gax.WithRetry(func() gax.Retryer {
   126  				return gax.OnCodes([]codes.Code{
   127  					codes.Unavailable,
   128  				}, gax.Backoff{
   129  					Initial:    100 * time.Millisecond,
   130  					Max:        30000 * time.Millisecond,
   131  					Multiplier: 1.30,
   132  				})
   133  			}),
   134  		},
   135  		SendNotificationChannelVerificationCode: []gax.CallOption{
   136  			gax.WithTimeout(30000 * time.Millisecond),
   137  		},
   138  		GetNotificationChannelVerificationCode: []gax.CallOption{
   139  			gax.WithTimeout(30000 * time.Millisecond),
   140  			gax.WithRetry(func() gax.Retryer {
   141  				return gax.OnCodes([]codes.Code{
   142  					codes.Unavailable,
   143  				}, gax.Backoff{
   144  					Initial:    100 * time.Millisecond,
   145  					Max:        30000 * time.Millisecond,
   146  					Multiplier: 1.30,
   147  				})
   148  			}),
   149  		},
   150  		VerifyNotificationChannel: []gax.CallOption{
   151  			gax.WithTimeout(30000 * time.Millisecond),
   152  			gax.WithRetry(func() gax.Retryer {
   153  				return gax.OnCodes([]codes.Code{
   154  					codes.Unavailable,
   155  				}, gax.Backoff{
   156  					Initial:    100 * time.Millisecond,
   157  					Max:        30000 * time.Millisecond,
   158  					Multiplier: 1.30,
   159  				})
   160  			}),
   161  		},
   162  	}
   163  }
   164  
   165  // internalNotificationChannelClient is an interface that defines the methods available from Cloud Monitoring API.
   166  type internalNotificationChannelClient interface {
   167  	Close() error
   168  	setGoogleClientInfo(...string)
   169  	Connection() *grpc.ClientConn
   170  	ListNotificationChannelDescriptors(context.Context, *monitoringpb.ListNotificationChannelDescriptorsRequest, ...gax.CallOption) *NotificationChannelDescriptorIterator
   171  	GetNotificationChannelDescriptor(context.Context, *monitoringpb.GetNotificationChannelDescriptorRequest, ...gax.CallOption) (*monitoringpb.NotificationChannelDescriptor, error)
   172  	ListNotificationChannels(context.Context, *monitoringpb.ListNotificationChannelsRequest, ...gax.CallOption) *NotificationChannelIterator
   173  	GetNotificationChannel(context.Context, *monitoringpb.GetNotificationChannelRequest, ...gax.CallOption) (*monitoringpb.NotificationChannel, error)
   174  	CreateNotificationChannel(context.Context, *monitoringpb.CreateNotificationChannelRequest, ...gax.CallOption) (*monitoringpb.NotificationChannel, error)
   175  	UpdateNotificationChannel(context.Context, *monitoringpb.UpdateNotificationChannelRequest, ...gax.CallOption) (*monitoringpb.NotificationChannel, error)
   176  	DeleteNotificationChannel(context.Context, *monitoringpb.DeleteNotificationChannelRequest, ...gax.CallOption) error
   177  	SendNotificationChannelVerificationCode(context.Context, *monitoringpb.SendNotificationChannelVerificationCodeRequest, ...gax.CallOption) error
   178  	GetNotificationChannelVerificationCode(context.Context, *monitoringpb.GetNotificationChannelVerificationCodeRequest, ...gax.CallOption) (*monitoringpb.GetNotificationChannelVerificationCodeResponse, error)
   179  	VerifyNotificationChannel(context.Context, *monitoringpb.VerifyNotificationChannelRequest, ...gax.CallOption) (*monitoringpb.NotificationChannel, error)
   180  }
   181  
   182  // NotificationChannelClient is a client for interacting with Cloud Monitoring API.
   183  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   184  //
   185  // The Notification Channel API provides access to configuration that
   186  // controls how messages related to incidents are sent.
   187  type NotificationChannelClient struct {
   188  	// The internal transport-dependent client.
   189  	internalClient internalNotificationChannelClient
   190  
   191  	// The call options for this service.
   192  	CallOptions *NotificationChannelCallOptions
   193  }
   194  
   195  // Wrapper methods routed to the internal client.
   196  
   197  // Close closes the connection to the API service. The user should invoke this when
   198  // the client is no longer required.
   199  func (c *NotificationChannelClient) Close() error {
   200  	return c.internalClient.Close()
   201  }
   202  
   203  // setGoogleClientInfo sets the name and version of the application in
   204  // the `x-goog-api-client` header passed on each request. Intended for
   205  // use by Google-written clients.
   206  func (c *NotificationChannelClient) setGoogleClientInfo(keyval ...string) {
   207  	c.internalClient.setGoogleClientInfo(keyval...)
   208  }
   209  
   210  // Connection returns a connection to the API service.
   211  //
   212  // Deprecated: Connections are now pooled so this method does not always
   213  // return the same resource.
   214  func (c *NotificationChannelClient) Connection() *grpc.ClientConn {
   215  	return c.internalClient.Connection()
   216  }
   217  
   218  // ListNotificationChannelDescriptors lists the descriptors for supported channel types. The use of descriptors
   219  // makes it possible for new channel types to be dynamically added.
   220  func (c *NotificationChannelClient) ListNotificationChannelDescriptors(ctx context.Context, req *monitoringpb.ListNotificationChannelDescriptorsRequest, opts ...gax.CallOption) *NotificationChannelDescriptorIterator {
   221  	return c.internalClient.ListNotificationChannelDescriptors(ctx, req, opts...)
   222  }
   223  
   224  // GetNotificationChannelDescriptor gets a single channel descriptor. The descriptor indicates which fields
   225  // are expected / permitted for a notification channel of the given type.
   226  func (c *NotificationChannelClient) GetNotificationChannelDescriptor(ctx context.Context, req *monitoringpb.GetNotificationChannelDescriptorRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannelDescriptor, error) {
   227  	return c.internalClient.GetNotificationChannelDescriptor(ctx, req, opts...)
   228  }
   229  
   230  // ListNotificationChannels lists the notification channels that have been created for the project.
   231  // To list the types of notification channels that are supported, use
   232  // the ListNotificationChannelDescriptors method.
   233  func (c *NotificationChannelClient) ListNotificationChannels(ctx context.Context, req *monitoringpb.ListNotificationChannelsRequest, opts ...gax.CallOption) *NotificationChannelIterator {
   234  	return c.internalClient.ListNotificationChannels(ctx, req, opts...)
   235  }
   236  
   237  // GetNotificationChannel gets a single notification channel. The channel includes the relevant
   238  // configuration details with which the channel was created. However, the
   239  // response may truncate or omit passwords, API keys, or other private key
   240  // matter and thus the response may not be 100% identical to the information
   241  // that was supplied in the call to the create method.
   242  func (c *NotificationChannelClient) GetNotificationChannel(ctx context.Context, req *monitoringpb.GetNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   243  	return c.internalClient.GetNotificationChannel(ctx, req, opts...)
   244  }
   245  
   246  // CreateNotificationChannel creates a new notification channel, representing a single notification
   247  // endpoint such as an email address, SMS number, or PagerDuty service.
   248  //
   249  // Design your application to single-thread API calls that modify the state of
   250  // notification channels in a single project. This includes calls to
   251  // CreateNotificationChannel, DeleteNotificationChannel and
   252  // UpdateNotificationChannel.
   253  func (c *NotificationChannelClient) CreateNotificationChannel(ctx context.Context, req *monitoringpb.CreateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   254  	return c.internalClient.CreateNotificationChannel(ctx, req, opts...)
   255  }
   256  
   257  // UpdateNotificationChannel updates a notification channel. Fields not specified in the field mask
   258  // remain unchanged.
   259  //
   260  // Design your application to single-thread API calls that modify the state of
   261  // notification channels in a single project. This includes calls to
   262  // CreateNotificationChannel, DeleteNotificationChannel and
   263  // UpdateNotificationChannel.
   264  func (c *NotificationChannelClient) UpdateNotificationChannel(ctx context.Context, req *monitoringpb.UpdateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   265  	return c.internalClient.UpdateNotificationChannel(ctx, req, opts...)
   266  }
   267  
   268  // DeleteNotificationChannel deletes a notification channel.
   269  //
   270  // Design your application to single-thread API calls that modify the state of
   271  // notification channels in a single project. This includes calls to
   272  // CreateNotificationChannel, DeleteNotificationChannel and
   273  // UpdateNotificationChannel.
   274  func (c *NotificationChannelClient) DeleteNotificationChannel(ctx context.Context, req *monitoringpb.DeleteNotificationChannelRequest, opts ...gax.CallOption) error {
   275  	return c.internalClient.DeleteNotificationChannel(ctx, req, opts...)
   276  }
   277  
   278  // SendNotificationChannelVerificationCode causes a verification code to be delivered to the channel. The code
   279  // can then be supplied in VerifyNotificationChannel to verify the channel.
   280  func (c *NotificationChannelClient) SendNotificationChannelVerificationCode(ctx context.Context, req *monitoringpb.SendNotificationChannelVerificationCodeRequest, opts ...gax.CallOption) error {
   281  	return c.internalClient.SendNotificationChannelVerificationCode(ctx, req, opts...)
   282  }
   283  
   284  // GetNotificationChannelVerificationCode requests a verification code for an already verified channel that can then
   285  // be used in a call to VerifyNotificationChannel() on a different channel
   286  // with an equivalent identity in the same or in a different project. This
   287  // makes it possible to copy a channel between projects without requiring
   288  // manual reverification of the channel. If the channel is not in the
   289  // verified state, this method will fail (in other words, this may only be
   290  // used if the SendNotificationChannelVerificationCode and
   291  // VerifyNotificationChannel paths have already been used to put the given
   292  // channel into the verified state).
   293  //
   294  // There is no guarantee that the verification codes returned by this method
   295  // will be of a similar structure or form as the ones that are delivered
   296  // to the channel via SendNotificationChannelVerificationCode; while
   297  // VerifyNotificationChannel() will recognize both the codes delivered via
   298  // SendNotificationChannelVerificationCode() and returned from
   299  // GetNotificationChannelVerificationCode(), it is typically the case that
   300  // the verification codes delivered via
   301  // SendNotificationChannelVerificationCode() will be shorter and also
   302  // have a shorter expiration (e.g. codes such as “G-123456”) whereas
   303  // GetVerificationCode() will typically return a much longer, websafe base
   304  // 64 encoded string that has a longer expiration time.
   305  func (c *NotificationChannelClient) GetNotificationChannelVerificationCode(ctx context.Context, req *monitoringpb.GetNotificationChannelVerificationCodeRequest, opts ...gax.CallOption) (*monitoringpb.GetNotificationChannelVerificationCodeResponse, error) {
   306  	return c.internalClient.GetNotificationChannelVerificationCode(ctx, req, opts...)
   307  }
   308  
   309  // VerifyNotificationChannel verifies a NotificationChannel by proving receipt of the code
   310  // delivered to the channel as a result of calling
   311  // SendNotificationChannelVerificationCode.
   312  func (c *NotificationChannelClient) VerifyNotificationChannel(ctx context.Context, req *monitoringpb.VerifyNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   313  	return c.internalClient.VerifyNotificationChannel(ctx, req, opts...)
   314  }
   315  
   316  // notificationChannelGRPCClient is a client for interacting with Cloud Monitoring API over gRPC transport.
   317  //
   318  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   319  type notificationChannelGRPCClient struct {
   320  	// Connection pool of gRPC connections to the service.
   321  	connPool gtransport.ConnPool
   322  
   323  	// Points back to the CallOptions field of the containing NotificationChannelClient
   324  	CallOptions **NotificationChannelCallOptions
   325  
   326  	// The gRPC API client.
   327  	notificationChannelClient monitoringpb.NotificationChannelServiceClient
   328  
   329  	// The x-goog-* metadata to be sent with each request.
   330  	xGoogHeaders []string
   331  }
   332  
   333  // NewNotificationChannelClient creates a new notification channel service client based on gRPC.
   334  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   335  //
   336  // The Notification Channel API provides access to configuration that
   337  // controls how messages related to incidents are sent.
   338  func NewNotificationChannelClient(ctx context.Context, opts ...option.ClientOption) (*NotificationChannelClient, error) {
   339  	clientOpts := defaultNotificationChannelGRPCClientOptions()
   340  	if newNotificationChannelClientHook != nil {
   341  		hookOpts, err := newNotificationChannelClientHook(ctx, clientHookParams{})
   342  		if err != nil {
   343  			return nil, err
   344  		}
   345  		clientOpts = append(clientOpts, hookOpts...)
   346  	}
   347  
   348  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   349  	if err != nil {
   350  		return nil, err
   351  	}
   352  	client := NotificationChannelClient{CallOptions: defaultNotificationChannelCallOptions()}
   353  
   354  	c := &notificationChannelGRPCClient{
   355  		connPool:                  connPool,
   356  		notificationChannelClient: monitoringpb.NewNotificationChannelServiceClient(connPool),
   357  		CallOptions:               &client.CallOptions,
   358  	}
   359  	c.setGoogleClientInfo()
   360  
   361  	client.internalClient = c
   362  
   363  	return &client, nil
   364  }
   365  
   366  // Connection returns a connection to the API service.
   367  //
   368  // Deprecated: Connections are now pooled so this method does not always
   369  // return the same resource.
   370  func (c *notificationChannelGRPCClient) Connection() *grpc.ClientConn {
   371  	return c.connPool.Conn()
   372  }
   373  
   374  // setGoogleClientInfo sets the name and version of the application in
   375  // the `x-goog-api-client` header passed on each request. Intended for
   376  // use by Google-written clients.
   377  func (c *notificationChannelGRPCClient) setGoogleClientInfo(keyval ...string) {
   378  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   379  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   380  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   381  }
   382  
   383  // Close closes the connection to the API service. The user should invoke this when
   384  // the client is no longer required.
   385  func (c *notificationChannelGRPCClient) Close() error {
   386  	return c.connPool.Close()
   387  }
   388  
   389  func (c *notificationChannelGRPCClient) ListNotificationChannelDescriptors(ctx context.Context, req *monitoringpb.ListNotificationChannelDescriptorsRequest, opts ...gax.CallOption) *NotificationChannelDescriptorIterator {
   390  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   391  
   392  	hds = append(c.xGoogHeaders, hds...)
   393  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   394  	opts = append((*c.CallOptions).ListNotificationChannelDescriptors[0:len((*c.CallOptions).ListNotificationChannelDescriptors):len((*c.CallOptions).ListNotificationChannelDescriptors)], opts...)
   395  	it := &NotificationChannelDescriptorIterator{}
   396  	req = proto.Clone(req).(*monitoringpb.ListNotificationChannelDescriptorsRequest)
   397  	it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannelDescriptor, string, error) {
   398  		resp := &monitoringpb.ListNotificationChannelDescriptorsResponse{}
   399  		if pageToken != "" {
   400  			req.PageToken = pageToken
   401  		}
   402  		if pageSize > math.MaxInt32 {
   403  			req.PageSize = math.MaxInt32
   404  		} else if pageSize != 0 {
   405  			req.PageSize = int32(pageSize)
   406  		}
   407  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   408  			var err error
   409  			resp, err = c.notificationChannelClient.ListNotificationChannelDescriptors(ctx, req, settings.GRPC...)
   410  			return err
   411  		}, opts...)
   412  		if err != nil {
   413  			return nil, "", err
   414  		}
   415  
   416  		it.Response = resp
   417  		return resp.GetChannelDescriptors(), resp.GetNextPageToken(), nil
   418  	}
   419  	fetch := func(pageSize int, pageToken string) (string, error) {
   420  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   421  		if err != nil {
   422  			return "", err
   423  		}
   424  		it.items = append(it.items, items...)
   425  		return nextPageToken, nil
   426  	}
   427  
   428  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   429  	it.pageInfo.MaxSize = int(req.GetPageSize())
   430  	it.pageInfo.Token = req.GetPageToken()
   431  
   432  	return it
   433  }
   434  
   435  func (c *notificationChannelGRPCClient) GetNotificationChannelDescriptor(ctx context.Context, req *monitoringpb.GetNotificationChannelDescriptorRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannelDescriptor, error) {
   436  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   437  
   438  	hds = append(c.xGoogHeaders, hds...)
   439  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   440  	opts = append((*c.CallOptions).GetNotificationChannelDescriptor[0:len((*c.CallOptions).GetNotificationChannelDescriptor):len((*c.CallOptions).GetNotificationChannelDescriptor)], opts...)
   441  	var resp *monitoringpb.NotificationChannelDescriptor
   442  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   443  		var err error
   444  		resp, err = c.notificationChannelClient.GetNotificationChannelDescriptor(ctx, req, settings.GRPC...)
   445  		return err
   446  	}, opts...)
   447  	if err != nil {
   448  		return nil, err
   449  	}
   450  	return resp, nil
   451  }
   452  
   453  func (c *notificationChannelGRPCClient) ListNotificationChannels(ctx context.Context, req *monitoringpb.ListNotificationChannelsRequest, opts ...gax.CallOption) *NotificationChannelIterator {
   454  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   455  
   456  	hds = append(c.xGoogHeaders, hds...)
   457  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   458  	opts = append((*c.CallOptions).ListNotificationChannels[0:len((*c.CallOptions).ListNotificationChannels):len((*c.CallOptions).ListNotificationChannels)], opts...)
   459  	it := &NotificationChannelIterator{}
   460  	req = proto.Clone(req).(*monitoringpb.ListNotificationChannelsRequest)
   461  	it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannel, string, error) {
   462  		resp := &monitoringpb.ListNotificationChannelsResponse{}
   463  		if pageToken != "" {
   464  			req.PageToken = pageToken
   465  		}
   466  		if pageSize > math.MaxInt32 {
   467  			req.PageSize = math.MaxInt32
   468  		} else if pageSize != 0 {
   469  			req.PageSize = int32(pageSize)
   470  		}
   471  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   472  			var err error
   473  			resp, err = c.notificationChannelClient.ListNotificationChannels(ctx, req, settings.GRPC...)
   474  			return err
   475  		}, opts...)
   476  		if err != nil {
   477  			return nil, "", err
   478  		}
   479  
   480  		it.Response = resp
   481  		return resp.GetNotificationChannels(), resp.GetNextPageToken(), nil
   482  	}
   483  	fetch := func(pageSize int, pageToken string) (string, error) {
   484  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   485  		if err != nil {
   486  			return "", err
   487  		}
   488  		it.items = append(it.items, items...)
   489  		return nextPageToken, nil
   490  	}
   491  
   492  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   493  	it.pageInfo.MaxSize = int(req.GetPageSize())
   494  	it.pageInfo.Token = req.GetPageToken()
   495  
   496  	return it
   497  }
   498  
   499  func (c *notificationChannelGRPCClient) GetNotificationChannel(ctx context.Context, req *monitoringpb.GetNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   500  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   501  
   502  	hds = append(c.xGoogHeaders, hds...)
   503  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   504  	opts = append((*c.CallOptions).GetNotificationChannel[0:len((*c.CallOptions).GetNotificationChannel):len((*c.CallOptions).GetNotificationChannel)], opts...)
   505  	var resp *monitoringpb.NotificationChannel
   506  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   507  		var err error
   508  		resp, err = c.notificationChannelClient.GetNotificationChannel(ctx, req, settings.GRPC...)
   509  		return err
   510  	}, opts...)
   511  	if err != nil {
   512  		return nil, err
   513  	}
   514  	return resp, nil
   515  }
   516  
   517  func (c *notificationChannelGRPCClient) CreateNotificationChannel(ctx context.Context, req *monitoringpb.CreateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   518  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   519  
   520  	hds = append(c.xGoogHeaders, hds...)
   521  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   522  	opts = append((*c.CallOptions).CreateNotificationChannel[0:len((*c.CallOptions).CreateNotificationChannel):len((*c.CallOptions).CreateNotificationChannel)], opts...)
   523  	var resp *monitoringpb.NotificationChannel
   524  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   525  		var err error
   526  		resp, err = c.notificationChannelClient.CreateNotificationChannel(ctx, req, settings.GRPC...)
   527  		return err
   528  	}, opts...)
   529  	if err != nil {
   530  		return nil, err
   531  	}
   532  	return resp, nil
   533  }
   534  
   535  func (c *notificationChannelGRPCClient) UpdateNotificationChannel(ctx context.Context, req *monitoringpb.UpdateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   536  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "notification_channel.name", url.QueryEscape(req.GetNotificationChannel().GetName()))}
   537  
   538  	hds = append(c.xGoogHeaders, hds...)
   539  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   540  	opts = append((*c.CallOptions).UpdateNotificationChannel[0:len((*c.CallOptions).UpdateNotificationChannel):len((*c.CallOptions).UpdateNotificationChannel)], opts...)
   541  	var resp *monitoringpb.NotificationChannel
   542  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   543  		var err error
   544  		resp, err = c.notificationChannelClient.UpdateNotificationChannel(ctx, req, settings.GRPC...)
   545  		return err
   546  	}, opts...)
   547  	if err != nil {
   548  		return nil, err
   549  	}
   550  	return resp, nil
   551  }
   552  
   553  func (c *notificationChannelGRPCClient) DeleteNotificationChannel(ctx context.Context, req *monitoringpb.DeleteNotificationChannelRequest, opts ...gax.CallOption) error {
   554  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   555  
   556  	hds = append(c.xGoogHeaders, hds...)
   557  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   558  	opts = append((*c.CallOptions).DeleteNotificationChannel[0:len((*c.CallOptions).DeleteNotificationChannel):len((*c.CallOptions).DeleteNotificationChannel)], opts...)
   559  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   560  		var err error
   561  		_, err = c.notificationChannelClient.DeleteNotificationChannel(ctx, req, settings.GRPC...)
   562  		return err
   563  	}, opts...)
   564  	return err
   565  }
   566  
   567  func (c *notificationChannelGRPCClient) SendNotificationChannelVerificationCode(ctx context.Context, req *monitoringpb.SendNotificationChannelVerificationCodeRequest, opts ...gax.CallOption) error {
   568  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   569  
   570  	hds = append(c.xGoogHeaders, hds...)
   571  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   572  	opts = append((*c.CallOptions).SendNotificationChannelVerificationCode[0:len((*c.CallOptions).SendNotificationChannelVerificationCode):len((*c.CallOptions).SendNotificationChannelVerificationCode)], opts...)
   573  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   574  		var err error
   575  		_, err = c.notificationChannelClient.SendNotificationChannelVerificationCode(ctx, req, settings.GRPC...)
   576  		return err
   577  	}, opts...)
   578  	return err
   579  }
   580  
   581  func (c *notificationChannelGRPCClient) GetNotificationChannelVerificationCode(ctx context.Context, req *monitoringpb.GetNotificationChannelVerificationCodeRequest, opts ...gax.CallOption) (*monitoringpb.GetNotificationChannelVerificationCodeResponse, error) {
   582  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   583  
   584  	hds = append(c.xGoogHeaders, hds...)
   585  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   586  	opts = append((*c.CallOptions).GetNotificationChannelVerificationCode[0:len((*c.CallOptions).GetNotificationChannelVerificationCode):len((*c.CallOptions).GetNotificationChannelVerificationCode)], opts...)
   587  	var resp *monitoringpb.GetNotificationChannelVerificationCodeResponse
   588  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   589  		var err error
   590  		resp, err = c.notificationChannelClient.GetNotificationChannelVerificationCode(ctx, req, settings.GRPC...)
   591  		return err
   592  	}, opts...)
   593  	if err != nil {
   594  		return nil, err
   595  	}
   596  	return resp, nil
   597  }
   598  
   599  func (c *notificationChannelGRPCClient) VerifyNotificationChannel(ctx context.Context, req *monitoringpb.VerifyNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
   600  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   601  
   602  	hds = append(c.xGoogHeaders, hds...)
   603  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   604  	opts = append((*c.CallOptions).VerifyNotificationChannel[0:len((*c.CallOptions).VerifyNotificationChannel):len((*c.CallOptions).VerifyNotificationChannel)], opts...)
   605  	var resp *monitoringpb.NotificationChannel
   606  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   607  		var err error
   608  		resp, err = c.notificationChannelClient.VerifyNotificationChannel(ctx, req, settings.GRPC...)
   609  		return err
   610  	}, opts...)
   611  	if err != nil {
   612  		return nil, err
   613  	}
   614  	return resp, nil
   615  }
   616  

View as plain text