1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package wafregional
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/wafregional/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// This is AWS WAF Classic documentation. For more information, see AWS WAF Classic
15// (https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html)
16// in the developer guide. For the latest version of AWS WAF, use the AWS WAFV2 API
17// and see the AWS WAF Developer Guide
18// (https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html). With
19// the latest version, AWS WAF has a single set of endpoints for regional and
20// global use. Inserts or deletes Predicate objects in a rule and updates the
21// RateLimit in the rule. Each Predicate object identifies a predicate, such as a
22// ByteMatchSet or an IPSet, that specifies the web requests that you want to block
23// or count. The RateLimit specifies the number of requests every five minutes that
24// triggers the rule. If you add more than one predicate to a RateBasedRule, a
25// request must match all the predicates and exceed the RateLimit to be counted or
26// blocked. For example, suppose you add the following to a RateBasedRule:
27//
28// * An
29// IPSet that matches the IP address 192.0.2.44/32
30//
31// * A ByteMatchSet that matches
32// BadBot in the User-Agent header
33//
34// Further, you specify a RateLimit of 1,000. You
35// then add the RateBasedRule to a WebACL and specify that you want to block
36// requests that satisfy the rule. For a request to be blocked, it must come from
37// the IP address 192.0.2.44 and the User-Agent header in the request must contain
38// the value BadBot. Further, requests that match these two conditions much be
39// received at a rate of more than 1,000 every five minutes. If the rate drops
40// below this limit, AWS WAF no longer blocks the requests. As a second example,
41// suppose you want to limit requests to a particular page on your site. To do
42// this, you could add the following to a RateBasedRule:
43//
44// * A ByteMatchSet with
45// FieldToMatch of URI
46//
47// * A PositionalConstraint of STARTS_WITH
48//
49// * A TargetString
50// of login
51//
52// Further, you specify a RateLimit of 1,000. By adding this
53// RateBasedRule to a WebACL, you could limit requests to your login page without
54// affecting the rest of your site.
55func (c *Client) UpdateRateBasedRule(ctx context.Context, params *UpdateRateBasedRuleInput, optFns ...func(*Options)) (*UpdateRateBasedRuleOutput, error) {
56	if params == nil {
57		params = &UpdateRateBasedRuleInput{}
58	}
59
60	result, metadata, err := c.invokeOperation(ctx, "UpdateRateBasedRule", params, optFns, addOperationUpdateRateBasedRuleMiddlewares)
61	if err != nil {
62		return nil, err
63	}
64
65	out := result.(*UpdateRateBasedRuleOutput)
66	out.ResultMetadata = metadata
67	return out, nil
68}
69
70type UpdateRateBasedRuleInput struct {
71
72	// The value returned by the most recent call to GetChangeToken.
73	//
74	// This member is required.
75	ChangeToken *string
76
77	// The maximum number of requests, which have an identical value in the field
78	// specified by the RateKey, allowed in a five-minute period. If the number of
79	// requests exceeds the RateLimit and the other predicates specified in the rule
80	// are also met, AWS WAF triggers the action that is specified for this rule.
81	//
82	// This member is required.
83	RateLimit int64
84
85	// The RuleId of the RateBasedRule that you want to update. RuleId is returned by
86	// CreateRateBasedRule and by ListRateBasedRules.
87	//
88	// This member is required.
89	RuleId *string
90
91	// An array of RuleUpdate objects that you want to insert into or delete from a
92	// RateBasedRule.
93	//
94	// This member is required.
95	Updates []types.RuleUpdate
96}
97
98type UpdateRateBasedRuleOutput struct {
99
100	// The ChangeToken that you used to submit the UpdateRateBasedRule request. You can
101	// also use this value to query the status of the request. For more information,
102	// see GetChangeTokenStatus.
103	ChangeToken *string
104
105	// Metadata pertaining to the operation's result.
106	ResultMetadata middleware.Metadata
107}
108
109func addOperationUpdateRateBasedRuleMiddlewares(stack *middleware.Stack, options Options) (err error) {
110	err = stack.Serialize.Add(&awsAwsjson11_serializeOpUpdateRateBasedRule{}, middleware.After)
111	if err != nil {
112		return err
113	}
114	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpUpdateRateBasedRule{}, middleware.After)
115	if err != nil {
116		return err
117	}
118	if err = addSetLoggerMiddleware(stack, options); err != nil {
119		return err
120	}
121	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
122		return err
123	}
124	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addResolveEndpointMiddleware(stack, options); err != nil {
128		return err
129	}
130	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
131		return err
132	}
133	if err = addRetryMiddlewares(stack, options); err != nil {
134		return err
135	}
136	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
137		return err
138	}
139	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
140		return err
141	}
142	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
143		return err
144	}
145	if err = addClientUserAgent(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
149		return err
150	}
151	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
152		return err
153	}
154	if err = addOpUpdateRateBasedRuleValidationMiddleware(stack); err != nil {
155		return err
156	}
157	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opUpdateRateBasedRule(options.Region), middleware.Before); err != nil {
158		return err
159	}
160	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
161		return err
162	}
163	if err = addResponseErrorMiddleware(stack); err != nil {
164		return err
165	}
166	if err = addRequestResponseLogging(stack, options); err != nil {
167		return err
168	}
169	return nil
170}
171
172func newServiceMetadataMiddleware_opUpdateRateBasedRule(region string) *awsmiddleware.RegisterServiceMetadata {
173	return &awsmiddleware.RegisterServiceMetadata{
174		Region:        region,
175		ServiceID:     ServiceID,
176		SigningName:   "waf-regional",
177		OperationName: "UpdateRateBasedRule",
178	}
179}
180