1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package route53resolver
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/route53resolver/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Retrieves the firewall rules that you have defined for the specified firewall
16// rule group. DNS Firewall uses the rules in a rule group to filter DNS network
17// traffic for a VPC. A single call might return only a partial list of the rules.
18// For information, see MaxResults.
19func (c *Client) ListFirewallRules(ctx context.Context, params *ListFirewallRulesInput, optFns ...func(*Options)) (*ListFirewallRulesOutput, error) {
20	if params == nil {
21		params = &ListFirewallRulesInput{}
22	}
23
24	result, metadata, err := c.invokeOperation(ctx, "ListFirewallRules", params, optFns, addOperationListFirewallRulesMiddlewares)
25	if err != nil {
26		return nil, err
27	}
28
29	out := result.(*ListFirewallRulesOutput)
30	out.ResultMetadata = metadata
31	return out, nil
32}
33
34type ListFirewallRulesInput struct {
35
36	// The unique identifier of the firewall rule group that you want to retrieve the
37	// rules for.
38	//
39	// This member is required.
40	FirewallRuleGroupId *string
41
42	// Optional additional filter for the rules to retrieve. The action that DNS
43	// Firewall should take on a DNS query when it matches one of the domains in the
44	// rule's domain list:
45	//
46	// * ALLOW - Permit the request to go through.
47	//
48	// * ALERT -
49	// Permit the request to go through but send an alert to the logs.
50	//
51	// * BLOCK -
52	// Disallow the request. If this is specified, additional handling details are
53	// provided in the rule's BlockResponse setting.
54	Action types.Action
55
56	// The maximum number of objects that you want Resolver to return for this request.
57	// If more objects are available, in the response, Resolver provides a NextToken
58	// value that you can use in a subsequent call to get the next batch of objects. If
59	// you don't specify a value for MaxResults, Resolver returns up to 100 objects.
60	MaxResults *int32
61
62	// For the first call to this list request, omit this value. When you request a
63	// list of objects, Resolver returns at most the number of objects specified in
64	// MaxResults. If more objects are available for retrieval, Resolver returns a
65	// NextToken value in the response. To retrieve the next batch of objects, use the
66	// token that was returned for the prior request in your next request.
67	NextToken *string
68
69	// Optional additional filter for the rules to retrieve. The setting that
70	// determines the processing order of the rules in a rule group. DNS Firewall
71	// processes the rules in a rule group by order of priority, starting from the
72	// lowest setting.
73	Priority *int32
74}
75
76type ListFirewallRulesOutput struct {
77
78	// A list of the rules that you have defined. This might be a parital list of the
79	// firewall rules that you've defined. For information, see MaxResults.
80	FirewallRules []types.FirewallRule
81
82	// If objects are still available for retrieval, Resolver returns this token in the
83	// response. To retrieve the next batch of objects, provide this token in your next
84	// request.
85	NextToken *string
86
87	// Metadata pertaining to the operation's result.
88	ResultMetadata middleware.Metadata
89}
90
91func addOperationListFirewallRulesMiddlewares(stack *middleware.Stack, options Options) (err error) {
92	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListFirewallRules{}, middleware.After)
93	if err != nil {
94		return err
95	}
96	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListFirewallRules{}, middleware.After)
97	if err != nil {
98		return err
99	}
100	if err = addSetLoggerMiddleware(stack, options); err != nil {
101		return err
102	}
103	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
104		return err
105	}
106	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
107		return err
108	}
109	if err = addResolveEndpointMiddleware(stack, options); err != nil {
110		return err
111	}
112	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
113		return err
114	}
115	if err = addRetryMiddlewares(stack, options); err != nil {
116		return err
117	}
118	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
119		return err
120	}
121	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
122		return err
123	}
124	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
125		return err
126	}
127	if err = addClientUserAgent(stack); err != nil {
128		return err
129	}
130	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
131		return err
132	}
133	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
134		return err
135	}
136	if err = addOpListFirewallRulesValidationMiddleware(stack); err != nil {
137		return err
138	}
139	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListFirewallRules(options.Region), middleware.Before); err != nil {
140		return err
141	}
142	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
143		return err
144	}
145	if err = addResponseErrorMiddleware(stack); err != nil {
146		return err
147	}
148	if err = addRequestResponseLogging(stack, options); err != nil {
149		return err
150	}
151	return nil
152}
153
154// ListFirewallRulesAPIClient is a client that implements the ListFirewallRules
155// operation.
156type ListFirewallRulesAPIClient interface {
157	ListFirewallRules(context.Context, *ListFirewallRulesInput, ...func(*Options)) (*ListFirewallRulesOutput, error)
158}
159
160var _ ListFirewallRulesAPIClient = (*Client)(nil)
161
162// ListFirewallRulesPaginatorOptions is the paginator options for ListFirewallRules
163type ListFirewallRulesPaginatorOptions struct {
164	// The maximum number of objects that you want Resolver to return for this request.
165	// If more objects are available, in the response, Resolver provides a NextToken
166	// value that you can use in a subsequent call to get the next batch of objects. If
167	// you don't specify a value for MaxResults, Resolver returns up to 100 objects.
168	Limit int32
169
170	// Set to true if pagination should stop if the service returns a pagination token
171	// that matches the most recent token provided to the service.
172	StopOnDuplicateToken bool
173}
174
175// ListFirewallRulesPaginator is a paginator for ListFirewallRules
176type ListFirewallRulesPaginator struct {
177	options   ListFirewallRulesPaginatorOptions
178	client    ListFirewallRulesAPIClient
179	params    *ListFirewallRulesInput
180	nextToken *string
181	firstPage bool
182}
183
184// NewListFirewallRulesPaginator returns a new ListFirewallRulesPaginator
185func NewListFirewallRulesPaginator(client ListFirewallRulesAPIClient, params *ListFirewallRulesInput, optFns ...func(*ListFirewallRulesPaginatorOptions)) *ListFirewallRulesPaginator {
186	if params == nil {
187		params = &ListFirewallRulesInput{}
188	}
189
190	options := ListFirewallRulesPaginatorOptions{}
191	if params.MaxResults != nil {
192		options.Limit = *params.MaxResults
193	}
194
195	for _, fn := range optFns {
196		fn(&options)
197	}
198
199	return &ListFirewallRulesPaginator{
200		options:   options,
201		client:    client,
202		params:    params,
203		firstPage: true,
204	}
205}
206
207// HasMorePages returns a boolean indicating whether more pages are available
208func (p *ListFirewallRulesPaginator) HasMorePages() bool {
209	return p.firstPage || p.nextToken != nil
210}
211
212// NextPage retrieves the next ListFirewallRules page.
213func (p *ListFirewallRulesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListFirewallRulesOutput, error) {
214	if !p.HasMorePages() {
215		return nil, fmt.Errorf("no more pages available")
216	}
217
218	params := *p.params
219	params.NextToken = p.nextToken
220
221	var limit *int32
222	if p.options.Limit > 0 {
223		limit = &p.options.Limit
224	}
225	params.MaxResults = limit
226
227	result, err := p.client.ListFirewallRules(ctx, &params, optFns...)
228	if err != nil {
229		return nil, err
230	}
231	p.firstPage = false
232
233	prevToken := p.nextToken
234	p.nextToken = result.NextToken
235
236	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
237		p.nextToken = nil
238	}
239
240	return result, nil
241}
242
243func newServiceMetadataMiddleware_opListFirewallRules(region string) *awsmiddleware.RegisterServiceMetadata {
244	return &awsmiddleware.RegisterServiceMetadata{
245		Region:        region,
246		ServiceID:     ServiceID,
247		SigningName:   "route53resolver",
248		OperationName: "ListFirewallRules",
249	}
250}
251