AssertCondition 정책

이 페이지는 ApigeeApigee Hybrid에 적용됩니다.

Apigee Edge 문서 보기

개요

AssertCondition 정책은 요청 또는 응답 흐름에서 조건부 문을 평가합니다. 흐름 변수를 기반으로 조건을 정의하고 이 정책을 사용하여 조건을 어설션할 수 있습니다. 조건은 항상 부울 값(true 또는 false)으로 평가됩니다. 조건문 작성에 대한 자세한 내용은 조건 참조를 확인하세요.

조건을 평가한 후 AssertCondition 정책은 assertcondition.policy-name.truthValue 흐름 변수에 평가 결과를 저장합니다. 후속 콜아웃 또는 조정된 로직에서 결과 흐름 변수를 사용할 수 있습니다. 조건이 true로 평가되면 변수 값이 true로 설정되고 그렇지 않으면 false로 설정됩니다. 여러 AssertCondition 정책을 정의한 경우 변수 이름의 policy-name을 통해 변수를 고유하게 식별할 수 있습니다.

이 정책은 표준 정책이며 모든 환경 유형에 배포할 수 있습니다. 정책 유형과 각 환경 유형에서의 가용성에 대한 자세한 내용은 정책 유형을 참조하세요.

<AssertCondition>

<AssertCondition> 정책을 정의합니다. 이 정책을 사용하면 논리 연산자로 연결된 하나 이상의 조건이 있는 조건문을 평가할 수 있습니다. 조건에서 지원되는 모든 연산자에 대한 자세한 내용은 연산자를 참조하세요.

조건문의 결과는 true 또는 false일 수 있는 부울 값입니다.
기본값 해당 사항 없음
필수 여부 필수
유형 복합 유형
상위 요소 해당 사항 없음
하위 요소 <Condition>
<DisplayName>

다음 표에서는 <AssertCondition>의 하위 요소를 간략하게 설명합니다.

하위 요소 필수 여부 설명
<Condition> 평가할 조건을 지정합니다.
<DisplayName> 선택사항 정책의 커스텀 이름입니다.

<AssertCondition> 요소는 다음 구문을 사용합니다.

구문

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssertCondition">
    <!-- Display name for this policy -->
    <DisplayName>DISPLAY_NAME</DisplayName>
    <!-- Assertion's condition where operators are defined -->
    <Condition>CONDITIONAL_STATEMENT</Condition>
</AssertCondition>

다음 예시에서는 google.dialogflow.my-prefix.claimAmount 변수가 0보다 크고 1000보다 작은지 확인합니다.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssertCondition continueOnError="false" enabled="true"
        name="MyAssertCondition">
    <DisplayName>Assert My Condition</DisplayName>
    <Condition>(google.dialogflow.my-prefix.claimAmount > 0)
                and
               (google.dialogflow.my-prefix.claimAmount LesserThan 1000)</Condition>
</AssertCondition>

예를 들면 다음과 같습니다.

  • google.dialogflow.my-prefix.claimAmount 변수 값이 500이면 조건이 참으로 평가되므로 assertcondition.MyAssertCondition.truthValue 변수가 true로 설정됩니다.
  • 그러나 google.dialogflow.my-prefix.claimAmount 변수 값이 1200이면 assertcondition.MyAssertCondition.truthValue 변수는 false로 설정됩니다.

이 요소에는 다음과 같이 모든 정책에 공통된 속성이 있습니다.

속성 기본값 필수 여부 설명
name 해당 사항 없음 필수

정책의 내부 이름입니다. name 속성의 값에는 문자, 숫자, 공백, 하이픈, 밑줄, 마침표가 포함될 수 있습니다. 이 값은 255자(영문 기준)를 초과할 수 없습니다.

원하는 경우 <DisplayName> 요소를 사용하여 관리 UI 프록시 편집기의 정책에 다른 자연어 이름을 사용하여 정책에 라벨을 지정합니다.

continueOnError 거짓 선택사항 정책이 실패할 경우 오류가 반환되도록 하려면 false로 설정합니다. 이는 대부분의 정책에서 예상되는 동작입니다. 정책이 실패해도 흐름 실행이 계속되도록 하려면 true로 설정합니다. 참조:
enabled 선택사항 정책을 시행하려면 true로 설정합니다. 정책을 중지하려면 false로 설정합니다. 정책이 흐름에 연결되어 있어도 정책이 시행되지 않습니다.
async   거짓 지원 중단됨 이 속성은 지원이 중단되었습니다.

하위 요소 참조

이 섹션에서는 <AssertCondition>의 하위 요소를 설명합니다.

<Condition>

평가할 조건을 지정합니다. Apigee에서 조건문을 작성하는 방법에 대한 자세한 내용은 조건 참조를 확인하세요.

기본값 해당 사항 없음
필수 여부 필수
유형 문자열
상위 요소 <AssertCondition>
하위 요소 없음

<DisplayName>

name 속성 외에 이 요소를 사용하여 관리 UI 프록시 편집기에서 자연스러운 다른 이름으로 정책의 라벨을 지정합니다.

<DisplayName> 요소는 모든 정책에 공통으로 적용됩니다.

기본값 해당 사항 없음
필수 여부 선택사항. <DisplayName>을 생략하면 정책의 name 속성 값이 사용됩니다.
유형 문자열
상위 요소 <PolicyElement>
하위 요소 없음

<DisplayName> 요소는 다음 문법을 사용합니다.

구문

<PolicyElement>
  <DisplayName>POLICY_DISPLAY_NAME</DisplayName>
  ...
</PolicyElement>

<PolicyElement>
  <DisplayName>My Validation Policy</DisplayName>
</PolicyElement>

<DisplayName> 요소에 속성 또는 하위 요소가 없습니다.

오류 코드

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause
steps.assertcondition.ConditionEvaluationFailed 500 Failed to evaluate the conditional statement. There can be many reasons for this error, including incorrect values in the variables at run time.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause
InvalidCondition The policy was not able to validate the conditional statement. There can be many reasons for this error, including malformed conditions or use of unsupported operators.

Fault variables

Whenever there are execution errors in a policy, Apigee generates error messages. You can view these error messages in the error response. Many a time, system generated error messages might not be relevant in the context of your product. You might want to customize the error messages based on the type of error to make the messages more meaningful.

To customize the error messages, you can use either fault rules or the RaiseFault policy. For information about differences between fault rules and the RaiseFault policy, see FaultRules vs. the RaiseFault policy. You must check for conditions using the Condition element in both the fault rules and the RaiseFault policy. Apigee provides fault variables unique to each policy and the values of the fault variables are set when a policy triggers runtime errors. By using these variables, you can check for specific error conditions and take appropriate actions. For more information about checking error conditions, see Building conditions.

The following table describes the fault variables specific to this policy.

Variables Where Example
fault.name="FAULT_NAME" FAULT_NAME is the name of the fault, as listed in the Runtime errors table. The fault name is the last part of the fault code. fault.name Matches "ConditionEvaluationFailed"
AssertCondition.POLICY_NAME.failed POLICY_NAME is the user-specified name of the policy that threw the fault. AssertCondition.My-AssertCondition.failed = true
For more information about policy errors, see What you need to know about policy errors.