1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package resourcegroups 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/resourcegroups/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of AWS resource identifiers that matches the specified query. The 16// query uses the same format as a resource query in a CreateGroup or 17// UpdateGroupQuery operation. Minimum permissions To run this command, you must 18// have the following permissions: 19// 20// * resource-groups:SearchResources 21func (c *Client) SearchResources(ctx context.Context, params *SearchResourcesInput, optFns ...func(*Options)) (*SearchResourcesOutput, error) { 22 if params == nil { 23 params = &SearchResourcesInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "SearchResources", params, optFns, addOperationSearchResourcesMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*SearchResourcesOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type SearchResourcesInput struct { 37 38 // The search query, using the same formats that are supported for resource group 39 // definition. For more information, see CreateGroup. 40 // 41 // This member is required. 42 ResourceQuery *types.ResourceQuery 43 44 // The total number of results that you want included on each page of the response. 45 // If you do not include this parameter, it defaults to a value that is specific to 46 // the operation. If additional items exist beyond the maximum you specify, the 47 // NextToken response element is present and has a value (is not null). Include 48 // that value as the NextToken request parameter in the next call to the operation 49 // to get the next part of the results. Note that the service might return fewer 50 // results than the maximum even when there are more results available. You should 51 // check NextToken after every operation to ensure that you receive all of the 52 // results. 53 MaxResults *int32 54 55 // The parameter for receiving additional results if you receive a NextToken 56 // response in a previous request. A NextToken response indicates that more output 57 // is available. Set this parameter to the value provided by a previous call's 58 // NextToken response to indicate where the output should continue from. 59 NextToken *string 60} 61 62type SearchResourcesOutput struct { 63 64 // If present, indicates that more output is available than is included in the 65 // current response. Use this value in the NextToken request parameter in a 66 // subsequent call to the operation to get the next part of the output. You should 67 // repeat this until the NextToken response element comes back as null. 68 NextToken *string 69 70 // A list of QueryError objects. Each error is an object that contains ErrorCode 71 // and Message structures. Possible values for ErrorCode are 72 // CLOUDFORMATION_STACK_INACTIVE and CLOUDFORMATION_STACK_NOT_EXISTING. 73 QueryErrors []types.QueryError 74 75 // The ARNs and resource types of resources that are members of the group that you 76 // specified. 77 ResourceIdentifiers []types.ResourceIdentifier 78 79 // Metadata pertaining to the operation's result. 80 ResultMetadata middleware.Metadata 81} 82 83func addOperationSearchResourcesMiddlewares(stack *middleware.Stack, options Options) (err error) { 84 err = stack.Serialize.Add(&awsRestjson1_serializeOpSearchResources{}, middleware.After) 85 if err != nil { 86 return err 87 } 88 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpSearchResources{}, middleware.After) 89 if err != nil { 90 return err 91 } 92 if err = addSetLoggerMiddleware(stack, options); err != nil { 93 return err 94 } 95 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 96 return err 97 } 98 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 99 return err 100 } 101 if err = addResolveEndpointMiddleware(stack, options); err != nil { 102 return err 103 } 104 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 105 return err 106 } 107 if err = addRetryMiddlewares(stack, options); err != nil { 108 return err 109 } 110 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 111 return err 112 } 113 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 114 return err 115 } 116 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 117 return err 118 } 119 if err = addClientUserAgent(stack); err != nil { 120 return err 121 } 122 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 123 return err 124 } 125 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addOpSearchResourcesValidationMiddleware(stack); err != nil { 129 return err 130 } 131 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchResources(options.Region), middleware.Before); err != nil { 132 return err 133 } 134 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 135 return err 136 } 137 if err = addResponseErrorMiddleware(stack); err != nil { 138 return err 139 } 140 if err = addRequestResponseLogging(stack, options); err != nil { 141 return err 142 } 143 return nil 144} 145 146// SearchResourcesAPIClient is a client that implements the SearchResources 147// operation. 148type SearchResourcesAPIClient interface { 149 SearchResources(context.Context, *SearchResourcesInput, ...func(*Options)) (*SearchResourcesOutput, error) 150} 151 152var _ SearchResourcesAPIClient = (*Client)(nil) 153 154// SearchResourcesPaginatorOptions is the paginator options for SearchResources 155type SearchResourcesPaginatorOptions struct { 156 // The total number of results that you want included on each page of the response. 157 // If you do not include this parameter, it defaults to a value that is specific to 158 // the operation. If additional items exist beyond the maximum you specify, the 159 // NextToken response element is present and has a value (is not null). Include 160 // that value as the NextToken request parameter in the next call to the operation 161 // to get the next part of the results. Note that the service might return fewer 162 // results than the maximum even when there are more results available. You should 163 // check NextToken after every operation to ensure that you receive all of the 164 // results. 165 Limit int32 166 167 // Set to true if pagination should stop if the service returns a pagination token 168 // that matches the most recent token provided to the service. 169 StopOnDuplicateToken bool 170} 171 172// SearchResourcesPaginator is a paginator for SearchResources 173type SearchResourcesPaginator struct { 174 options SearchResourcesPaginatorOptions 175 client SearchResourcesAPIClient 176 params *SearchResourcesInput 177 nextToken *string 178 firstPage bool 179} 180 181// NewSearchResourcesPaginator returns a new SearchResourcesPaginator 182func NewSearchResourcesPaginator(client SearchResourcesAPIClient, params *SearchResourcesInput, optFns ...func(*SearchResourcesPaginatorOptions)) *SearchResourcesPaginator { 183 if params == nil { 184 params = &SearchResourcesInput{} 185 } 186 187 options := SearchResourcesPaginatorOptions{} 188 if params.MaxResults != nil { 189 options.Limit = *params.MaxResults 190 } 191 192 for _, fn := range optFns { 193 fn(&options) 194 } 195 196 return &SearchResourcesPaginator{ 197 options: options, 198 client: client, 199 params: params, 200 firstPage: true, 201 } 202} 203 204// HasMorePages returns a boolean indicating whether more pages are available 205func (p *SearchResourcesPaginator) HasMorePages() bool { 206 return p.firstPage || p.nextToken != nil 207} 208 209// NextPage retrieves the next SearchResources page. 210func (p *SearchResourcesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchResourcesOutput, error) { 211 if !p.HasMorePages() { 212 return nil, fmt.Errorf("no more pages available") 213 } 214 215 params := *p.params 216 params.NextToken = p.nextToken 217 218 var limit *int32 219 if p.options.Limit > 0 { 220 limit = &p.options.Limit 221 } 222 params.MaxResults = limit 223 224 result, err := p.client.SearchResources(ctx, ¶ms, optFns...) 225 if err != nil { 226 return nil, err 227 } 228 p.firstPage = false 229 230 prevToken := p.nextToken 231 p.nextToken = result.NextToken 232 233 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 234 p.nextToken = nil 235 } 236 237 return result, nil 238} 239 240func newServiceMetadataMiddleware_opSearchResources(region string) *awsmiddleware.RegisterServiceMetadata { 241 return &awsmiddleware.RegisterServiceMetadata{ 242 Region: region, 243 ServiceID: ServiceID, 244 SigningName: "resource-groups", 245 OperationName: "SearchResources", 246 } 247} 248