1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ecrpublic
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/ecrpublic/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Describes repositories in a public registry.
16func (c *Client) DescribeRepositories(ctx context.Context, params *DescribeRepositoriesInput, optFns ...func(*Options)) (*DescribeRepositoriesOutput, error) {
17	if params == nil {
18		params = &DescribeRepositoriesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "DescribeRepositories", params, optFns, c.addOperationDescribeRepositoriesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*DescribeRepositoriesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type DescribeRepositoriesInput struct {
32
33	// The maximum number of repository results returned by DescribeRepositories in
34	// paginated output. When this parameter is used, DescribeRepositories only returns
35	// maxResults results in a single page along with a nextToken response element. The
36	// remaining results of the initial request can be seen by sending another
37	// DescribeRepositories request with the returned nextToken value. This value can
38	// be between 1 and 1000. If this parameter is not used, then DescribeRepositories
39	// returns up to 100 results and a nextToken value, if applicable. This option
40	// cannot be used when you specify repositories with repositoryNames.
41	MaxResults *int32
42
43	// The nextToken value returned from a previous paginated DescribeRepositories
44	// request where maxResults was used and the results exceeded the value of that
45	// parameter. Pagination continues from the end of the previous results that
46	// returned the nextToken value. This value is null when there are no more results
47	// to return. This option cannot be used when you specify repositories with
48	// repositoryNames. This token should be treated as an opaque identifier that is
49	// only used to retrieve the next items in a list and not for other programmatic
50	// purposes.
51	NextToken *string
52
53	// The AWS account ID associated with the registry that contains the repositories
54	// to be described. If you do not specify a registry, the default public registry
55	// is assumed.
56	RegistryId *string
57
58	// A list of repositories to describe. If this parameter is omitted, then all
59	// repositories in a registry are described.
60	RepositoryNames []string
61
62	noSmithyDocumentSerde
63}
64
65type DescribeRepositoriesOutput struct {
66
67	// The nextToken value to include in a future DescribeRepositories request. When
68	// the results of a DescribeRepositories request exceed maxResults, this value can
69	// be used to retrieve the next page of results. This value is null when there are
70	// no more results to return.
71	NextToken *string
72
73	// A list of repository objects corresponding to valid repositories.
74	Repositories []types.Repository
75
76	// Metadata pertaining to the operation's result.
77	ResultMetadata middleware.Metadata
78
79	noSmithyDocumentSerde
80}
81
82func (c *Client) addOperationDescribeRepositoriesMiddlewares(stack *middleware.Stack, options Options) (err error) {
83	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeRepositories{}, middleware.After)
84	if err != nil {
85		return err
86	}
87	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeRepositories{}, middleware.After)
88	if err != nil {
89		return err
90	}
91	if err = addSetLoggerMiddleware(stack, options); err != nil {
92		return err
93	}
94	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
95		return err
96	}
97	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
98		return err
99	}
100	if err = addResolveEndpointMiddleware(stack, options); err != nil {
101		return err
102	}
103	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
104		return err
105	}
106	if err = addRetryMiddlewares(stack, options); err != nil {
107		return err
108	}
109	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
110		return err
111	}
112	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
113		return err
114	}
115	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
116		return err
117	}
118	if err = addClientUserAgent(stack); err != nil {
119		return err
120	}
121	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
122		return err
123	}
124	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
125		return err
126	}
127	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeRepositories(options.Region), middleware.Before); err != nil {
128		return err
129	}
130	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addResponseErrorMiddleware(stack); err != nil {
134		return err
135	}
136	if err = addRequestResponseLogging(stack, options); err != nil {
137		return err
138	}
139	return nil
140}
141
142// DescribeRepositoriesAPIClient is a client that implements the
143// DescribeRepositories operation.
144type DescribeRepositoriesAPIClient interface {
145	DescribeRepositories(context.Context, *DescribeRepositoriesInput, ...func(*Options)) (*DescribeRepositoriesOutput, error)
146}
147
148var _ DescribeRepositoriesAPIClient = (*Client)(nil)
149
150// DescribeRepositoriesPaginatorOptions is the paginator options for
151// DescribeRepositories
152type DescribeRepositoriesPaginatorOptions struct {
153	// The maximum number of repository results returned by DescribeRepositories in
154	// paginated output. When this parameter is used, DescribeRepositories only returns
155	// maxResults results in a single page along with a nextToken response element. The
156	// remaining results of the initial request can be seen by sending another
157	// DescribeRepositories request with the returned nextToken value. This value can
158	// be between 1 and 1000. If this parameter is not used, then DescribeRepositories
159	// returns up to 100 results and a nextToken value, if applicable. This option
160	// cannot be used when you specify repositories with repositoryNames.
161	Limit int32
162
163	// Set to true if pagination should stop if the service returns a pagination token
164	// that matches the most recent token provided to the service.
165	StopOnDuplicateToken bool
166}
167
168// DescribeRepositoriesPaginator is a paginator for DescribeRepositories
169type DescribeRepositoriesPaginator struct {
170	options   DescribeRepositoriesPaginatorOptions
171	client    DescribeRepositoriesAPIClient
172	params    *DescribeRepositoriesInput
173	nextToken *string
174	firstPage bool
175}
176
177// NewDescribeRepositoriesPaginator returns a new DescribeRepositoriesPaginator
178func NewDescribeRepositoriesPaginator(client DescribeRepositoriesAPIClient, params *DescribeRepositoriesInput, optFns ...func(*DescribeRepositoriesPaginatorOptions)) *DescribeRepositoriesPaginator {
179	if params == nil {
180		params = &DescribeRepositoriesInput{}
181	}
182
183	options := DescribeRepositoriesPaginatorOptions{}
184	if params.MaxResults != nil {
185		options.Limit = *params.MaxResults
186	}
187
188	for _, fn := range optFns {
189		fn(&options)
190	}
191
192	return &DescribeRepositoriesPaginator{
193		options:   options,
194		client:    client,
195		params:    params,
196		firstPage: true,
197	}
198}
199
200// HasMorePages returns a boolean indicating whether more pages are available
201func (p *DescribeRepositoriesPaginator) HasMorePages() bool {
202	return p.firstPage || p.nextToken != nil
203}
204
205// NextPage retrieves the next DescribeRepositories page.
206func (p *DescribeRepositoriesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeRepositoriesOutput, error) {
207	if !p.HasMorePages() {
208		return nil, fmt.Errorf("no more pages available")
209	}
210
211	params := *p.params
212	params.NextToken = p.nextToken
213
214	var limit *int32
215	if p.options.Limit > 0 {
216		limit = &p.options.Limit
217	}
218	params.MaxResults = limit
219
220	result, err := p.client.DescribeRepositories(ctx, &params, optFns...)
221	if err != nil {
222		return nil, err
223	}
224	p.firstPage = false
225
226	prevToken := p.nextToken
227	p.nextToken = result.NextToken
228
229	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
230		p.nextToken = nil
231	}
232
233	return result, nil
234}
235
236func newServiceMetadataMiddleware_opDescribeRepositories(region string) *awsmiddleware.RegisterServiceMetadata {
237	return &awsmiddleware.RegisterServiceMetadata{
238		Region:        region,
239		ServiceID:     ServiceID,
240		SigningName:   "ecr-public",
241		OperationName: "DescribeRepositories",
242	}
243}
244