api_op_DescribeLogGroups.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package cloudwatchlogs
  3. import (
  4. "context"
  5. "fmt"
  6. awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  7. "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
  8. "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
  9. "github.com/aws/smithy-go/middleware"
  10. smithyhttp "github.com/aws/smithy-go/transport/http"
  11. )
  12. // Lists the specified log groups. You can list all your log groups or filter the
  13. // results by prefix. The results are ASCII-sorted by log group name. CloudWatch
  14. // Logs doesn’t support IAM policies that control access to the DescribeLogGroups
  15. // action by using the aws:ResourceTag/key-name condition key. Other CloudWatch
  16. // Logs actions do support the use of the aws:ResourceTag/key-name condition key
  17. // to control access. For more information about using tags to control access, see
  18. // Controlling access to Amazon Web Services resources using tags
  19. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html).
  20. func (c *Client) DescribeLogGroups(ctx context.Context, params *DescribeLogGroupsInput, optFns ...func(*Options)) (*DescribeLogGroupsOutput, error) {
  21. if params == nil {
  22. params = &DescribeLogGroupsInput{}
  23. }
  24. result, metadata, err := c.invokeOperation(ctx, "DescribeLogGroups", params, optFns, c.addOperationDescribeLogGroupsMiddlewares)
  25. if err != nil {
  26. return nil, err
  27. }
  28. out := result.(*DescribeLogGroupsOutput)
  29. out.ResultMetadata = metadata
  30. return out, nil
  31. }
  32. type DescribeLogGroupsInput struct {
  33. // The maximum number of items returned. If you don't specify a value, the default
  34. // is up to 50 items.
  35. Limit *int32
  36. // The prefix to match.
  37. LogGroupNamePrefix *string
  38. // The token for the next set of items to return. (You received this token from a
  39. // previous call.)
  40. NextToken *string
  41. noSmithyDocumentSerde
  42. }
  43. type DescribeLogGroupsOutput struct {
  44. // The log groups. If the retentionInDays value is not included for a log group,
  45. // then that log group is set to have its events never expire.
  46. LogGroups []types.LogGroup
  47. // The token for the next set of items to return. The token expires after 24 hours.
  48. NextToken *string
  49. // Metadata pertaining to the operation's result.
  50. ResultMetadata middleware.Metadata
  51. noSmithyDocumentSerde
  52. }
  53. func (c *Client) addOperationDescribeLogGroupsMiddlewares(stack *middleware.Stack, options Options) (err error) {
  54. err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeLogGroups{}, middleware.After)
  55. if err != nil {
  56. return err
  57. }
  58. err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeLogGroups{}, middleware.After)
  59. if err != nil {
  60. return err
  61. }
  62. if err = addSetLoggerMiddleware(stack, options); err != nil {
  63. return err
  64. }
  65. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  66. return err
  67. }
  68. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  69. return err
  70. }
  71. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  72. return err
  73. }
  74. if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
  75. return err
  76. }
  77. if err = addRetryMiddlewares(stack, options); err != nil {
  78. return err
  79. }
  80. if err = addHTTPSignerV4Middleware(stack, options); err != nil {
  81. return err
  82. }
  83. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  84. return err
  85. }
  86. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  87. return err
  88. }
  89. if err = addClientUserAgent(stack); err != nil {
  90. return err
  91. }
  92. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  93. return err
  94. }
  95. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  96. return err
  97. }
  98. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeLogGroups(options.Region), middleware.Before); err != nil {
  99. return err
  100. }
  101. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  102. return err
  103. }
  104. if err = addResponseErrorMiddleware(stack); err != nil {
  105. return err
  106. }
  107. if err = addRequestResponseLogging(stack, options); err != nil {
  108. return err
  109. }
  110. return nil
  111. }
  112. // DescribeLogGroupsAPIClient is a client that implements the DescribeLogGroups
  113. // operation.
  114. type DescribeLogGroupsAPIClient interface {
  115. DescribeLogGroups(context.Context, *DescribeLogGroupsInput, ...func(*Options)) (*DescribeLogGroupsOutput, error)
  116. }
  117. var _ DescribeLogGroupsAPIClient = (*Client)(nil)
  118. // DescribeLogGroupsPaginatorOptions is the paginator options for DescribeLogGroups
  119. type DescribeLogGroupsPaginatorOptions struct {
  120. // The maximum number of items returned. If you don't specify a value, the default
  121. // is up to 50 items.
  122. Limit int32
  123. // Set to true if pagination should stop if the service returns a pagination token
  124. // that matches the most recent token provided to the service.
  125. StopOnDuplicateToken bool
  126. }
  127. // DescribeLogGroupsPaginator is a paginator for DescribeLogGroups
  128. type DescribeLogGroupsPaginator struct {
  129. options DescribeLogGroupsPaginatorOptions
  130. client DescribeLogGroupsAPIClient
  131. params *DescribeLogGroupsInput
  132. nextToken *string
  133. firstPage bool
  134. }
  135. // NewDescribeLogGroupsPaginator returns a new DescribeLogGroupsPaginator
  136. func NewDescribeLogGroupsPaginator(client DescribeLogGroupsAPIClient, params *DescribeLogGroupsInput, optFns ...func(*DescribeLogGroupsPaginatorOptions)) *DescribeLogGroupsPaginator {
  137. if params == nil {
  138. params = &DescribeLogGroupsInput{}
  139. }
  140. options := DescribeLogGroupsPaginatorOptions{}
  141. if params.Limit != nil {
  142. options.Limit = *params.Limit
  143. }
  144. for _, fn := range optFns {
  145. fn(&options)
  146. }
  147. return &DescribeLogGroupsPaginator{
  148. options: options,
  149. client: client,
  150. params: params,
  151. firstPage: true,
  152. nextToken: params.NextToken,
  153. }
  154. }
  155. // HasMorePages returns a boolean indicating whether more pages are available
  156. func (p *DescribeLogGroupsPaginator) HasMorePages() bool {
  157. return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
  158. }
  159. // NextPage retrieves the next DescribeLogGroups page.
  160. func (p *DescribeLogGroupsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeLogGroupsOutput, error) {
  161. if !p.HasMorePages() {
  162. return nil, fmt.Errorf("no more pages available")
  163. }
  164. params := *p.params
  165. params.NextToken = p.nextToken
  166. var limit *int32
  167. if p.options.Limit > 0 {
  168. limit = &p.options.Limit
  169. }
  170. params.Limit = limit
  171. result, err := p.client.DescribeLogGroups(ctx, &params, optFns...)
  172. if err != nil {
  173. return nil, err
  174. }
  175. p.firstPage = false
  176. prevToken := p.nextToken
  177. p.nextToken = result.NextToken
  178. if p.options.StopOnDuplicateToken &&
  179. prevToken != nil &&
  180. p.nextToken != nil &&
  181. *prevToken == *p.nextToken {
  182. p.nextToken = nil
  183. }
  184. return result, nil
  185. }
  186. func newServiceMetadataMiddleware_opDescribeLogGroups(region string) *awsmiddleware.RegisterServiceMetadata {
  187. return &awsmiddleware.RegisterServiceMetadata{
  188. Region: region,
  189. ServiceID: ServiceID,
  190. SigningName: "logs",
  191. OperationName: "DescribeLogGroups",
  192. }
  193. }