Skip to content

generate_rule_configuration async

generate_rule_configuration(
    prompt: SensitiveString,
    rule_firewall_type: RuleFirewallType,
    rule_type: RuleType,
    *,
    config_overrides: Optional[AsyncNetworkSecurityManagerClientConfig] = None,
    waf_config_data_type: Optional[WAFConfigDataType] = None,
    current_configuration: Optional[str] = None,
    client_token: Optional[IdempotencyToken] = None,
) -> GenerateRuleConfigurationResponse

Generates a rule configuration from a natural-language description. Provide a prompt along with the rule's firewall type and rule type. The service returns a configuration that you can use when you create or update a rule. If you also provide an existing configuration, the service edits that configuration instead of generating a new one.

Parameters:

  • prompt (SensitiveString) –

    A natural-language description of the configuration that you want to generate.

  • rule_firewall_type (RuleFirewallType) –

    The firewall type of the rule.

  • rule_type (RuleType) –

    The type of the rule. CONFIGURATION rules contain firewall settings, and INSPECTION rules contain rule groups.

  • waf_config_data_type (Optional[WAFConfigDataType], default: None ) –

    For AWS WAF configuration rules, the specific AWS WAF configuration variant to generate. This is optional; if you omit it, the service selects the variant.

  • current_configuration (Optional[str], default: None ) –

    An existing configuration to edit, as a JSON string. When you provide this value, the operation edits the configuration. When you omit it, the operation generates a new configuration.

  • client_token (Optional[IdempotencyToken], default: None ) –

    A unique, case-sensitive token that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service returns the result of the original successful request.

Raises:

  • AccessDeniedException –

    You do not have sufficient permissions to perform this action.

  • InternalServerException –

    The request processing failed because of an internal error in the service. This is a retryable error.

  • ThrottlingException –

    The request was denied because of request throttling. Reduce your request rate and try again.

  • ValidationException –

    The request failed validation. For details, see the reason and fieldList members of the response.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Generate a rule configuration from a description Generates a firewall rule configuration from a natural language description. The response contains the generated configuration as a JSON string, ready to use as the configuration of a rule.

>>> await client.generate_rule_configuration(prompt='Create a rate limiting rule that blocks IP addresses sending more than 2000 requests in 5 minutes', rule_firewall_type='WAF', rule_type='INSPECTION', client_token='550e8400-e29b-41d4-a716-446655440015')
Source code in docs_src/capo_network_security_manager/_services/async_network_security_manager.py
async def generate_rule_configuration(
    self,
    prompt: "capo_network_security_manager.types.sensitive_string.SensitiveString",
    rule_firewall_type: "capo_network_security_manager.types.rule_firewall_type.RuleFirewallType",
    rule_type: "capo_network_security_manager.types.rule_type.RuleType",
    *,
    config_overrides: Optional[AsyncNetworkSecurityManagerClientConfig] = None,
    waf_config_data_type: Optional[
        "capo_network_security_manager.types.waf_config_data_type.WAFConfigDataType"
    ] = None,
    current_configuration: Optional[str] = None,
    client_token: Optional[
        "capo_network_security_manager.types.idempotency_token.IdempotencyToken"
    ] = None,
) -> "capo_network_security_manager.types.generate_rule_configuration_response.GenerateRuleConfigurationResponse":
    """<p>Generates a rule configuration from a natural-language description. Provide a prompt along with the rule's firewall type and rule type. The service returns a configuration that you can use when you create or update a rule. If you also provide an existing configuration, the service edits that configuration instead of generating a new one.</p>

    Args:
        prompt: <p>A natural-language description of the configuration that you want to generate.</p>
        rule_firewall_type: <p>The firewall type of the rule.</p>
        rule_type: <p>The type of the rule. <code>CONFIGURATION</code> rules contain firewall settings, and <code>INSPECTION</code> rules contain rule groups.</p>
        waf_config_data_type: <p>For AWS WAF configuration rules, the specific AWS WAF configuration variant to generate. This is optional; if you omit it, the service selects the variant.</p>
        current_configuration: <p>An existing configuration to edit, as a JSON string. When you provide this value, the operation edits the configuration. When you omit it, the operation generates a new configuration.</p>
        client_token: <p>A unique, case-sensitive token that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service returns the result of the original successful request.</p>

    Raises:
        capo_network_security_manager.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient permissions to perform this action.</p>
        capo_network_security_manager.errors.internal_server_exception.InternalServerException: <p>The request processing failed because of an internal error in the service. This is a retryable error.</p>
        capo_network_security_manager.errors.throttling_exception.ThrottlingException: <p>The request was denied because of request throttling. Reduce your request rate and try again.</p>
        capo_network_security_manager.errors.validation_exception.ValidationException: <p>The request failed validation. For details, see the <code>reason</code> and <code>fieldList</code> members of the response.</p>
        capo_network_security_manager.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Generate a rule configuration from a description
        Generates a firewall rule configuration from a natural language description. The response contains the generated configuration as a JSON string, ready to use as the configuration of a rule.

        >>> await client.generate_rule_configuration(prompt='Create a rate limiting rule that blocks IP addresses sending more than 2000 requests in 5 minutes', rule_firewall_type='WAF', rule_type='INSPECTION', client_token='550e8400-e29b-41d4-a716-446655440015')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_network_security_manager.types.generate_rule_configuration_request.GenerateRuleConfigurationRequest]",
    ) -> AsyncOperationResponse[
        "capo_network_security_manager.types.generate_rule_configuration_response.GenerateRuleConfigurationResponse"
    ]:
        import capo_network_security_manager._operations.piccolo_customer_api_service.generate_rule_configuration

        (
            output,
            http_response,
        ) = await capo_network_security_manager._operations.piccolo_customer_api_service.generate_rule_configuration.async_generate_rule_configuration(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_network_security_manager.types.generate_rule_configuration_request.GenerateRuleConfigurationRequest",
    ) -> dict[str, Any]:
        import capo_network_security_manager.types.generate_rule_configuration_request

        return capo_network_security_manager.types.generate_rule_configuration_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("GenerateRuleConfiguration", redact_input=_redact_input),
    )
    input_: capo_network_security_manager.types.generate_rule_configuration_request.GenerateRuleConfigurationRequest = {
        "prompt": prompt,
        "rule_firewall_type": rule_firewall_type,
        "rule_type": rule_type,
    }
    if waf_config_data_type is not None:
        input_["waf_config_data_type"] = waf_config_data_type
    if current_configuration is not None:
        input_["current_configuration"] = current_configuration
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output