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