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.
 
 
 

372 lines
15 KiB

  1. // Copyright 2018 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. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package monitoring
  16. import (
  17. "math"
  18. "time"
  19. "cloud.google.com/go/internal/version"
  20. gax "github.com/googleapis/gax-go"
  21. "golang.org/x/net/context"
  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", version.Go()}, keyval...)
  115. kv = append(kv, "gapic", version.Repo, "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. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannelDescriptor, string, error) {
  125. var resp *monitoringpb.ListNotificationChannelDescriptorsResponse
  126. req.PageToken = pageToken
  127. if pageSize > math.MaxInt32 {
  128. req.PageSize = math.MaxInt32
  129. } else {
  130. req.PageSize = int32(pageSize)
  131. }
  132. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  133. var err error
  134. resp, err = c.notificationChannelClient.ListNotificationChannelDescriptors(ctx, req, settings.GRPC...)
  135. return err
  136. }, opts...)
  137. if err != nil {
  138. return nil, "", err
  139. }
  140. return resp.ChannelDescriptors, resp.NextPageToken, nil
  141. }
  142. fetch := func(pageSize int, pageToken string) (string, error) {
  143. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  144. if err != nil {
  145. return "", err
  146. }
  147. it.items = append(it.items, items...)
  148. return nextPageToken, nil
  149. }
  150. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  151. return it
  152. }
  153. // GetNotificationChannelDescriptor gets a single channel descriptor. The descriptor indicates which fields
  154. // are expected / permitted for a notification channel of the given type.
  155. func (c *NotificationChannelClient) GetNotificationChannelDescriptor(ctx context.Context, req *monitoringpb.GetNotificationChannelDescriptorRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannelDescriptor, error) {
  156. ctx = insertMetadata(ctx, c.xGoogMetadata)
  157. opts = append(c.CallOptions.GetNotificationChannelDescriptor[0:len(c.CallOptions.GetNotificationChannelDescriptor):len(c.CallOptions.GetNotificationChannelDescriptor)], opts...)
  158. var resp *monitoringpb.NotificationChannelDescriptor
  159. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  160. var err error
  161. resp, err = c.notificationChannelClient.GetNotificationChannelDescriptor(ctx, req, settings.GRPC...)
  162. return err
  163. }, opts...)
  164. if err != nil {
  165. return nil, err
  166. }
  167. return resp, nil
  168. }
  169. // ListNotificationChannels lists the notification channels that have been created for the project.
  170. func (c *NotificationChannelClient) ListNotificationChannels(ctx context.Context, req *monitoringpb.ListNotificationChannelsRequest, opts ...gax.CallOption) *NotificationChannelIterator {
  171. ctx = insertMetadata(ctx, c.xGoogMetadata)
  172. opts = append(c.CallOptions.ListNotificationChannels[0:len(c.CallOptions.ListNotificationChannels):len(c.CallOptions.ListNotificationChannels)], opts...)
  173. it := &NotificationChannelIterator{}
  174. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannel, string, error) {
  175. var resp *monitoringpb.ListNotificationChannelsResponse
  176. req.PageToken = pageToken
  177. if pageSize > math.MaxInt32 {
  178. req.PageSize = math.MaxInt32
  179. } else {
  180. req.PageSize = int32(pageSize)
  181. }
  182. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  183. var err error
  184. resp, err = c.notificationChannelClient.ListNotificationChannels(ctx, req, settings.GRPC...)
  185. return err
  186. }, opts...)
  187. if err != nil {
  188. return nil, "", err
  189. }
  190. return resp.NotificationChannels, resp.NextPageToken, nil
  191. }
  192. fetch := func(pageSize int, pageToken string) (string, error) {
  193. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  194. if err != nil {
  195. return "", err
  196. }
  197. it.items = append(it.items, items...)
  198. return nextPageToken, nil
  199. }
  200. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  201. return it
  202. }
  203. // GetNotificationChannel gets a single notification channel. The channel includes the relevant
  204. // configuration details with which the channel was created. However, the
  205. // response may truncate or omit passwords, API keys, or other private key
  206. // matter and thus the response may not be 100% identical to the information
  207. // that was supplied in the call to the create method.
  208. func (c *NotificationChannelClient) GetNotificationChannel(ctx context.Context, req *monitoringpb.GetNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
  209. ctx = insertMetadata(ctx, c.xGoogMetadata)
  210. opts = append(c.CallOptions.GetNotificationChannel[0:len(c.CallOptions.GetNotificationChannel):len(c.CallOptions.GetNotificationChannel)], opts...)
  211. var resp *monitoringpb.NotificationChannel
  212. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  213. var err error
  214. resp, err = c.notificationChannelClient.GetNotificationChannel(ctx, req, settings.GRPC...)
  215. return err
  216. }, opts...)
  217. if err != nil {
  218. return nil, err
  219. }
  220. return resp, nil
  221. }
  222. // CreateNotificationChannel creates a new notification channel, representing a single notification
  223. // endpoint such as an email address, SMS number, or pagerduty service.
  224. func (c *NotificationChannelClient) CreateNotificationChannel(ctx context.Context, req *monitoringpb.CreateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
  225. ctx = insertMetadata(ctx, c.xGoogMetadata)
  226. opts = append(c.CallOptions.CreateNotificationChannel[0:len(c.CallOptions.CreateNotificationChannel):len(c.CallOptions.CreateNotificationChannel)], opts...)
  227. var resp *monitoringpb.NotificationChannel
  228. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  229. var err error
  230. resp, err = c.notificationChannelClient.CreateNotificationChannel(ctx, req, settings.GRPC...)
  231. return err
  232. }, opts...)
  233. if err != nil {
  234. return nil, err
  235. }
  236. return resp, nil
  237. }
  238. // UpdateNotificationChannel updates a notification channel. Fields not specified in the field mask
  239. // remain unchanged.
  240. func (c *NotificationChannelClient) UpdateNotificationChannel(ctx context.Context, req *monitoringpb.UpdateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
  241. ctx = insertMetadata(ctx, c.xGoogMetadata)
  242. opts = append(c.CallOptions.UpdateNotificationChannel[0:len(c.CallOptions.UpdateNotificationChannel):len(c.CallOptions.UpdateNotificationChannel)], opts...)
  243. var resp *monitoringpb.NotificationChannel
  244. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  245. var err error
  246. resp, err = c.notificationChannelClient.UpdateNotificationChannel(ctx, req, settings.GRPC...)
  247. return err
  248. }, opts...)
  249. if err != nil {
  250. return nil, err
  251. }
  252. return resp, nil
  253. }
  254. // DeleteNotificationChannel deletes a notification channel.
  255. func (c *NotificationChannelClient) DeleteNotificationChannel(ctx context.Context, req *monitoringpb.DeleteNotificationChannelRequest, opts ...gax.CallOption) error {
  256. ctx = insertMetadata(ctx, c.xGoogMetadata)
  257. opts = append(c.CallOptions.DeleteNotificationChannel[0:len(c.CallOptions.DeleteNotificationChannel):len(c.CallOptions.DeleteNotificationChannel)], opts...)
  258. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  259. var err error
  260. _, err = c.notificationChannelClient.DeleteNotificationChannel(ctx, req, settings.GRPC...)
  261. return err
  262. }, opts...)
  263. return err
  264. }
  265. // NotificationChannelDescriptorIterator manages a stream of *monitoringpb.NotificationChannelDescriptor.
  266. type NotificationChannelDescriptorIterator struct {
  267. items []*monitoringpb.NotificationChannelDescriptor
  268. pageInfo *iterator.PageInfo
  269. nextFunc func() error
  270. // InternalFetch is for use by the Google Cloud Libraries only.
  271. // It is not part of the stable interface of this package.
  272. //
  273. // InternalFetch returns results from a single call to the underlying RPC.
  274. // The number of results is no greater than pageSize.
  275. // If there are no more results, nextPageToken is empty and err is nil.
  276. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.NotificationChannelDescriptor, nextPageToken string, err error)
  277. }
  278. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  279. func (it *NotificationChannelDescriptorIterator) PageInfo() *iterator.PageInfo {
  280. return it.pageInfo
  281. }
  282. // Next returns the next result. Its second return value is iterator.Done if there are no more
  283. // results. Once Next returns Done, all subsequent calls will return Done.
  284. func (it *NotificationChannelDescriptorIterator) Next() (*monitoringpb.NotificationChannelDescriptor, error) {
  285. var item *monitoringpb.NotificationChannelDescriptor
  286. if err := it.nextFunc(); err != nil {
  287. return item, err
  288. }
  289. item = it.items[0]
  290. it.items = it.items[1:]
  291. return item, nil
  292. }
  293. func (it *NotificationChannelDescriptorIterator) bufLen() int {
  294. return len(it.items)
  295. }
  296. func (it *NotificationChannelDescriptorIterator) takeBuf() interface{} {
  297. b := it.items
  298. it.items = nil
  299. return b
  300. }
  301. // NotificationChannelIterator manages a stream of *monitoringpb.NotificationChannel.
  302. type NotificationChannelIterator struct {
  303. items []*monitoringpb.NotificationChannel
  304. pageInfo *iterator.PageInfo
  305. nextFunc func() error
  306. // InternalFetch is for use by the Google Cloud Libraries only.
  307. // It is not part of the stable interface of this package.
  308. //
  309. // InternalFetch returns results from a single call to the underlying RPC.
  310. // The number of results is no greater than pageSize.
  311. // If there are no more results, nextPageToken is empty and err is nil.
  312. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.NotificationChannel, nextPageToken string, err error)
  313. }
  314. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  315. func (it *NotificationChannelIterator) PageInfo() *iterator.PageInfo {
  316. return it.pageInfo
  317. }
  318. // Next returns the next result. Its second return value is iterator.Done if there are no more
  319. // results. Once Next returns Done, all subsequent calls will return Done.
  320. func (it *NotificationChannelIterator) Next() (*monitoringpb.NotificationChannel, error) {
  321. var item *monitoringpb.NotificationChannel
  322. if err := it.nextFunc(); err != nil {
  323. return item, err
  324. }
  325. item = it.items[0]
  326. it.items = it.items[1:]
  327. return item, nil
  328. }
  329. func (it *NotificationChannelIterator) bufLen() int {
  330. return len(it.items)
  331. }
  332. func (it *NotificationChannelIterator) takeBuf() interface{} {
  333. b := it.items
  334. it.items = nil
  335. return b
  336. }