1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ec2
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/ec2/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Describes the Amazon FPGA Images (AFIs) available to you. These include public
16// AFIs, private AFIs that you own, and AFIs owned by other AWS accounts for which
17// you have load permissions.
18func (c *Client) DescribeFpgaImages(ctx context.Context, params *DescribeFpgaImagesInput, optFns ...func(*Options)) (*DescribeFpgaImagesOutput, error) {
19	if params == nil {
20		params = &DescribeFpgaImagesInput{}
21	}
22
23	result, metadata, err := c.invokeOperation(ctx, "DescribeFpgaImages", params, optFns, addOperationDescribeFpgaImagesMiddlewares)
24	if err != nil {
25		return nil, err
26	}
27
28	out := result.(*DescribeFpgaImagesOutput)
29	out.ResultMetadata = metadata
30	return out, nil
31}
32
33type DescribeFpgaImagesInput struct {
34
35	// Checks whether you have the required permissions for the action, without
36	// actually making the request, and provides an error response. If you have the
37	// required permissions, the error response is DryRunOperation. Otherwise, it is
38	// UnauthorizedOperation.
39	DryRun bool
40
41	// The filters.
42	//
43	// * create-time - The creation time of the AFI.
44	//
45	// * fpga-image-id -
46	// The FPGA image identifier (AFI ID).
47	//
48	// * fpga-image-global-id - The global FPGA
49	// image identifier (AGFI ID).
50	//
51	// * name - The name of the AFI.
52	//
53	// * owner-id - The AWS
54	// account ID of the AFI owner.
55	//
56	// * product-code - The product code.
57	//
58	// *
59	// shell-version - The version of the AWS Shell that was used to create the
60	// bitstream.
61	//
62	// * state - The state of the AFI (pending | failed | available |
63	// unavailable).
64	//
65	// * tag: - The key/value combination of a tag assigned to the
66	// resource. Use the tag key in the filter name and the tag value as the filter
67	// value. For example, to find all resources that have a tag with the key Owner and
68	// the value TeamA, specify tag:Owner for the filter name and TeamA for the filter
69	// value.
70	//
71	// * tag-key - The key of a tag assigned to the resource. Use this filter
72	// to find all resources assigned a tag with a specific key, regardless of the tag
73	// value.
74	//
75	// * update-time - The time of the most recent update.
76	Filters []types.Filter
77
78	// The AFI IDs.
79	FpgaImageIds []string
80
81	// The maximum number of results to return in a single call.
82	MaxResults int32
83
84	// The token to retrieve the next page of results.
85	NextToken *string
86
87	// Filters the AFI by owner. Specify an AWS account ID, self (owner is the sender
88	// of the request), or an AWS owner alias (valid values are amazon |
89	// aws-marketplace).
90	Owners []string
91}
92
93type DescribeFpgaImagesOutput struct {
94
95	// Information about the FPGA images.
96	FpgaImages []types.FpgaImage
97
98	// The token to use to retrieve the next page of results. This value is null when
99	// there are no more results to return.
100	NextToken *string
101
102	// Metadata pertaining to the operation's result.
103	ResultMetadata middleware.Metadata
104}
105
106func addOperationDescribeFpgaImagesMiddlewares(stack *middleware.Stack, options Options) (err error) {
107	err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeFpgaImages{}, middleware.After)
108	if err != nil {
109		return err
110	}
111	err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeFpgaImages{}, middleware.After)
112	if err != nil {
113		return err
114	}
115	if err = addSetLoggerMiddleware(stack, options); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
119		return err
120	}
121	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addResolveEndpointMiddleware(stack, options); err != nil {
125		return err
126	}
127	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
128		return err
129	}
130	if err = addRetryMiddlewares(stack, options); err != nil {
131		return err
132	}
133	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
134		return err
135	}
136	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
137		return err
138	}
139	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
140		return err
141	}
142	if err = addClientUserAgent(stack); err != nil {
143		return err
144	}
145	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
149		return err
150	}
151	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeFpgaImages(options.Region), middleware.Before); err != nil {
152		return err
153	}
154	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
155		return err
156	}
157	if err = addResponseErrorMiddleware(stack); err != nil {
158		return err
159	}
160	if err = addRequestResponseLogging(stack, options); err != nil {
161		return err
162	}
163	return nil
164}
165
166// DescribeFpgaImagesAPIClient is a client that implements the DescribeFpgaImages
167// operation.
168type DescribeFpgaImagesAPIClient interface {
169	DescribeFpgaImages(context.Context, *DescribeFpgaImagesInput, ...func(*Options)) (*DescribeFpgaImagesOutput, error)
170}
171
172var _ DescribeFpgaImagesAPIClient = (*Client)(nil)
173
174// DescribeFpgaImagesPaginatorOptions is the paginator options for
175// DescribeFpgaImages
176type DescribeFpgaImagesPaginatorOptions struct {
177	// The maximum number of results to return in a single call.
178	Limit int32
179
180	// Set to true if pagination should stop if the service returns a pagination token
181	// that matches the most recent token provided to the service.
182	StopOnDuplicateToken bool
183}
184
185// DescribeFpgaImagesPaginator is a paginator for DescribeFpgaImages
186type DescribeFpgaImagesPaginator struct {
187	options   DescribeFpgaImagesPaginatorOptions
188	client    DescribeFpgaImagesAPIClient
189	params    *DescribeFpgaImagesInput
190	nextToken *string
191	firstPage bool
192}
193
194// NewDescribeFpgaImagesPaginator returns a new DescribeFpgaImagesPaginator
195func NewDescribeFpgaImagesPaginator(client DescribeFpgaImagesAPIClient, params *DescribeFpgaImagesInput, optFns ...func(*DescribeFpgaImagesPaginatorOptions)) *DescribeFpgaImagesPaginator {
196	options := DescribeFpgaImagesPaginatorOptions{}
197	if params.MaxResults != 0 {
198		options.Limit = params.MaxResults
199	}
200
201	for _, fn := range optFns {
202		fn(&options)
203	}
204
205	if params == nil {
206		params = &DescribeFpgaImagesInput{}
207	}
208
209	return &DescribeFpgaImagesPaginator{
210		options:   options,
211		client:    client,
212		params:    params,
213		firstPage: true,
214	}
215}
216
217// HasMorePages returns a boolean indicating whether more pages are available
218func (p *DescribeFpgaImagesPaginator) HasMorePages() bool {
219	return p.firstPage || p.nextToken != nil
220}
221
222// NextPage retrieves the next DescribeFpgaImages page.
223func (p *DescribeFpgaImagesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeFpgaImagesOutput, error) {
224	if !p.HasMorePages() {
225		return nil, fmt.Errorf("no more pages available")
226	}
227
228	params := *p.params
229	params.NextToken = p.nextToken
230
231	params.MaxResults = p.options.Limit
232
233	result, err := p.client.DescribeFpgaImages(ctx, &params, optFns...)
234	if err != nil {
235		return nil, err
236	}
237	p.firstPage = false
238
239	prevToken := p.nextToken
240	p.nextToken = result.NextToken
241
242	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
243		p.nextToken = nil
244	}
245
246	return result, nil
247}
248
249func newServiceMetadataMiddleware_opDescribeFpgaImages(region string) *awsmiddleware.RegisterServiceMetadata {
250	return &awsmiddleware.RegisterServiceMetadata{
251		Region:        region,
252		ServiceID:     ServiceID,
253		SigningName:   "ec2",
254		OperationName: "DescribeFpgaImages",
255	}
256}
257