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 all the tagged or previously tagged resources that are located in the
16// specified Region for the AWS account. Depending on what information you want
17// returned, you can also specify the following:
18//
19// * Filters that specify what tags
20// and resource types you want returned. The response includes all tags that are
21// associated with the requested resources.
22//
23// * Information about compliance with
24// the account's effective tag policy. For more information on tag policies, see
25// Tag Policies
26// (https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html)
27// in the AWS Organizations User Guide.
28//
29// This operation supports pagination, where
30// the response can be sent in multiple pages. You should check the PaginationToken
31// response parameter to determine if there are additional results available to
32// return. Repeat the query, passing the PaginationToken response parameter value
33// as an input to the next request until you recieve a null value. A null value for
34// PaginationToken indicates that there are no more results waiting to be returned.
35func (c *Client) GetResources(ctx context.Context, params *GetResourcesInput, optFns ...func(*Options)) (*GetResourcesOutput, error) {
36	if params == nil {
37		params = &GetResourcesInput{}
38	}
39
40	result, metadata, err := c.invokeOperation(ctx, "GetResources", params, optFns, addOperationGetResourcesMiddlewares)
41	if err != nil {
42		return nil, err
43	}
44
45	out := result.(*GetResourcesOutput)
46	out.ResultMetadata = metadata
47	return out, nil
48}
49
50type GetResourcesInput struct {
51
52	// Specifies whether to exclude resources that are compliant with the tag policy.
53	// Set this to true if you are interested in retrieving information on noncompliant
54	// resources only. You can use this parameter only if the IncludeComplianceDetails
55	// parameter is also set to true.
56	ExcludeCompliantResources *bool
57
58	// Specifies whether to include details regarding the compliance with the effective
59	// tag policy. Set this to true to determine whether resources are compliant with
60	// the tag policy and to get details.
61	IncludeComplianceDetails *bool
62
63	// Specifies a PaginationToken response value from a previous request to indicate
64	// that you want the next page of results. Leave this parameter empty in your
65	// initial request.
66	PaginationToken *string
67
68	// Specifies a list of ARNs of resources for which you want to retrieve tag data.
69	// You can't specify both this parameter and any of the pagination parameters
70	// (ResourcesPerPage, TagsPerPage, PaginationToken) in the same request. If you
71	// specify both, you get an Invalid Parameter exception. If a resource specified by
72	// this parameter doesn't exist, it doesn't generate an error; it simply isn't
73	// included in the response. An ARN (Amazon Resource Name) uniquely identifies a
74	// resource. For more information, see Amazon Resource Names (ARNs) and AWS Service
75	// Namespaces
76	// (http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) in
77	// the AWS General Reference.
78	ResourceARNList []string
79
80	// Specifies the resource types that you want included in the response. The format
81	// of each resource type is service[:resourceType]. For example, specifying a
82	// resource type of ec2 returns all Amazon EC2 resources (which includes EC2
83	// instances). Specifying a resource type of ec2:instance returns only EC2
84	// instances. The string for each service name and resource type is the same as
85	// that embedded in a resource's Amazon Resource Name (ARN). Consult the AWS
86	// General Reference for the following: For more information about ARNs, see Amazon
87	// Resource Names (ARNs) and AWS Service Namespaces
88	// (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html).
89	// You can specify multiple resource types by using an array. The array can include
90	// up to 100 items. Note that the length constraint requirement applies to each
91	// resource type filter.
92	ResourceTypeFilters []string
93
94	// Specifies the maximum number of results to be returned in each page. A query can
95	// return fewer than this maximum, even if there are more results still to return.
96	// You should always check the PaginationToken response value to see if there are
97	// more results. You can specify a minimum of 1 and a maximum value of 100.
98	ResourcesPerPage *int32
99
100	// Specifies a list of TagFilters (keys and values) to restrict the output to only
101	// those resources that have the specified tag and, if included, the specified
102	// value. Each TagFilter must contain a key with values optional. A request can
103	// include up to 50 keys, and each key can include up to 20 values. Note the
104	// following when deciding how to use TagFilters:
105	//
106	// * If you don't specify a
107	// TagFilter, the response includes all resources that are currently tagged or ever
108	// had a tag. Resources that currently don't have tags are shown with an empty tag
109	// set, like this: "Tags": [].
110	//
111	// * If you specify more than one filter in a single
112	// request, the response returns only those resources that satisfy all filters.
113	//
114	// *
115	// If you specify a filter that contains more than one value for a key, the
116	// response returns resources that match any of the specified values for that
117	// key.
118	//
119	// * If you don't specify any values for a key, the response returns
120	// resources that are tagged with that key and any or no value. For example, for
121	// the following filters: filter1= {keyA,{value1}},
122	// filter2={keyB,{value2,value3,value4}}, filter3= {keyC}:
123	//
124	// *
125	// GetResources({filter1}) returns resources tagged with key1=value1
126	//
127	// *
128	// GetResources({filter2}) returns resources tagged with key2=value2 or key2=value3
129	// or key2=value4
130	//
131	// * GetResources({filter3}) returns resources tagged with any tag
132	// with the key key3, and with any or no value
133	//
134	// *
135	// GetResources({filter1,filter2,filter3}) returns resources tagged with
136	// (key1=value1) and (key2=value2 or key2=value3 or key2=value4) and (key3, any or
137	// no value)
138	TagFilters []types.TagFilter
139
140	// AWS recommends using ResourcesPerPage instead of this parameter. A limit that
141	// restricts the number of tags (key and value pairs) returned by GetResources in
142	// paginated output. A resource with no tags is counted as having one tag (one key
143	// and value pair). GetResources does not split a resource and its associated tags
144	// across pages. If the specified TagsPerPage would cause such a break, a
145	// PaginationToken is returned in place of the affected resource and its tags. Use
146	// that token in another request to get the remaining data. For example, if you
147	// specify a TagsPerPage of 100 and the account has 22 resources with 10 tags each
148	// (meaning that each resource has 10 key and value pairs), the output will consist
149	// of three pages. The first page displays the first 10 resources, each with its 10
150	// tags. The second page displays the next 10 resources, each with its 10 tags. The
151	// third page displays the remaining 2 resources, each with its 10 tags. You can
152	// set TagsPerPage to a minimum of 100 items up to a maximum of 500 items.
153	TagsPerPage *int32
154}
155
156type GetResourcesOutput struct {
157
158	// A string that indicates that there is more data available than this response
159	// contains. To receive the next part of the response, specify this response value
160	// as the PaginationToken value in the request for the next page.
161	PaginationToken *string
162
163	// A list of resource ARNs and the tags (keys and values) associated with those
164	// ARNs.
165	ResourceTagMappingList []types.ResourceTagMapping
166
167	// Metadata pertaining to the operation's result.
168	ResultMetadata middleware.Metadata
169}
170
171func addOperationGetResourcesMiddlewares(stack *middleware.Stack, options Options) (err error) {
172	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetResources{}, middleware.After)
173	if err != nil {
174		return err
175	}
176	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetResources{}, middleware.After)
177	if err != nil {
178		return err
179	}
180	if err = addSetLoggerMiddleware(stack, options); err != nil {
181		return err
182	}
183	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
184		return err
185	}
186	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
187		return err
188	}
189	if err = addResolveEndpointMiddleware(stack, options); err != nil {
190		return err
191	}
192	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
193		return err
194	}
195	if err = addRetryMiddlewares(stack, options); err != nil {
196		return err
197	}
198	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
199		return err
200	}
201	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
202		return err
203	}
204	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
205		return err
206	}
207	if err = addClientUserAgent(stack); err != nil {
208		return err
209	}
210	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
211		return err
212	}
213	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
214		return err
215	}
216	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetResources(options.Region), middleware.Before); err != nil {
217		return err
218	}
219	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
220		return err
221	}
222	if err = addResponseErrorMiddleware(stack); err != nil {
223		return err
224	}
225	if err = addRequestResponseLogging(stack, options); err != nil {
226		return err
227	}
228	return nil
229}
230
231// GetResourcesAPIClient is a client that implements the GetResources operation.
232type GetResourcesAPIClient interface {
233	GetResources(context.Context, *GetResourcesInput, ...func(*Options)) (*GetResourcesOutput, error)
234}
235
236var _ GetResourcesAPIClient = (*Client)(nil)
237
238// GetResourcesPaginatorOptions is the paginator options for GetResources
239type GetResourcesPaginatorOptions struct {
240	// Specifies the maximum number of results to be returned in each page. A query can
241	// return fewer than this maximum, even if there are more results still to return.
242	// You should always check the PaginationToken response value to see if there are
243	// more results. You can specify a minimum of 1 and a maximum value of 100.
244	Limit int32
245
246	// Set to true if pagination should stop if the service returns a pagination token
247	// that matches the most recent token provided to the service.
248	StopOnDuplicateToken bool
249}
250
251// GetResourcesPaginator is a paginator for GetResources
252type GetResourcesPaginator struct {
253	options   GetResourcesPaginatorOptions
254	client    GetResourcesAPIClient
255	params    *GetResourcesInput
256	nextToken *string
257	firstPage bool
258}
259
260// NewGetResourcesPaginator returns a new GetResourcesPaginator
261func NewGetResourcesPaginator(client GetResourcesAPIClient, params *GetResourcesInput, optFns ...func(*GetResourcesPaginatorOptions)) *GetResourcesPaginator {
262	if params == nil {
263		params = &GetResourcesInput{}
264	}
265
266	options := GetResourcesPaginatorOptions{}
267	if params.ResourcesPerPage != nil {
268		options.Limit = *params.ResourcesPerPage
269	}
270
271	for _, fn := range optFns {
272		fn(&options)
273	}
274
275	return &GetResourcesPaginator{
276		options:   options,
277		client:    client,
278		params:    params,
279		firstPage: true,
280	}
281}
282
283// HasMorePages returns a boolean indicating whether more pages are available
284func (p *GetResourcesPaginator) HasMorePages() bool {
285	return p.firstPage || p.nextToken != nil
286}
287
288// NextPage retrieves the next GetResources page.
289func (p *GetResourcesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetResourcesOutput, error) {
290	if !p.HasMorePages() {
291		return nil, fmt.Errorf("no more pages available")
292	}
293
294	params := *p.params
295	params.PaginationToken = p.nextToken
296
297	var limit *int32
298	if p.options.Limit > 0 {
299		limit = &p.options.Limit
300	}
301	params.ResourcesPerPage = limit
302
303	result, err := p.client.GetResources(ctx, &params, optFns...)
304	if err != nil {
305		return nil, err
306	}
307	p.firstPage = false
308
309	prevToken := p.nextToken
310	p.nextToken = result.PaginationToken
311
312	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
313		p.nextToken = nil
314	}
315
316	return result, nil
317}
318
319func newServiceMetadataMiddleware_opGetResources(region string) *awsmiddleware.RegisterServiceMetadata {
320	return &awsmiddleware.RegisterServiceMetadata{
321		Region:        region,
322		ServiceID:     ServiceID,
323		SigningName:   "tagging",
324		OperationName: "GetResources",
325	}
326}
327