You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

376 lines
16 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package monitoring
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // NotificationChannelCallOptions contains the retry settings for each method of NotificationChannelClient.
  31. type NotificationChannelCallOptions struct {
  32. ListNotificationChannelDescriptors []gax.CallOption
  33. GetNotificationChannelDescriptor []gax.CallOption
  34. ListNotificationChannels []gax.CallOption
  35. GetNotificationChannel []gax.CallOption
  36. CreateNotificationChannel []gax.CallOption
  37. UpdateNotificationChannel []gax.CallOption
  38. DeleteNotificationChannel []gax.CallOption
  39. }
  40. func defaultNotificationChannelClientOptions() []option.ClientOption {
  41. return []option.ClientOption{
  42. option.WithEndpoint("monitoring.googleapis.com:443"),
  43. option.WithScopes(DefaultAuthScopes()...),
  44. }
  45. }
  46. func defaultNotificationChannelCallOptions() *NotificationChannelCallOptions {
  47. retry := map[[2]string][]gax.CallOption{
  48. {"default", "idempotent"}: {
  49. gax.WithRetry(func() gax.Retryer {
  50. return gax.OnCodes([]codes.Code{
  51. codes.DeadlineExceeded,
  52. codes.Unavailable,
  53. }, gax.Backoff{
  54. Initial: 100 * time.Millisecond,
  55. Max: 60000 * time.Millisecond,
  56. Multiplier: 1.3,
  57. })
  58. }),
  59. },
  60. }
  61. return &NotificationChannelCallOptions{
  62. ListNotificationChannelDescriptors: retry[[2]string{"default", "idempotent"}],
  63. GetNotificationChannelDescriptor: retry[[2]string{"default", "idempotent"}],
  64. ListNotificationChannels: retry[[2]string{"default", "idempotent"}],
  65. GetNotificationChannel: retry[[2]string{"default", "idempotent"}],
  66. CreateNotificationChannel: retry[[2]string{"default", "non_idempotent"}],
  67. UpdateNotificationChannel: retry[[2]string{"default", "non_idempotent"}],
  68. DeleteNotificationChannel: retry[[2]string{"default", "idempotent"}],
  69. }
  70. }
  71. // NotificationChannelClient is a client for interacting with Stackdriver Monitoring API.
  72. //
  73. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  74. type NotificationChannelClient struct {
  75. // The connection to the service.
  76. conn *grpc.ClientConn
  77. // The gRPC API client.
  78. notificationChannelClient monitoringpb.NotificationChannelServiceClient
  79. // The call options for this service.
  80. CallOptions *NotificationChannelCallOptions
  81. // The x-goog-* metadata to be sent with each request.
  82. xGoogMetadata metadata.MD
  83. }
  84. // NewNotificationChannelClient creates a new notification channel service client.
  85. //
  86. // The Notification Channel API provides access to configuration that
  87. // controls how messages related to incidents are sent.
  88. func NewNotificationChannelClient(ctx context.Context, opts ...option.ClientOption) (*NotificationChannelClient, error) {
  89. conn, err := transport.DialGRPC(ctx, append(defaultNotificationChannelClientOptions(), opts...)...)
  90. if err != nil {
  91. return nil, err
  92. }
  93. c := &NotificationChannelClient{
  94. conn: conn,
  95. CallOptions: defaultNotificationChannelCallOptions(),
  96. notificationChannelClient: monitoringpb.NewNotificationChannelServiceClient(conn),
  97. }
  98. c.setGoogleClientInfo()
  99. return c, nil
  100. }
  101. // Connection returns the client's connection to the API service.
  102. func (c *NotificationChannelClient) Connection() *grpc.ClientConn {
  103. return c.conn
  104. }
  105. // Close closes the connection to the API service. The user should invoke this when
  106. // the client is no longer required.
  107. func (c *NotificationChannelClient) Close() error {
  108. return c.conn.Close()
  109. }
  110. // setGoogleClientInfo sets the name and version of the application in
  111. // the `x-goog-api-client` header passed on each request. Intended for
  112. // use by Google-written clients.
  113. func (c *NotificationChannelClient) setGoogleClientInfo(keyval ...string) {
  114. kv := append([]string{"gl-go", versionGo()}, keyval...)
  115. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  116. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  117. }
  118. // ListNotificationChannelDescriptors lists the descriptors for supported channel types. The use of descriptors
  119. // makes it possible for new channel types to be dynamically added.
  120. func (c *NotificationChannelClient) ListNotificationChannelDescriptors(ctx context.Context, req *monitoringpb.ListNotificationChannelDescriptorsRequest, opts ...gax.CallOption) *NotificationChannelDescriptorIterator {
  121. ctx = insertMetadata(ctx, c.xGoogMetadata)
  122. opts = append(c.CallOptions.ListNotificationChannelDescriptors[0:len(c.CallOptions.ListNotificationChannelDescriptors):len(c.CallOptions.ListNotificationChannelDescriptors)], opts...)
  123. it := &NotificationChannelDescriptorIterator{}
  124. req = proto.Clone(req).(*monitoringpb.ListNotificationChannelDescriptorsRequest)
  125. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannelDescriptor, string, error) {
  126. var resp *monitoringpb.ListNotificationChannelDescriptorsResponse
  127. req.PageToken = pageToken
  128. if pageSize > math.MaxInt32 {
  129. req.PageSize = math.MaxInt32
  130. } else {
  131. req.PageSize = int32(pageSize)
  132. }
  133. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  134. var err error
  135. resp, err = c.notificationChannelClient.ListNotificationChannelDescriptors(ctx, req, settings.GRPC...)
  136. return err
  137. }, opts...)
  138. if err != nil {
  139. return nil, "", err
  140. }
  141. return resp.ChannelDescriptors, resp.NextPageToken, nil
  142. }
  143. fetch := func(pageSize int, pageToken string) (string, error) {
  144. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  145. if err != nil {
  146. return "", err
  147. }
  148. it.items = append(it.items, items...)
  149. return nextPageToken, nil
  150. }
  151. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  152. it.pageInfo.MaxSize = int(req.PageSize)
  153. return it
  154. }
  155. // GetNotificationChannelDescriptor gets a single channel descriptor. The descriptor indicates which fields
  156. // are expected / permitted for a notification channel of the given type.
  157. func (c *NotificationChannelClient) GetNotificationChannelDescriptor(ctx context.Context, req *monitoringpb.GetNotificationChannelDescriptorRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannelDescriptor, error) {
  158. ctx = insertMetadata(ctx, c.xGoogMetadata)
  159. opts = append(c.CallOptions.GetNotificationChannelDescriptor[0:len(c.CallOptions.GetNotificationChannelDescriptor):len(c.CallOptions.GetNotificationChannelDescriptor)], opts...)
  160. var resp *monitoringpb.NotificationChannelDescriptor
  161. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  162. var err error
  163. resp, err = c.notificationChannelClient.GetNotificationChannelDescriptor(ctx, req, settings.GRPC...)
  164. return err
  165. }, opts...)
  166. if err != nil {
  167. return nil, err
  168. }
  169. return resp, nil
  170. }
  171. // ListNotificationChannels lists the notification channels that have been created for the project.
  172. func (c *NotificationChannelClient) ListNotificationChannels(ctx context.Context, req *monitoringpb.ListNotificationChannelsRequest, opts ...gax.CallOption) *NotificationChannelIterator {
  173. ctx = insertMetadata(ctx, c.xGoogMetadata)
  174. opts = append(c.CallOptions.ListNotificationChannels[0:len(c.CallOptions.ListNotificationChannels):len(c.CallOptions.ListNotificationChannels)], opts...)
  175. it := &NotificationChannelIterator{}
  176. req = proto.Clone(req).(*monitoringpb.ListNotificationChannelsRequest)
  177. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannel, string, error) {
  178. var resp *monitoringpb.ListNotificationChannelsResponse
  179. req.PageToken = pageToken
  180. if pageSize > math.MaxInt32 {
  181. req.PageSize = math.MaxInt32
  182. } else {
  183. req.PageSize = int32(pageSize)
  184. }
  185. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  186. var err error
  187. resp, err = c.notificationChannelClient.ListNotificationChannels(ctx, req, settings.GRPC...)
  188. return err
  189. }, opts...)
  190. if err != nil {
  191. return nil, "", err
  192. }
  193. return resp.NotificationChannels, resp.NextPageToken, nil
  194. }
  195. fetch := func(pageSize int, pageToken string) (string, error) {
  196. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  197. if err != nil {
  198. return "", err
  199. }
  200. it.items = append(it.items, items...)
  201. return nextPageToken, nil
  202. }
  203. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  204. it.pageInfo.MaxSize = int(req.PageSize)
  205. return it
  206. }
  207. // GetNotificationChannel gets a single notification channel. The channel includes the relevant
  208. // configuration details with which the channel was created. However, the
  209. // response may truncate or omit passwords, API keys, or other private key
  210. // matter and thus the response may not be 100% identical to the information
  211. // that was supplied in the call to the create method.
  212. func (c *NotificationChannelClient) GetNotificationChannel(ctx context.Context, req *monitoringpb.GetNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
  213. ctx = insertMetadata(ctx, c.xGoogMetadata)
  214. opts = append(c.CallOptions.GetNotificationChannel[0:len(c.CallOptions.GetNotificationChannel):len(c.CallOptions.GetNotificationChannel)], opts...)
  215. var resp *monitoringpb.NotificationChannel
  216. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  217. var err error
  218. resp, err = c.notificationChannelClient.GetNotificationChannel(ctx, req, settings.GRPC...)
  219. return err
  220. }, opts...)
  221. if err != nil {
  222. return nil, err
  223. }
  224. return resp, nil
  225. }
  226. // CreateNotificationChannel creates a new notification channel, representing a single notification
  227. // endpoint such as an email address, SMS number, or PagerDuty service.
  228. func (c *NotificationChannelClient) CreateNotificationChannel(ctx context.Context, req *monitoringpb.CreateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
  229. ctx = insertMetadata(ctx, c.xGoogMetadata)
  230. opts = append(c.CallOptions.CreateNotificationChannel[0:len(c.CallOptions.CreateNotificationChannel):len(c.CallOptions.CreateNotificationChannel)], opts...)
  231. var resp *monitoringpb.NotificationChannel
  232. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  233. var err error
  234. resp, err = c.notificationChannelClient.CreateNotificationChannel(ctx, req, settings.GRPC...)
  235. return err
  236. }, opts...)
  237. if err != nil {
  238. return nil, err
  239. }
  240. return resp, nil
  241. }
  242. // UpdateNotificationChannel updates a notification channel. Fields not specified in the field mask
  243. // remain unchanged.
  244. func (c *NotificationChannelClient) UpdateNotificationChannel(ctx context.Context, req *monitoringpb.UpdateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
  245. ctx = insertMetadata(ctx, c.xGoogMetadata)
  246. opts = append(c.CallOptions.UpdateNotificationChannel[0:len(c.CallOptions.UpdateNotificationChannel):len(c.CallOptions.UpdateNotificationChannel)], opts...)
  247. var resp *monitoringpb.NotificationChannel
  248. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  249. var err error
  250. resp, err = c.notificationChannelClient.UpdateNotificationChannel(ctx, req, settings.GRPC...)
  251. return err
  252. }, opts...)
  253. if err != nil {
  254. return nil, err
  255. }
  256. return resp, nil
  257. }
  258. // DeleteNotificationChannel deletes a notification channel.
  259. func (c *NotificationChannelClient) DeleteNotificationChannel(ctx context.Context, req *monitoringpb.DeleteNotificationChannelRequest, opts ...gax.CallOption) error {
  260. ctx = insertMetadata(ctx, c.xGoogMetadata)
  261. opts = append(c.CallOptions.DeleteNotificationChannel[0:len(c.CallOptions.DeleteNotificationChannel):len(c.CallOptions.DeleteNotificationChannel)], opts...)
  262. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  263. var err error
  264. _, err = c.notificationChannelClient.DeleteNotificationChannel(ctx, req, settings.GRPC...)
  265. return err
  266. }, opts...)
  267. return err
  268. }
  269. // NotificationChannelDescriptorIterator manages a stream of *monitoringpb.NotificationChannelDescriptor.
  270. type NotificationChannelDescriptorIterator struct {
  271. items []*monitoringpb.NotificationChannelDescriptor
  272. pageInfo *iterator.PageInfo
  273. nextFunc func() error
  274. // InternalFetch is for use by the Google Cloud Libraries only.
  275. // It is not part of the stable interface of this package.
  276. //
  277. // InternalFetch returns results from a single call to the underlying RPC.
  278. // The number of results is no greater than pageSize.
  279. // If there are no more results, nextPageToken is empty and err is nil.
  280. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.NotificationChannelDescriptor, nextPageToken string, err error)
  281. }
  282. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  283. func (it *NotificationChannelDescriptorIterator) PageInfo() *iterator.PageInfo {
  284. return it.pageInfo
  285. }
  286. // Next returns the next result. Its second return value is iterator.Done if there are no more
  287. // results. Once Next returns Done, all subsequent calls will return Done.
  288. func (it *NotificationChannelDescriptorIterator) Next() (*monitoringpb.NotificationChannelDescriptor, error) {
  289. var item *monitoringpb.NotificationChannelDescriptor
  290. if err := it.nextFunc(); err != nil {
  291. return item, err
  292. }
  293. item = it.items[0]
  294. it.items = it.items[1:]
  295. return item, nil
  296. }
  297. func (it *NotificationChannelDescriptorIterator) bufLen() int {
  298. return len(it.items)
  299. }
  300. func (it *NotificationChannelDescriptorIterator) takeBuf() interface{} {
  301. b := it.items
  302. it.items = nil
  303. return b
  304. }
  305. // NotificationChannelIterator manages a stream of *monitoringpb.NotificationChannel.
  306. type NotificationChannelIterator struct {
  307. items []*monitoringpb.NotificationChannel
  308. pageInfo *iterator.PageInfo
  309. nextFunc func() error
  310. // InternalFetch is for use by the Google Cloud Libraries only.
  311. // It is not part of the stable interface of this package.
  312. //
  313. // InternalFetch returns results from a single call to the underlying RPC.
  314. // The number of results is no greater than pageSize.
  315. // If there are no more results, nextPageToken is empty and err is nil.
  316. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.NotificationChannel, nextPageToken string, err error)
  317. }
  318. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  319. func (it *NotificationChannelIterator) PageInfo() *iterator.PageInfo {
  320. return it.pageInfo
  321. }
  322. // Next returns the next result. Its second return value is iterator.Done if there are no more
  323. // results. Once Next returns Done, all subsequent calls will return Done.
  324. func (it *NotificationChannelIterator) Next() (*monitoringpb.NotificationChannel, error) {
  325. var item *monitoringpb.NotificationChannel
  326. if err := it.nextFunc(); err != nil {
  327. return item, err
  328. }
  329. item = it.items[0]
  330. it.items = it.items[1:]
  331. return item, nil
  332. }
  333. func (it *NotificationChannelIterator) bufLen() int {
  334. return len(it.items)
  335. }
  336. func (it *NotificationChannelIterator) takeBuf() interface{} {
  337. b := it.items
  338. it.items = nil
  339. return b
  340. }