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// Information about one or more Traffic Mirror targets.
16func (c *Client) DescribeTrafficMirrorTargets(ctx context.Context, params *DescribeTrafficMirrorTargetsInput, optFns ...func(*Options)) (*DescribeTrafficMirrorTargetsOutput, error) {
17	if params == nil {
18		params = &DescribeTrafficMirrorTargetsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "DescribeTrafficMirrorTargets", params, optFns, addOperationDescribeTrafficMirrorTargetsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*DescribeTrafficMirrorTargetsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type DescribeTrafficMirrorTargetsInput struct {
32
33	// Checks whether you have the required permissions for the action, without
34	// actually making the request, and provides an error response. If you have the
35	// required permissions, the error response is DryRunOperation. Otherwise, it is
36	// UnauthorizedOperation.
37	DryRun bool
38
39	// One or more filters. The possible values are:
40	//
41	// * description: The Traffic Mirror
42	// target description.
43	//
44	// * network-interface-id: The ID of the Traffic Mirror
45	// session network interface.
46	//
47	// * network-load-balancer-arn: The Amazon Resource
48	// Name (ARN) of the Network Load Balancer that is associated with the session.
49	//
50	// *
51	// owner-id: The ID of the account that owns the Traffic Mirror session.
52	//
53	// *
54	// traffic-mirror-target-id: The ID of the Traffic Mirror target.
55	Filters []types.Filter
56
57	// The maximum number of results to return with a single call. To retrieve the
58	// remaining results, make another call with the returned nextToken value.
59	MaxResults int32
60
61	// The token for the next page of results.
62	NextToken *string
63
64	// The ID of the Traffic Mirror targets.
65	TrafficMirrorTargetIds []string
66}
67
68type DescribeTrafficMirrorTargetsOutput struct {
69
70	// The token to use to retrieve the next page of results. The value is null when
71	// there are no more results to return.
72	NextToken *string
73
74	// Information about one or more Traffic Mirror targets.
75	TrafficMirrorTargets []types.TrafficMirrorTarget
76
77	// Metadata pertaining to the operation's result.
78	ResultMetadata middleware.Metadata
79}
80
81func addOperationDescribeTrafficMirrorTargetsMiddlewares(stack *middleware.Stack, options Options) (err error) {
82	err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeTrafficMirrorTargets{}, middleware.After)
83	if err != nil {
84		return err
85	}
86	err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeTrafficMirrorTargets{}, middleware.After)
87	if err != nil {
88		return err
89	}
90	if err = addSetLoggerMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
97		return err
98	}
99	if err = addResolveEndpointMiddleware(stack, options); err != nil {
100		return err
101	}
102	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
103		return err
104	}
105	if err = addRetryMiddlewares(stack, options); err != nil {
106		return err
107	}
108	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
112		return err
113	}
114	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
115		return err
116	}
117	if err = addClientUserAgent(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
124		return err
125	}
126	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeTrafficMirrorTargets(options.Region), middleware.Before); err != nil {
127		return err
128	}
129	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addResponseErrorMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addRequestResponseLogging(stack, options); err != nil {
136		return err
137	}
138	return nil
139}
140
141// DescribeTrafficMirrorTargetsAPIClient is a client that implements the
142// DescribeTrafficMirrorTargets operation.
143type DescribeTrafficMirrorTargetsAPIClient interface {
144	DescribeTrafficMirrorTargets(context.Context, *DescribeTrafficMirrorTargetsInput, ...func(*Options)) (*DescribeTrafficMirrorTargetsOutput, error)
145}
146
147var _ DescribeTrafficMirrorTargetsAPIClient = (*Client)(nil)
148
149// DescribeTrafficMirrorTargetsPaginatorOptions is the paginator options for
150// DescribeTrafficMirrorTargets
151type DescribeTrafficMirrorTargetsPaginatorOptions struct {
152	// The maximum number of results to return with a single call. To retrieve the
153	// remaining results, make another call with the returned nextToken value.
154	Limit int32
155
156	// Set to true if pagination should stop if the service returns a pagination token
157	// that matches the most recent token provided to the service.
158	StopOnDuplicateToken bool
159}
160
161// DescribeTrafficMirrorTargetsPaginator is a paginator for
162// DescribeTrafficMirrorTargets
163type DescribeTrafficMirrorTargetsPaginator struct {
164	options   DescribeTrafficMirrorTargetsPaginatorOptions
165	client    DescribeTrafficMirrorTargetsAPIClient
166	params    *DescribeTrafficMirrorTargetsInput
167	nextToken *string
168	firstPage bool
169}
170
171// NewDescribeTrafficMirrorTargetsPaginator returns a new
172// DescribeTrafficMirrorTargetsPaginator
173func NewDescribeTrafficMirrorTargetsPaginator(client DescribeTrafficMirrorTargetsAPIClient, params *DescribeTrafficMirrorTargetsInput, optFns ...func(*DescribeTrafficMirrorTargetsPaginatorOptions)) *DescribeTrafficMirrorTargetsPaginator {
174	options := DescribeTrafficMirrorTargetsPaginatorOptions{}
175	if params.MaxResults != 0 {
176		options.Limit = params.MaxResults
177	}
178
179	for _, fn := range optFns {
180		fn(&options)
181	}
182
183	if params == nil {
184		params = &DescribeTrafficMirrorTargetsInput{}
185	}
186
187	return &DescribeTrafficMirrorTargetsPaginator{
188		options:   options,
189		client:    client,
190		params:    params,
191		firstPage: true,
192	}
193}
194
195// HasMorePages returns a boolean indicating whether more pages are available
196func (p *DescribeTrafficMirrorTargetsPaginator) HasMorePages() bool {
197	return p.firstPage || p.nextToken != nil
198}
199
200// NextPage retrieves the next DescribeTrafficMirrorTargets page.
201func (p *DescribeTrafficMirrorTargetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeTrafficMirrorTargetsOutput, error) {
202	if !p.HasMorePages() {
203		return nil, fmt.Errorf("no more pages available")
204	}
205
206	params := *p.params
207	params.NextToken = p.nextToken
208
209	params.MaxResults = p.options.Limit
210
211	result, err := p.client.DescribeTrafficMirrorTargets(ctx, &params, optFns...)
212	if err != nil {
213		return nil, err
214	}
215	p.firstPage = false
216
217	prevToken := p.nextToken
218	p.nextToken = result.NextToken
219
220	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
221		p.nextToken = nil
222	}
223
224	return result, nil
225}
226
227func newServiceMetadataMiddleware_opDescribeTrafficMirrorTargets(region string) *awsmiddleware.RegisterServiceMetadata {
228	return &awsmiddleware.RegisterServiceMetadata{
229		Region:        region,
230		ServiceID:     ServiceID,
231		SigningName:   "ec2",
232		OperationName: "DescribeTrafficMirrorTargets",
233	}
234}
235