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