Flex Gateway新着情報
Governance新着情報
Monitoring API ManagerXML タグ内から機密データが含まれていることがわかっている特定の属性を削除できます。この DataWeave の例では、渡される要素とその子から特定の XML 属性を削除する関数を DataWeave ヘッダーで定義します。 開始する前に、Mule 4 アプリケーションでは DataWeave のバージョン 2.x が使用されることに注意してください。Mule 3 アプリケーションでの DataWeave については、DataWeave バージョン 1.2 の例を参照してください。 他の DataWeave バージョンの場合は、DataWeave の目次のバージョンセレクターを使用できます。
この例では、以下を使用します。
各要素を調べる mapObject。
XML 要素の属性を参照する @。
存在している XML 属性のみをリストし、子要素がオブジェクトである場合にのみ関数を再帰的にコールする if および else。
子が Object 型かどうかをチェックする is。
XML 属性のリストから要素を削除する -。
値がない場合に出力 XML に自己終了タグが表示されるようにする出力ディレクティブの inlineCloseOn="empty"。
入力内の親 users オブジェクトまたは子 user オブジェクトにキーが password の属性が含まれる場合、removeAttributes によってオブジェクトからその属性が削除されます。
%dw 2.0
output application/xml inlineCloseOn="empty"
var removeAttribute = (element,attrName) ->
  element mapObject (value, key) -> {
    // Pass the name of the key of the input object,
    // for example, whether the key is "users" or "user",
    // and use @() to remap the XML attributes.
    (key) @(
        (
          // If the element contains attributes (key.@?),
          // remove any attribute that has the provided key,
          // "password".
          if (key.@?)
            (key.@ - attrName)
          // Otherwise, do nothing.
          else {}
        )
    ) :
    // If the value of the input object contains one or
    // more objects, apply removeAttribute to remove any
    // attribute with the key "password" from those objects.
    if (value is Object)
      removeAttribute(value, attrName)
    // Otherwise, return the value of the input object.
    else value
  }
---
removeAttribute(payload, "password")
<users>
  <user username="Julian" password="1234"/>
  <user username="Mariano" password="4321"/>
</users>
<?xml version='1.0' encoding='US-ASCII'?>
<users>
  <user username="Julian"/>
  <user username="Mariano"/>
</users>