Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

424 linhas
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 logging
  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. loggingpb "google.golang.org/genproto/googleapis/logging/v2"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // ConfigCallOptions contains the retry settings for each method of ConfigClient.
  31. type ConfigCallOptions struct {
  32. ListSinks []gax.CallOption
  33. GetSink []gax.CallOption
  34. CreateSink []gax.CallOption
  35. UpdateSink []gax.CallOption
  36. DeleteSink []gax.CallOption
  37. ListExclusions []gax.CallOption
  38. GetExclusion []gax.CallOption
  39. CreateExclusion []gax.CallOption
  40. UpdateExclusion []gax.CallOption
  41. DeleteExclusion []gax.CallOption
  42. }
  43. func defaultConfigClientOptions() []option.ClientOption {
  44. return []option.ClientOption{
  45. option.WithEndpoint("logging.googleapis.com:443"),
  46. option.WithScopes(DefaultAuthScopes()...),
  47. }
  48. }
  49. func defaultConfigCallOptions() *ConfigCallOptions {
  50. retry := map[[2]string][]gax.CallOption{
  51. {"default", "idempotent"}: {
  52. gax.WithRetry(func() gax.Retryer {
  53. return gax.OnCodes([]codes.Code{
  54. codes.DeadlineExceeded,
  55. codes.Internal,
  56. codes.Unavailable,
  57. }, gax.Backoff{
  58. Initial: 100 * time.Millisecond,
  59. Max: 1000 * time.Millisecond,
  60. Multiplier: 1.2,
  61. })
  62. }),
  63. },
  64. }
  65. return &ConfigCallOptions{
  66. ListSinks: retry[[2]string{"default", "idempotent"}],
  67. GetSink: retry[[2]string{"default", "idempotent"}],
  68. CreateSink: retry[[2]string{"default", "non_idempotent"}],
  69. UpdateSink: retry[[2]string{"default", "non_idempotent"}],
  70. DeleteSink: retry[[2]string{"default", "idempotent"}],
  71. ListExclusions: retry[[2]string{"default", "idempotent"}],
  72. GetExclusion: retry[[2]string{"default", "idempotent"}],
  73. CreateExclusion: retry[[2]string{"default", "non_idempotent"}],
  74. UpdateExclusion: retry[[2]string{"default", "non_idempotent"}],
  75. DeleteExclusion: retry[[2]string{"default", "idempotent"}],
  76. }
  77. }
  78. // ConfigClient is a client for interacting with Stackdriver Logging API.
  79. //
  80. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  81. type ConfigClient struct {
  82. // The connection to the service.
  83. conn *grpc.ClientConn
  84. // The gRPC API client.
  85. configClient loggingpb.ConfigServiceV2Client
  86. // The call options for this service.
  87. CallOptions *ConfigCallOptions
  88. // The x-goog-* metadata to be sent with each request.
  89. xGoogMetadata metadata.MD
  90. }
  91. // NewConfigClient creates a new config service v2 client.
  92. //
  93. // Service for configuring sinks used to export log entries outside of
  94. // Stackdriver Logging.
  95. func NewConfigClient(ctx context.Context, opts ...option.ClientOption) (*ConfigClient, error) {
  96. conn, err := transport.DialGRPC(ctx, append(defaultConfigClientOptions(), opts...)...)
  97. if err != nil {
  98. return nil, err
  99. }
  100. c := &ConfigClient{
  101. conn: conn,
  102. CallOptions: defaultConfigCallOptions(),
  103. configClient: loggingpb.NewConfigServiceV2Client(conn),
  104. }
  105. c.SetGoogleClientInfo()
  106. return c, nil
  107. }
  108. // Connection returns the client's connection to the API service.
  109. func (c *ConfigClient) Connection() *grpc.ClientConn {
  110. return c.conn
  111. }
  112. // Close closes the connection to the API service. The user should invoke this when
  113. // the client is no longer required.
  114. func (c *ConfigClient) Close() error {
  115. return c.conn.Close()
  116. }
  117. // SetGoogleClientInfo sets the name and version of the application in
  118. // the `x-goog-api-client` header passed on each request. Intended for
  119. // use by Google-written clients.
  120. func (c *ConfigClient) SetGoogleClientInfo(keyval ...string) {
  121. kv := append([]string{"gl-go", version.Go()}, keyval...)
  122. kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
  123. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  124. }
  125. // ListSinks lists sinks.
  126. func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest, opts ...gax.CallOption) *LogSinkIterator {
  127. ctx = insertMetadata(ctx, c.xGoogMetadata)
  128. opts = append(c.CallOptions.ListSinks[0:len(c.CallOptions.ListSinks):len(c.CallOptions.ListSinks)], opts...)
  129. it := &LogSinkIterator{}
  130. it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogSink, string, error) {
  131. var resp *loggingpb.ListSinksResponse
  132. req.PageToken = pageToken
  133. if pageSize > math.MaxInt32 {
  134. req.PageSize = math.MaxInt32
  135. } else {
  136. req.PageSize = int32(pageSize)
  137. }
  138. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  139. var err error
  140. resp, err = c.configClient.ListSinks(ctx, req, settings.GRPC...)
  141. return err
  142. }, opts...)
  143. if err != nil {
  144. return nil, "", err
  145. }
  146. return resp.Sinks, resp.NextPageToken, nil
  147. }
  148. fetch := func(pageSize int, pageToken string) (string, error) {
  149. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  150. if err != nil {
  151. return "", err
  152. }
  153. it.items = append(it.items, items...)
  154. return nextPageToken, nil
  155. }
  156. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  157. return it
  158. }
  159. // GetSink gets a sink.
  160. func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
  161. ctx = insertMetadata(ctx, c.xGoogMetadata)
  162. opts = append(c.CallOptions.GetSink[0:len(c.CallOptions.GetSink):len(c.CallOptions.GetSink)], opts...)
  163. var resp *loggingpb.LogSink
  164. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  165. var err error
  166. resp, err = c.configClient.GetSink(ctx, req, settings.GRPC...)
  167. return err
  168. }, opts...)
  169. if err != nil {
  170. return nil, err
  171. }
  172. return resp, nil
  173. }
  174. // CreateSink creates a sink that exports specified log entries to a destination. The
  175. // export of newly-ingested log entries begins immediately, unless the sink's
  176. // writer_identity is not permitted to write to the destination. A sink can
  177. // export log entries only from the resource owning the sink.
  178. func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
  179. ctx = insertMetadata(ctx, c.xGoogMetadata)
  180. opts = append(c.CallOptions.CreateSink[0:len(c.CallOptions.CreateSink):len(c.CallOptions.CreateSink)], opts...)
  181. var resp *loggingpb.LogSink
  182. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  183. var err error
  184. resp, err = c.configClient.CreateSink(ctx, req, settings.GRPC...)
  185. return err
  186. }, opts...)
  187. if err != nil {
  188. return nil, err
  189. }
  190. return resp, nil
  191. }
  192. // UpdateSink updates a sink. This method replaces the following fields in the existing
  193. // sink with values from the new sink: destination, and filter.
  194. // The updated sink might also have a new writer_identity; see the
  195. // unique_writer_identity field.
  196. func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
  197. ctx = insertMetadata(ctx, c.xGoogMetadata)
  198. opts = append(c.CallOptions.UpdateSink[0:len(c.CallOptions.UpdateSink):len(c.CallOptions.UpdateSink)], opts...)
  199. var resp *loggingpb.LogSink
  200. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  201. var err error
  202. resp, err = c.configClient.UpdateSink(ctx, req, settings.GRPC...)
  203. return err
  204. }, opts...)
  205. if err != nil {
  206. return nil, err
  207. }
  208. return resp, nil
  209. }
  210. // DeleteSink deletes a sink. If the sink has a unique writer_identity, then that
  211. // service account is also deleted.
  212. func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest, opts ...gax.CallOption) error {
  213. ctx = insertMetadata(ctx, c.xGoogMetadata)
  214. opts = append(c.CallOptions.DeleteSink[0:len(c.CallOptions.DeleteSink):len(c.CallOptions.DeleteSink)], opts...)
  215. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  216. var err error
  217. _, err = c.configClient.DeleteSink(ctx, req, settings.GRPC...)
  218. return err
  219. }, opts...)
  220. return err
  221. }
  222. // ListExclusions lists all the exclusions in a parent resource.
  223. func (c *ConfigClient) ListExclusions(ctx context.Context, req *loggingpb.ListExclusionsRequest, opts ...gax.CallOption) *LogExclusionIterator {
  224. ctx = insertMetadata(ctx, c.xGoogMetadata)
  225. opts = append(c.CallOptions.ListExclusions[0:len(c.CallOptions.ListExclusions):len(c.CallOptions.ListExclusions)], opts...)
  226. it := &LogExclusionIterator{}
  227. it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogExclusion, string, error) {
  228. var resp *loggingpb.ListExclusionsResponse
  229. req.PageToken = pageToken
  230. if pageSize > math.MaxInt32 {
  231. req.PageSize = math.MaxInt32
  232. } else {
  233. req.PageSize = int32(pageSize)
  234. }
  235. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  236. var err error
  237. resp, err = c.configClient.ListExclusions(ctx, req, settings.GRPC...)
  238. return err
  239. }, opts...)
  240. if err != nil {
  241. return nil, "", err
  242. }
  243. return resp.Exclusions, resp.NextPageToken, nil
  244. }
  245. fetch := func(pageSize int, pageToken string) (string, error) {
  246. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  247. if err != nil {
  248. return "", err
  249. }
  250. it.items = append(it.items, items...)
  251. return nextPageToken, nil
  252. }
  253. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  254. return it
  255. }
  256. // GetExclusion gets the description of an exclusion.
  257. func (c *ConfigClient) GetExclusion(ctx context.Context, req *loggingpb.GetExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) {
  258. ctx = insertMetadata(ctx, c.xGoogMetadata)
  259. opts = append(c.CallOptions.GetExclusion[0:len(c.CallOptions.GetExclusion):len(c.CallOptions.GetExclusion)], opts...)
  260. var resp *loggingpb.LogExclusion
  261. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  262. var err error
  263. resp, err = c.configClient.GetExclusion(ctx, req, settings.GRPC...)
  264. return err
  265. }, opts...)
  266. if err != nil {
  267. return nil, err
  268. }
  269. return resp, nil
  270. }
  271. // CreateExclusion creates a new exclusion in a specified parent resource.
  272. // Only log entries belonging to that resource can be excluded.
  273. // You can have up to 10 exclusions in a resource.
  274. func (c *ConfigClient) CreateExclusion(ctx context.Context, req *loggingpb.CreateExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) {
  275. ctx = insertMetadata(ctx, c.xGoogMetadata)
  276. opts = append(c.CallOptions.CreateExclusion[0:len(c.CallOptions.CreateExclusion):len(c.CallOptions.CreateExclusion)], opts...)
  277. var resp *loggingpb.LogExclusion
  278. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  279. var err error
  280. resp, err = c.configClient.CreateExclusion(ctx, req, settings.GRPC...)
  281. return err
  282. }, opts...)
  283. if err != nil {
  284. return nil, err
  285. }
  286. return resp, nil
  287. }
  288. // UpdateExclusion changes one or more properties of an existing exclusion.
  289. func (c *ConfigClient) UpdateExclusion(ctx context.Context, req *loggingpb.UpdateExclusionRequest, opts ...gax.CallOption) (*loggingpb.LogExclusion, error) {
  290. ctx = insertMetadata(ctx, c.xGoogMetadata)
  291. opts = append(c.CallOptions.UpdateExclusion[0:len(c.CallOptions.UpdateExclusion):len(c.CallOptions.UpdateExclusion)], opts...)
  292. var resp *loggingpb.LogExclusion
  293. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  294. var err error
  295. resp, err = c.configClient.UpdateExclusion(ctx, req, settings.GRPC...)
  296. return err
  297. }, opts...)
  298. if err != nil {
  299. return nil, err
  300. }
  301. return resp, nil
  302. }
  303. // DeleteExclusion deletes an exclusion.
  304. func (c *ConfigClient) DeleteExclusion(ctx context.Context, req *loggingpb.DeleteExclusionRequest, opts ...gax.CallOption) error {
  305. ctx = insertMetadata(ctx, c.xGoogMetadata)
  306. opts = append(c.CallOptions.DeleteExclusion[0:len(c.CallOptions.DeleteExclusion):len(c.CallOptions.DeleteExclusion)], opts...)
  307. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  308. var err error
  309. _, err = c.configClient.DeleteExclusion(ctx, req, settings.GRPC...)
  310. return err
  311. }, opts...)
  312. return err
  313. }
  314. // LogExclusionIterator manages a stream of *loggingpb.LogExclusion.
  315. type LogExclusionIterator struct {
  316. items []*loggingpb.LogExclusion
  317. pageInfo *iterator.PageInfo
  318. nextFunc func() error
  319. // InternalFetch is for use by the Google Cloud Libraries only.
  320. // It is not part of the stable interface of this package.
  321. //
  322. // InternalFetch returns results from a single call to the underlying RPC.
  323. // The number of results is no greater than pageSize.
  324. // If there are no more results, nextPageToken is empty and err is nil.
  325. InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogExclusion, nextPageToken string, err error)
  326. }
  327. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  328. func (it *LogExclusionIterator) PageInfo() *iterator.PageInfo {
  329. return it.pageInfo
  330. }
  331. // Next returns the next result. Its second return value is iterator.Done if there are no more
  332. // results. Once Next returns Done, all subsequent calls will return Done.
  333. func (it *LogExclusionIterator) Next() (*loggingpb.LogExclusion, error) {
  334. var item *loggingpb.LogExclusion
  335. if err := it.nextFunc(); err != nil {
  336. return item, err
  337. }
  338. item = it.items[0]
  339. it.items = it.items[1:]
  340. return item, nil
  341. }
  342. func (it *LogExclusionIterator) bufLen() int {
  343. return len(it.items)
  344. }
  345. func (it *LogExclusionIterator) takeBuf() interface{} {
  346. b := it.items
  347. it.items = nil
  348. return b
  349. }
  350. // LogSinkIterator manages a stream of *loggingpb.LogSink.
  351. type LogSinkIterator struct {
  352. items []*loggingpb.LogSink
  353. pageInfo *iterator.PageInfo
  354. nextFunc func() error
  355. // InternalFetch is for use by the Google Cloud Libraries only.
  356. // It is not part of the stable interface of this package.
  357. //
  358. // InternalFetch returns results from a single call to the underlying RPC.
  359. // The number of results is no greater than pageSize.
  360. // If there are no more results, nextPageToken is empty and err is nil.
  361. InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogSink, nextPageToken string, err error)
  362. }
  363. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  364. func (it *LogSinkIterator) PageInfo() *iterator.PageInfo {
  365. return it.pageInfo
  366. }
  367. // Next returns the next result. Its second return value is iterator.Done if there are no more
  368. // results. Once Next returns Done, all subsequent calls will return Done.
  369. func (it *LogSinkIterator) Next() (*loggingpb.LogSink, error) {
  370. var item *loggingpb.LogSink
  371. if err := it.nextFunc(); err != nil {
  372. return item, err
  373. }
  374. item = it.items[0]
  375. it.items = it.items[1:]
  376. return item, nil
  377. }
  378. func (it *LogSinkIterator) bufLen() int {
  379. return len(it.items)
  380. }
  381. func (it *LogSinkIterator) takeBuf() interface{} {
  382. b := it.items
  383. it.items = nil
  384. return b
  385. }