1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package resourcegroupstaggingapi
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/resourcegroupstaggingapi/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a table that shows counts of resources that are noncompliant with their
16// tag policies. For more information on tag policies, see Tag Policies
17// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html)
18// in the AWS Organizations User Guide. You can call this operation only from the
19// organization's management account and from the us-east-1 Region. This operation
20// supports pagination, where the response can be sent in multiple pages. You
21// should check the PaginationToken response parameter to determine if there are
22// additional results available to return. Repeat the query, passing the
23// PaginationToken response parameter value as an input to the next request until
24// you recieve a null value. A null value for PaginationToken indicates that there
25// are no more results waiting to be returned.
26func (c *Client) GetComplianceSummary(ctx context.Context, params *GetComplianceSummaryInput, optFns ...func(*Options)) (*GetComplianceSummaryOutput, error) {
27	if params == nil {
28		params = &GetComplianceSummaryInput{}
29	}
30
31	result, metadata, err := c.invokeOperation(ctx, "GetComplianceSummary", params, optFns, addOperationGetComplianceSummaryMiddlewares)
32	if err != nil {
33		return nil, err
34	}
35
36	out := result.(*GetComplianceSummaryOutput)
37	out.ResultMetadata = metadata
38	return out, nil
39}
40
41type GetComplianceSummaryInput struct {
42
43	// Specifies a list of attributes to group the counts of noncompliant resources by.
44	// If supplied, the counts are sorted by those attributes.
45	GroupBy []types.GroupByAttribute
46
47	// Specifies the maximum number of results to be returned in each page. A query can
48	// return fewer than this maximum, even if there are more results still to return.
49	// You should always check the PaginationToken response value to see if there are
50	// more results. You can specify a minimum of 1 and a maximum value of 100.
51	MaxResults *int32
52
53	// Specifies a PaginationToken response value from a previous request to indicate
54	// that you want the next page of results. Leave this parameter empty in your
55	// initial request.
56	PaginationToken *string
57
58	// Specifies a list of AWS Regions to limit the output by. If you use this
59	// parameter, the count of returned noncompliant resources includes only resources
60	// in the specified Regions.
61	RegionFilters []string
62
63	// Specifies that you want the response to include information for only resources
64	// of the specified types. The format of each resource type is
65	// service[:resourceType]. For example, specifying a resource type of ec2 returns
66	// all Amazon EC2 resources (which includes EC2 instances). Specifying a resource
67	// type of ec2:instance returns only EC2 instances. The string for each service
68	// name and resource type is the same as that embedded in a resource's Amazon
69	// Resource Name (ARN). Consult the AWS General Reference for the following:
70	//
71	// * For
72	// a list of service name strings, see AWS Service Namespaces
73	// (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-aws-service-namespaces).
74	//
75	// *
76	// For resource type strings, see Example ARNs
77	// (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arns-syntax).
78	//
79	// *
80	// For more information about ARNs, see Amazon Resource Names (ARNs) and AWS
81	// Service Namespaces
82	// (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
83	//
84	// You
85	// can specify multiple resource types by using a comma separated array. The array
86	// can include up to 100 items. Note that the length constraint requirement applies
87	// to each resource type filter.
88	ResourceTypeFilters []string
89
90	// Specifies that you want the response to include information for only resources
91	// that have tags with the specified tag keys. If you use this parameter, the count
92	// of returned noncompliant resources includes only resources that have the
93	// specified tag keys.
94	TagKeyFilters []string
95
96	// Specifies target identifiers (usually, specific account IDs) to limit the output
97	// by. If you use this parameter, the count of returned noncompliant resources
98	// includes only resources with the specified target IDs.
99	TargetIdFilters []string
100}
101
102type GetComplianceSummaryOutput struct {
103
104	// A string that indicates that there is more data available than this response
105	// contains. To receive the next part of the response, specify this response value
106	// as the PaginationToken value in the request for the next page.
107	PaginationToken *string
108
109	// A table that shows counts of noncompliant resources.
110	SummaryList []types.Summary
111
112	// Metadata pertaining to the operation's result.
113	ResultMetadata middleware.Metadata
114}
115
116func addOperationGetComplianceSummaryMiddlewares(stack *middleware.Stack, options Options) (err error) {
117	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetComplianceSummary{}, middleware.After)
118	if err != nil {
119		return err
120	}
121	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetComplianceSummary{}, middleware.After)
122	if err != nil {
123		return err
124	}
125	if err = addSetLoggerMiddleware(stack, options); err != nil {
126		return err
127	}
128	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
129		return err
130	}
131	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
132		return err
133	}
134	if err = addResolveEndpointMiddleware(stack, options); err != nil {
135		return err
136	}
137	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
138		return err
139	}
140	if err = addRetryMiddlewares(stack, options); err != nil {
141		return err
142	}
143	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
144		return err
145	}
146	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
147		return err
148	}
149	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
150		return err
151	}
152	if err = addClientUserAgent(stack); err != nil {
153		return err
154	}
155	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
156		return err
157	}
158	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
159		return err
160	}
161	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetComplianceSummary(options.Region), middleware.Before); err != nil {
162		return err
163	}
164	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
165		return err
166	}
167	if err = addResponseErrorMiddleware(stack); err != nil {
168		return err
169	}
170	if err = addRequestResponseLogging(stack, options); err != nil {
171		return err
172	}
173	return nil
174}
175
176// GetComplianceSummaryAPIClient is a client that implements the
177// GetComplianceSummary operation.
178type GetComplianceSummaryAPIClient interface {
179	GetComplianceSummary(context.Context, *GetComplianceSummaryInput, ...func(*Options)) (*GetComplianceSummaryOutput, error)
180}
181
182var _ GetComplianceSummaryAPIClient = (*Client)(nil)
183
184// GetComplianceSummaryPaginatorOptions is the paginator options for
185// GetComplianceSummary
186type GetComplianceSummaryPaginatorOptions struct {
187	// Specifies the maximum number of results to be returned in each page. A query can
188	// return fewer than this maximum, even if there are more results still to return.
189	// You should always check the PaginationToken response value to see if there are
190	// more results. You can specify a minimum of 1 and a maximum value of 100.
191	Limit int32
192
193	// Set to true if pagination should stop if the service returns a pagination token
194	// that matches the most recent token provided to the service.
195	StopOnDuplicateToken bool
196}
197
198// GetComplianceSummaryPaginator is a paginator for GetComplianceSummary
199type GetComplianceSummaryPaginator struct {
200	options   GetComplianceSummaryPaginatorOptions
201	client    GetComplianceSummaryAPIClient
202	params    *GetComplianceSummaryInput
203	nextToken *string
204	firstPage bool
205}
206
207// NewGetComplianceSummaryPaginator returns a new GetComplianceSummaryPaginator
208func NewGetComplianceSummaryPaginator(client GetComplianceSummaryAPIClient, params *GetComplianceSummaryInput, optFns ...func(*GetComplianceSummaryPaginatorOptions)) *GetComplianceSummaryPaginator {
209	if params == nil {
210		params = &GetComplianceSummaryInput{}
211	}
212
213	options := GetComplianceSummaryPaginatorOptions{}
214	if params.MaxResults != nil {
215		options.Limit = *params.MaxResults
216	}
217
218	for _, fn := range optFns {
219		fn(&options)
220	}
221
222	return &GetComplianceSummaryPaginator{
223		options:   options,
224		client:    client,
225		params:    params,
226		firstPage: true,
227	}
228}
229
230// HasMorePages returns a boolean indicating whether more pages are available
231func (p *GetComplianceSummaryPaginator) HasMorePages() bool {
232	return p.firstPage || p.nextToken != nil
233}
234
235// NextPage retrieves the next GetComplianceSummary page.
236func (p *GetComplianceSummaryPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetComplianceSummaryOutput, error) {
237	if !p.HasMorePages() {
238		return nil, fmt.Errorf("no more pages available")
239	}
240
241	params := *p.params
242	params.PaginationToken = p.nextToken
243
244	var limit *int32
245	if p.options.Limit > 0 {
246		limit = &p.options.Limit
247	}
248	params.MaxResults = limit
249
250	result, err := p.client.GetComplianceSummary(ctx, &params, optFns...)
251	if err != nil {
252		return nil, err
253	}
254	p.firstPage = false
255
256	prevToken := p.nextToken
257	p.nextToken = result.PaginationToken
258
259	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
260		p.nextToken = nil
261	}
262
263	return result, nil
264}
265
266func newServiceMetadataMiddleware_opGetComplianceSummary(region string) *awsmiddleware.RegisterServiceMetadata {
267	return &awsmiddleware.RegisterServiceMetadata{
268		Region:        region,
269		ServiceID:     ServiceID,
270		SigningName:   "tagging",
271		OperationName: "GetComplianceSummary",
272	}
273}
274