Container for the parameters to the CreateRule operation. Creates a Rule, which contains the IPSet objects, ByteMatchSet objects, and other predicates that identify the requests that you want to block. If you add more than one predicate to a Rule, a request must match all of the specifications to be allowed or blocked. For example, suppose you add the following to a Rule:
  • An IPSet that matches the IP address 192.0.2.44/32

  • A ByteMatchSet that matches BadBot in the User-Agent header

You then add the Rule to a WebACL and specify that you want to blocks requests that satisfy the Rule. For a request to be blocked, it must come from the IP address 192.0.2.44 and the User-Agent header in the request must contain the value BadBot.

To create and configure a Rule, perform the following steps:

  1. Create and update the predicates that you want to include in the Rule. For more information, see CreateByteMatchSet, CreateIPSet, and CreateSqlInjectionMatchSet.

  2. Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of a CreateRule request.

  3. Submit a CreateRule request.

  4. Use GetChangeToken to get the change token that you provide in the ChangeToken parameter of an UpdateRule request.

  5. Submit an UpdateRule request to specify the predicates that you want to include in the Rule.

  6. Create and update a WebACL that contains the Rule. For more information, see CreateWebACL.

For more information about how to use the AWS WAF API to allow or block HTTP requests, see the AWS WAF Developer Guide.

