StyleBookでリテラル形式の特殊文字を使用できるようにする
StyleBookの定義では、文字列内の特殊文字をリテラル形式にする必要がある場合は、逐語的な文字列を使用できます。これらの文字列には、エスケープ文字、バックスラッシュ、引用符、括弧、空白、角かっこなどを含めることができます。
StyleBooksでは、逐語的な文字列を使用して、Citrix ADCポリシー式をリテラル形式で含めることができます。通常、ポリシー式には特殊文字が含まれています。逐語的な文字列を使用しない場合、文字列を部分文字列に分割して特殊文字をエスケープする必要があります。
逐語的な文字列を作成するには、次のように特殊文字間の文字列をカプセル化します。
~{string}~
StyleBook 式では、逐語的な文字列を使用できます。
注:
入力文字列には} ~ という文字シーケンスを使用しないでください。このシーケンスは文字列の終わりを示すものです。
例:
---
name: test-deny-url
namespace: citrix.adc.stylebooks
version: "6.2"
display-name: StyleBook for creating an AppFw profile
description: This Stylebook configures an AppFw config.
schema-version: "1.0"
import-stylebooks:
-
namespace: netscaler.nitro.config
prefix: ns
version: "13.0"
parameters:
-
name: name
type: string
required: true
substitutions:
default-deny-urls-regex:
"Command_injection_attack": str("([ /=]|\t|\n)(ls|cat)([ ;'" + "\\"&].\*)?$")
"Command_injection_attack2": ~{([ /=]|\t|\n)(ls|rm|cat)([ ;'"&].\*)?$}~
components:
-
name: appfw-profile-comp
type: ns::appfwprofile
properties:
name: $parameters.name
type: ["XML"]
components:
-
name: appfw-profile-denyurl-default-binding-subcomp-all
type: ns::appfwprofile_denyurl_binding
properties:
name: $parent.properties.name
denyurl?: $substitutions.default-deny-urls-regex["Command_injection_attack"]
state?: "ENABLED"
-
name: appfw-profile-denyurl-default-binding-subcomp-all2
type: ns::appfwprofile_denyurl_binding
properties:
name: $parent.properties.name
denyurl?: $substitutions.default-deny-urls-regex["Command_injection_attack2"]
state?: "ENABLED"
<!--NeedCopy-->
この例では、 default-deny-urls-regex
置換は逐語的に表現されています。
-
"Command_injection_attack": str("([ /=]|\\t|\\n)(ls|cat)([ ;'" + "\\\"&].*)?$")
: StyleBookはそれを正規表現として処理します。 -
"Command_injection_attack2": ~{([ /=]|\t|\n)(ls|rm|cat)([ ;'\"&].*)?$}~
: StyleBookはそれを逐語表現として処理します。この文字列の特殊文字はリテラル形式をとります。
複数の逐語文字列を連結する
逐語文字列を通常の文字列または補間で連結できます。そうすると、StyleBookは逐語文字列のみの解釈をスキップします。連結する文字列の間には、プラス (+) 演算子を使用します。
例:
value: "~{"id": "}~ + %{$atom.key}% + ~{", "value": "}~ + %{$atom.value}% + ~{"}~"
<!--NeedCopy-->
この例では、%{$atom.key}%
と%{$atom.value}%
が解釈されます。そして、残りの部分については解釈がスキップされます。