1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package opsworkscm 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/opsworkscm/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of tags that are applied to the specified AWS OpsWorks for Chef 16// Automate or AWS OpsWorks for Puppet Enterprise servers or backups. 17func (c *Client) ListTagsForResource(ctx context.Context, params *ListTagsForResourceInput, optFns ...func(*Options)) (*ListTagsForResourceOutput, error) { 18 if params == nil { 19 params = &ListTagsForResourceInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListTagsForResource", params, optFns, addOperationListTagsForResourceMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListTagsForResourceOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListTagsForResourceInput struct { 33 34 // The Amazon Resource Number (ARN) of an AWS OpsWorks for Chef Automate or AWS 35 // OpsWorks for Puppet Enterprise server for which you want to show applied tags. 36 // For example, 37 // arn:aws:opsworks-cm:us-west-2:123456789012:server/test-owcm-server/EXAMPLE-66b0-4196-8274-d1a2bEXAMPLE. 38 // 39 // This member is required. 40 ResourceArn *string 41 42 // To receive a paginated response, use this parameter to specify the maximum 43 // number of results to be returned with a single call. If the number of available 44 // results exceeds this maximum, the response includes a NextToken value that you 45 // can assign to the NextToken request parameter to get the next set of results. 46 MaxResults *int32 47 48 // NextToken is a string that is returned in some command responses. It indicates 49 // that not all entries have been returned, and that you must run at least one more 50 // request to get remaining items. To get remaining results, call 51 // ListTagsForResource again, and assign the token from the previous results as the 52 // value of the nextToken parameter. If there are no more results, the response 53 // object's nextToken parameter value is null. Setting a nextToken value that was 54 // not returned in your previous results causes an InvalidNextTokenException to 55 // occur. 56 NextToken *string 57} 58 59type ListTagsForResourceOutput struct { 60 61 // A token that you can use as the value of NextToken in subsequent calls to the 62 // API to show more results. 63 NextToken *string 64 65 // Tags that have been applied to the resource. 66 Tags []types.Tag 67 68 // Metadata pertaining to the operation's result. 69 ResultMetadata middleware.Metadata 70} 71 72func addOperationListTagsForResourceMiddlewares(stack *middleware.Stack, options Options) (err error) { 73 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListTagsForResource{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListTagsForResource{}, middleware.After) 78 if err != nil { 79 return err 80 } 81 if err = addSetLoggerMiddleware(stack, options); err != nil { 82 return err 83 } 84 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 85 return err 86 } 87 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 88 return err 89 } 90 if err = addResolveEndpointMiddleware(stack, options); err != nil { 91 return err 92 } 93 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 94 return err 95 } 96 if err = addRetryMiddlewares(stack, options); err != nil { 97 return err 98 } 99 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 103 return err 104 } 105 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 106 return err 107 } 108 if err = addClientUserAgent(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 115 return err 116 } 117 if err = addOpListTagsForResourceValidationMiddleware(stack); err != nil { 118 return err 119 } 120 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListTagsForResource(options.Region), middleware.Before); err != nil { 121 return err 122 } 123 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 124 return err 125 } 126 if err = addResponseErrorMiddleware(stack); err != nil { 127 return err 128 } 129 if err = addRequestResponseLogging(stack, options); err != nil { 130 return err 131 } 132 return nil 133} 134 135// ListTagsForResourceAPIClient is a client that implements the ListTagsForResource 136// operation. 137type ListTagsForResourceAPIClient interface { 138 ListTagsForResource(context.Context, *ListTagsForResourceInput, ...func(*Options)) (*ListTagsForResourceOutput, error) 139} 140 141var _ ListTagsForResourceAPIClient = (*Client)(nil) 142 143// ListTagsForResourcePaginatorOptions is the paginator options for 144// ListTagsForResource 145type ListTagsForResourcePaginatorOptions struct { 146 // To receive a paginated response, use this parameter to specify the maximum 147 // number of results to be returned with a single call. If the number of available 148 // results exceeds this maximum, the response includes a NextToken value that you 149 // can assign to the NextToken request parameter to get the next set of results. 150 Limit int32 151 152 // Set to true if pagination should stop if the service returns a pagination token 153 // that matches the most recent token provided to the service. 154 StopOnDuplicateToken bool 155} 156 157// ListTagsForResourcePaginator is a paginator for ListTagsForResource 158type ListTagsForResourcePaginator struct { 159 options ListTagsForResourcePaginatorOptions 160 client ListTagsForResourceAPIClient 161 params *ListTagsForResourceInput 162 nextToken *string 163 firstPage bool 164} 165 166// NewListTagsForResourcePaginator returns a new ListTagsForResourcePaginator 167func NewListTagsForResourcePaginator(client ListTagsForResourceAPIClient, params *ListTagsForResourceInput, optFns ...func(*ListTagsForResourcePaginatorOptions)) *ListTagsForResourcePaginator { 168 if params == nil { 169 params = &ListTagsForResourceInput{} 170 } 171 172 options := ListTagsForResourcePaginatorOptions{} 173 if params.MaxResults != nil { 174 options.Limit = *params.MaxResults 175 } 176 177 for _, fn := range optFns { 178 fn(&options) 179 } 180 181 return &ListTagsForResourcePaginator{ 182 options: options, 183 client: client, 184 params: params, 185 firstPage: true, 186 } 187} 188 189// HasMorePages returns a boolean indicating whether more pages are available 190func (p *ListTagsForResourcePaginator) HasMorePages() bool { 191 return p.firstPage || p.nextToken != nil 192} 193 194// NextPage retrieves the next ListTagsForResource page. 195func (p *ListTagsForResourcePaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListTagsForResourceOutput, error) { 196 if !p.HasMorePages() { 197 return nil, fmt.Errorf("no more pages available") 198 } 199 200 params := *p.params 201 params.NextToken = p.nextToken 202 203 var limit *int32 204 if p.options.Limit > 0 { 205 limit = &p.options.Limit 206 } 207 params.MaxResults = limit 208 209 result, err := p.client.ListTagsForResource(ctx, ¶ms, optFns...) 210 if err != nil { 211 return nil, err 212 } 213 p.firstPage = false 214 215 prevToken := p.nextToken 216 p.nextToken = result.NextToken 217 218 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 219 p.nextToken = nil 220 } 221 222 return result, nil 223} 224 225func newServiceMetadataMiddleware_opListTagsForResource(region string) *awsmiddleware.RegisterServiceMetadata { 226 return &awsmiddleware.RegisterServiceMetadata{ 227 Region: region, 228 ServiceID: ServiceID, 229 SigningName: "opsworks-cm", 230 OperationName: "ListTagsForResource", 231 } 232} 233