Наследование: AmazonWAFRequest
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.WAF.Model.CreateRuleRequest();

            if (cmdletContext.ChangeToken != null)
            {
                request.ChangeToken = cmdletContext.ChangeToken;
            }
            if (cmdletContext.MetricName != null)
            {
                request.MetricName = cmdletContext.MetricName;
            }
            if (cmdletContext.Name != null)
            {
                request.Name = cmdletContext.Name;
            }
            if (cmdletContext.Tag != null)
            {
                request.Tags = cmdletContext.Tag;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Initiates the asynchronous execution of the CreateRule operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateRule operation on AmazonWAFClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateRule
        ///         operation.</returns>
        public IAsyncResult BeginCreateRule(CreateRuleRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new CreateRuleRequestMarshaller();
            var unmarshaller = CreateRuleResponseUnmarshaller.Instance;

            return BeginInvoke<CreateRuleRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
Пример #3
0
        /// <summary>
        /// Creates a <code>Rule</code>, which contains the <code>IPSet</code> objects, <code>ByteMatchSet</code>
        /// objects, and other predicates that identify the requests that you want to block. If
        /// you add more than one predicate to a <code>Rule</code>, a request must match all of
        /// the specifications to be allowed or blocked. For example, suppose you add the following
        /// to a <code>Rule</code>:
        /// 
        ///  <ul> <li>An <code>IPSet</code> that matches the IP address <code>192.0.2.44/32</code>
        /// </li> <li>A <code>ByteMatchSet</code> that matches <code>BadBot</code> in the <code>User-Agent</code>
        /// header</li> </ul> 
        /// <para>
        /// You then add the <code>Rule</code> to a <code>WebACL</code> and specify that you want
        /// to blocks requests that satisfy the <code>Rule</code>. For a request to be blocked,
        /// it must come from the IP address 192.0.2.44 <i>and</i> the <code>User-Agent</code>
        /// header in the request must contain the value <code>BadBot</code>.
        /// </para>
        ///  
        /// <para>
        /// To create and configure a <code>Rule</code>, perform the following steps:
        /// </para>
        ///  <ol> <li>Create and update the predicates that you want to include in the <code>Rule</code>.
        /// For more information, see <a>CreateByteMatchSet</a>, <a>CreateIPSet</a>, and <a>CreateSqlInjectionMatchSet</a>.</li>
        /// <li>Use <a>GetChangeToken</a> to get the change token that you provide in the <code>ChangeToken</code>
        /// parameter of a <code>CreateRule</code> request.</li> <li>Submit a <code>CreateRule</code>
        /// request.</li> <li>Use <code>GetChangeToken</code> to get the change token that you
        /// provide in the <code>ChangeToken</code> parameter of an <a>UpdateRule</a> request.</li>
        /// <li>Submit an <code>UpdateRule</code> request to specify the predicates that you want
        /// to include in the <code>Rule</code>.</li> <li>Create and update a <code>WebACL</code>
        /// that contains the <code>Rule</code>. For more information, see <a>CreateWebACL</a>.</li>
        /// </ol> 
        /// <para>
        /// For more information about how to use the AWS WAF API to allow or block HTTP requests,
        /// see the <a href="http://docs.aws.amazon.com/waf/latest/developerguide/">AWS WAF Developer
        /// Guide</a>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the CreateRule service method.</param>
        /// 
        /// <returns>The response from the CreateRule service method, as returned by WAF.</returns>
        /// <exception cref="Amazon.WAF.Model.WAFDisallowedNameException">
        /// The name specified is invalid.
        /// </exception>
        /// <exception cref="Amazon.WAF.Model.WAFInternalErrorException">
        /// The operation failed because of a system problem, even though the request was valid.
        /// Retry your request.
        /// </exception>
        /// <exception cref="Amazon.WAF.Model.WAFInvalidParameterException">
        /// The operation failed because AWS WAF didn't recognize a parameter in the request.
        /// For example:
        /// 
        ///  <ul> <li>You specified an invalid parameter name.</li> <li>You specified an invalid
        /// value.</li> <li>You tried to update an object (<code>ByteMatchSet</code>, <code>IPSet</code>,
        /// <code>Rule</code>, or <code>WebACL</code>) using an action other than <code>INSERT</code>
        /// or <code>DELETE</code>.</li> <li>You tried to create a <code>WebACL</code> with a
        /// <code>DefaultAction</code> <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>,
        /// or <code>COUNT</code>.</li> <li>You tried to update a <code>WebACL</code> with a <code>WafAction</code>
        /// <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>, or <code>COUNT</code>.</li>
        /// <li>You tried to update a <code>ByteMatchSet</code> with a <code>FieldToMatch</code>
        /// <code>Type</code> other than HEADER, QUERY_STRING, or URI.</li> <li>You tried to update
        /// a <code>ByteMatchSet</code> with a <code>Field</code> of <code>HEADER</code> but no
        /// value for <code>Data</code>.</li> </ul>
        /// </exception>
        /// <exception cref="Amazon.WAF.Model.WAFLimitsExceededException">
        /// The operation exceeds a resource limit, for example, the maximum number of <code>WebACL</code>
        /// objects that you can create for an AWS account. For more information, see <a href="http://docs.aws.amazon.com/waf/latest/DeveloperGuide/limits.html">Limits</a>
        /// in the <i>AWS WAF Developer Guide</i>.
        /// </exception>
        /// <exception cref="Amazon.WAF.Model.WAFStaleDataException">
        /// The operation failed because you tried to create, update, or delete an object by using
        /// a change token that has already been used.
        /// </exception>
        public CreateRuleResponse CreateRule(CreateRuleRequest request)
        {
            var marshaller = new CreateRuleRequestMarshaller();
            var unmarshaller = CreateRuleResponseUnmarshaller.Instance;

            return Invoke<CreateRuleRequest,CreateRuleResponse>(request, marshaller, unmarshaller);
        }
Пример #4
0
 /// <summary>
 /// Creates a <code>Rule</code>, which contains the <code>IPSet</code> objects, <code>ByteMatchSet</code>
 /// objects, and other predicates that identify the requests that you want to block. If
 /// you add more than one predicate to a <code>Rule</code>, a request must match all of
 /// the specifications to be allowed or blocked. For example, suppose you add the following
 /// to a <code>Rule</code>:
 /// 
 ///  <ul> <li>An <code>IPSet</code> that matches the IP address <code>192.0.2.44/32</code>
 /// </li> <li>A <code>ByteMatchSet</code> that matches <code>BadBot</code> in the <code>User-Agent</code>
 /// header</li> </ul> 
 /// <para>
 /// You then add the <code>Rule</code> to a <code>WebACL</code> and specify that you want
 /// to blocks requests that satisfy the <code>Rule</code>. For a request to be blocked,
 /// it must come from the IP address 192.0.2.44 <i>and</i> the <code>User-Agent</code>
 /// header in the request must contain the value <code>BadBot</code>.
 /// </para>
 ///  
 /// <para>
 /// To create and configure a <code>Rule</code>, perform the following steps:
 /// </para>
 ///  <ol> <li>Create and update the predicates that you want to include in the <code>Rule</code>.
 /// For more information, see <a>CreateByteMatchSet</a>, <a>CreateIPSet</a>, and <a>CreateSqlInjectionMatchSet</a>.</li>
 /// <li>Use <a>GetChangeToken</a> to get the change token that you provide in the <code>ChangeToken</code>
 /// parameter of a <code>CreateRule</code> request.</li> <li>Submit a <code>CreateRule</code>
 /// request.</li> <li>Use <code>GetChangeToken</code> to get the change token that you
 /// provide in the <code>ChangeToken</code> parameter of an <a>UpdateRule</a> request.</li>
 /// <li>Submit an <code>UpdateRule</code> request to specify the predicates that you want
 /// to include in the <code>Rule</code>.</li> <li>Create and update a <code>WebACL</code>
 /// that contains the <code>Rule</code>. For more information, see <a>CreateWebACL</a>.</li>
 /// </ol> 
 /// <para>
 /// For more information about how to use the AWS WAF API to allow or block HTTP requests,
 /// see the <a href="http://docs.aws.amazon.com/waf/latest/developerguide/">AWS WAF Developer
 /// Guide</a>.
 /// </para>
 /// </summary>
 /// <param name="name">A friendly name or description of the <a>Rule</a>. You can't change the name of a <code>Rule</code> after you create it.</param>
 /// <param name="changeToken">The value returned by the most recent call to <a>GetChangeToken</a>.</param>
 /// <param name="metricName">A friendly name or description for the metrics for this <code>Rule</code>. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace. You can't change the name of the metric after you create the <code>Rule</code>.</param>
 /// 
 /// <returns>The response from the CreateRule service method, as returned by WAF.</returns>
 /// <exception cref="Amazon.WAF.Model.WAFDisallowedNameException">
 /// The name specified is invalid.
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFInternalErrorException">
 /// The operation failed because of a system problem, even though the request was valid.
 /// Retry your request.
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFInvalidParameterException">
 /// The operation failed because AWS WAF didn't recognize a parameter in the request.
 /// For example:
 /// 
 ///  <ul> <li>You specified an invalid parameter name.</li> <li>You specified an invalid
 /// value.</li> <li>You tried to update an object (<code>ByteMatchSet</code>, <code>IPSet</code>,
 /// <code>Rule</code>, or <code>WebACL</code>) using an action other than <code>INSERT</code>
 /// or <code>DELETE</code>.</li> <li>You tried to create a <code>WebACL</code> with a
 /// <code>DefaultAction</code> <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>,
 /// or <code>COUNT</code>.</li> <li>You tried to update a <code>WebACL</code> with a <code>WafAction</code>
 /// <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>, or <code>COUNT</code>.</li>
 /// <li>You tried to update a <code>ByteMatchSet</code> with a <code>FieldToMatch</code>
 /// <code>Type</code> other than HEADER, QUERY_STRING, or URI.</li> <li>You tried to update
 /// a <code>ByteMatchSet</code> with a <code>Field</code> of <code>HEADER</code> but no
 /// value for <code>Data</code>.</li> </ul>
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFLimitsExceededException">
 /// The operation exceeds a resource limit, for example, the maximum number of <code>WebACL</code>
 /// objects that you can create for an AWS account. For more information, see <a href="http://docs.aws.amazon.com/waf/latest/DeveloperGuide/limits.html">Limits</a>
 /// in the <i>AWS WAF Developer Guide</i>.
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFStaleDataException">
 /// The operation failed because you tried to create, update, or delete an object by using
 /// a change token that has already been used.
 /// </exception>
 public CreateRuleResponse CreateRule(string name, string changeToken, string metricName)
 {
     var request = new CreateRuleRequest();
     request.Name = name;
     request.ChangeToken = changeToken;
     request.MetricName = metricName;
     return CreateRule(request);
 }
Пример #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the CreateRule operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the CreateRule operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<CreateRuleResponse> CreateRuleAsync(CreateRuleRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new CreateRuleRequestMarshaller();
            var unmarshaller = CreateRuleResponseUnmarshaller.Instance;

            return InvokeAsync<CreateRuleRequest,CreateRuleResponse>(request, marshaller,
                unmarshaller, cancellationToken);
        }
Пример #6
0
 /// <summary>
 /// Creates a <code>Rule</code>, which contains the <code>IPSet</code> objects, <code>ByteMatchSet</code>
 /// objects, and other predicates that identify the requests that you want to block. If
 /// you add more than one predicate to a <code>Rule</code>, a request must match all of
 /// the specifications to be allowed or blocked. For example, suppose you add the following
 /// to a <code>Rule</code>:
 /// 
 ///  <ul> <li>An <code>IPSet</code> that matches the IP address <code>192.0.2.44/32</code></li>
 /// <li>A <code>ByteMatchSet</code> that matches <code>BadBot</code> in the <code>User-Agent</code>
 /// header</li> </ul> 
 /// <para>
 /// You then add the <code>Rule</code> to a <code>WebACL</code> and specify that you want
 /// to blocks requests that satisfy the <code>Rule</code>. For a request to be blocked,
 /// it must come from the IP address 192.0.2.44 <i>and</i> the <code>User-Agent</code>
 /// header in the request must contain the value <code>BadBot</code>.
 /// </para>
 ///  
 /// <para>
 /// To create and configure a <code>Rule</code>, perform the following steps:
 /// </para>
 ///  <ol> <li>Create and update the predicates that you want to include in the <code>Rule</code>.
 /// For more information, see <a>CreateByteMatchSet</a>, <a>CreateIPSet</a>, and <a>CreateSqlInjectionMatchSet</a>.</li>
 /// <li>Use <a>GetChangeToken</a> to get the change token that you provide in the <code>ChangeToken</code>
 /// parameter of a <code>CreateRule</code> request.</li> <li>Submit a <code>CreateRule</code>
 /// request.</li> <li>Use <code>GetChangeToken</code> to get the change token that you
 /// provide in the <code>ChangeToken</code> parameter of an <a>UpdateRule</a> request.</li>
 /// <li>Submit an <code>UpdateRule</code> request to specify the predicates that you want
 /// to include in the <code>Rule</code>.</li> <li>Create and update a <code>WebACL</code>
 /// that contains the <code>Rule</code>. For more information, see <a>CreateWebACL</a>.</li>
 /// </ol> 
 /// <para>
 /// For more information about how to use the AWS WAF API to allow or block HTTP requests,
 /// see the <a href="http://docs.aws.amazon.com/waf/latest/developerguide/">AWS WAF Developer
 /// Guide</a>.
 /// </para>
 /// </summary>
 /// <param name="name">A friendly name or description of the <a>Rule</a>. You can't change the name of a <code>Rule</code> after you create it.</param>
 /// <param name="changeToken">The value returned by the most recent call to <a>GetChangeToken</a>.</param>
 /// <param name="metricName">A friendly name or description for the metrics for this <code>Rule</code>. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace. You can't change the name of the metric after you create the <code>Rule</code>.</param>
 /// <param name="cancellationToken">
 ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// 
 /// <returns>The response from the CreateRule service method, as returned by WAF.</returns>
 /// <exception cref="Amazon.WAF.Model.WAFDisallowedNameException">
 /// The name specified is invalid.
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFInternalErrorException">
 /// The operation failed because of a system problem, even though the request was valid.
 /// Retry your request.
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFInvalidParameterException">
 /// The operation failed because AWS WAF didn't recognize a parameter in the request.
 /// For example:
 /// 
 ///  <ul> <li>You specified an invalid parameter name.</li> <li>You specified an invalid
 /// value.</li> <li>You tried to update an object (<code>ByteMatchSet</code>, <code>IPSet</code>,
 /// <code>Rule</code>, or <code>WebACL</code>) using an action other than <code>INSERT</code>
 /// or <code>DELETE</code>.</li> <li>You tried to create a <code>WebACL</code> with a
 /// <code>DefaultAction</code> <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>,
 /// or <code>COUNT</code>.</li> <li>You tried to update a <code>WebACL</code> with a <code>WafAction</code>
 /// <code>Type</code> other than <code>ALLOW</code>, <code>BLOCK</code>, or <code>COUNT</code>.</li>
 /// <li>You tried to update a <code>ByteMatchSet</code> with a <code>FieldToMatch</code>
 /// <code>Type</code> other than HEADER, QUERY_STRING, or URI.</li> <li>You tried to update
 /// a <code>ByteMatchSet</code> with a <code>Field</code> of <code>HEADER</code> but no
 /// value for <code>Data</code>.</li> </ul>
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFLimitsExceededException">
 /// The operation exceeds a resource limit, for example, the maximum number of <code>WebACL</code>
 /// objects that you can create for an AWS account. For more information, see <a href="http://docs.aws.amazon.com/waf/latest/developerguide/limits.html">Limits</a>
 /// in the <i>AWS WAF Developer Guide</i>.
 /// </exception>
 /// <exception cref="Amazon.WAF.Model.WAFStaleDataException">
 /// The operation failed because you tried to create, update, or delete an object by using
 /// a change token that has already been used.
 /// </exception>
 public Task<CreateRuleResponse> CreateRuleAsync(string name, string changeToken, string metricName, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new CreateRuleRequest();
     request.Name = name;
     request.ChangeToken = changeToken;
     request.MetricName = metricName;
     return CreateRuleAsync(request, cancellationToken);
 }
 private Amazon.WAF.Model.CreateRuleResponse CallAWSServiceOperation(IAmazonWAF client, Amazon.WAF.Model.CreateRuleRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS WAF", "CreateRule");
     try
     {
         #if DESKTOP
         return(client.CreateRule(request));
         #elif CORECLR
         return(client.CreateRuleAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }