1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package macie2 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/macie2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Retrieves (queries) quotas and aggregated usage data for one or more accounts. 16func (c *Client) GetUsageStatistics(ctx context.Context, params *GetUsageStatisticsInput, optFns ...func(*Options)) (*GetUsageStatisticsOutput, error) { 17 if params == nil { 18 params = &GetUsageStatisticsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "GetUsageStatistics", params, optFns, addOperationGetUsageStatisticsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*GetUsageStatisticsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type GetUsageStatisticsInput struct { 32 33 // An array of objects, one for each condition to use to filter the query results. 34 // If you specify more than one condition, Amazon Macie uses an AND operator to 35 // join the conditions. 36 FilterBy []types.UsageStatisticsFilter 37 38 // The maximum number of items to include in each page of the response. 39 MaxResults int32 40 41 // The nextToken string that specifies which page of results to return in a 42 // paginated response. 43 NextToken *string 44 45 // The criteria to use to sort the query results. 46 SortBy *types.UsageStatisticsSortBy 47 48 // The inclusive time period to query usage data for. Valid values are: 49 // MONTH_TO_DATE, for the current calendar month to date; and, PAST_30_DAYS, for 50 // the preceding 30 days. If you don't specify a value, Amazon Macie provides usage 51 // data for the preceding 30 days. 52 TimeRange types.TimeRange 53} 54 55type GetUsageStatisticsOutput struct { 56 57 // The string to use in a subsequent request to get the next page of results in a 58 // paginated response. This value is null if there are no additional pages. 59 NextToken *string 60 61 // An array of objects that contains the results of the query. Each object contains 62 // the data for an account that meets the filter criteria specified in the request. 63 Records []types.UsageRecord 64 65 // The inclusive time period that the usage data applies to. Possible values are: 66 // MONTH_TO_DATE, for the current calendar month to date; and, PAST_30_DAYS, for 67 // the preceding 30 days. 68 TimeRange types.TimeRange 69 70 // Metadata pertaining to the operation's result. 71 ResultMetadata middleware.Metadata 72} 73 74func addOperationGetUsageStatisticsMiddlewares(stack *middleware.Stack, options Options) (err error) { 75 err = stack.Serialize.Add(&awsRestjson1_serializeOpGetUsageStatistics{}, middleware.After) 76 if err != nil { 77 return err 78 } 79 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpGetUsageStatistics{}, middleware.After) 80 if err != nil { 81 return err 82 } 83 if err = addSetLoggerMiddleware(stack, options); err != nil { 84 return err 85 } 86 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 87 return err 88 } 89 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 90 return err 91 } 92 if err = addResolveEndpointMiddleware(stack, options); err != nil { 93 return err 94 } 95 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 96 return err 97 } 98 if err = addRetryMiddlewares(stack, options); err != nil { 99 return err 100 } 101 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 102 return err 103 } 104 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 105 return err 106 } 107 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 108 return err 109 } 110 if err = addClientUserAgent(stack); err != nil { 111 return err 112 } 113 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 114 return err 115 } 116 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 117 return err 118 } 119 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetUsageStatistics(options.Region), middleware.Before); err != nil { 120 return err 121 } 122 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addResponseErrorMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addRequestResponseLogging(stack, options); err != nil { 129 return err 130 } 131 return nil 132} 133 134// GetUsageStatisticsAPIClient is a client that implements the GetUsageStatistics 135// operation. 136type GetUsageStatisticsAPIClient interface { 137 GetUsageStatistics(context.Context, *GetUsageStatisticsInput, ...func(*Options)) (*GetUsageStatisticsOutput, error) 138} 139 140var _ GetUsageStatisticsAPIClient = (*Client)(nil) 141 142// GetUsageStatisticsPaginatorOptions is the paginator options for 143// GetUsageStatistics 144type GetUsageStatisticsPaginatorOptions struct { 145 // The maximum number of items to include in each page of the response. 146 Limit int32 147 148 // Set to true if pagination should stop if the service returns a pagination token 149 // that matches the most recent token provided to the service. 150 StopOnDuplicateToken bool 151} 152 153// GetUsageStatisticsPaginator is a paginator for GetUsageStatistics 154type GetUsageStatisticsPaginator struct { 155 options GetUsageStatisticsPaginatorOptions 156 client GetUsageStatisticsAPIClient 157 params *GetUsageStatisticsInput 158 nextToken *string 159 firstPage bool 160} 161 162// NewGetUsageStatisticsPaginator returns a new GetUsageStatisticsPaginator 163func NewGetUsageStatisticsPaginator(client GetUsageStatisticsAPIClient, params *GetUsageStatisticsInput, optFns ...func(*GetUsageStatisticsPaginatorOptions)) *GetUsageStatisticsPaginator { 164 if params == nil { 165 params = &GetUsageStatisticsInput{} 166 } 167 168 options := GetUsageStatisticsPaginatorOptions{} 169 if params.MaxResults != 0 { 170 options.Limit = params.MaxResults 171 } 172 173 for _, fn := range optFns { 174 fn(&options) 175 } 176 177 return &GetUsageStatisticsPaginator{ 178 options: options, 179 client: client, 180 params: params, 181 firstPage: true, 182 } 183} 184 185// HasMorePages returns a boolean indicating whether more pages are available 186func (p *GetUsageStatisticsPaginator) HasMorePages() bool { 187 return p.firstPage || p.nextToken != nil 188} 189 190// NextPage retrieves the next GetUsageStatistics page. 191func (p *GetUsageStatisticsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetUsageStatisticsOutput, error) { 192 if !p.HasMorePages() { 193 return nil, fmt.Errorf("no more pages available") 194 } 195 196 params := *p.params 197 params.NextToken = p.nextToken 198 199 params.MaxResults = p.options.Limit 200 201 result, err := p.client.GetUsageStatistics(ctx, ¶ms, optFns...) 202 if err != nil { 203 return nil, err 204 } 205 p.firstPage = false 206 207 prevToken := p.nextToken 208 p.nextToken = result.NextToken 209 210 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 211 p.nextToken = nil 212 } 213 214 return result, nil 215} 216 217func newServiceMetadataMiddleware_opGetUsageStatistics(region string) *awsmiddleware.RegisterServiceMetadata { 218 return &awsmiddleware.RegisterServiceMetadata{ 219 Region: region, 220 ServiceID: ServiceID, 221 SigningName: "macie2", 222 OperationName: "GetUsageStatistics", 223 } 224} 225