Layer7-Community / graphman-client

This repository contains a Postman collection, a Node.js CLI application, sample queries for the CLI, and GraphQL schemas for the Graphman API.
Other
7 stars 5 forks source link

v1.3.00: explode / implode only works with policyCodeFormat=xml #54

Closed res13 closed 2 months ago

res13 commented 2 months ago

I exported my 11.1.00.17707 Gateway with the command

./graphman.sh export --using all --output gateway.json

and the following options in graphman.configuration file:

 "options": {
        "log": "info",
        "schema": "v11.1.00",
        "policyCodeFormat": "json",
        "keyFormat": "p12",
        "extensions": ["pre-request", "post-export", "pre-import"]
    }

then I exploded it:

./graphman.sh explode --input e-apigw.json --output gateway-exploded

and I tried to implode it again without any changes:

./graphman.sh implode --input e-apigw-exploded --output gateway-imploded.json

which gives me following errors:

[error] file doesn't exist, gateway-exploded/tree/Common Modules/Policy Fragments/"All":[{"Encapsulated":{"encassGuid":"ac6f3bf7-329c-48db-b3bc-f30c32113e0d","encassName":"request body to string","parameters":{"binaryPlaceholder":"<Binary content>"}}},{"SetVariable":{"contentType":"text/plain; charset=utf-8","dataType":"message","expression":"${body}","variable":"requestBody"}},{"CacheStorage":{"cacheEntryKey":"${requestid}.request","cacheId":"log","maxEntries":"1000","maxEntrySizeBytes":"10485760","otherTargetMessageVariable":"requestBody","storeSoapFaults":true,"target":"OTHER"}},{"Join":{"inputVariable":"request.http.allheadervalues","joinSubstring":"\\n","outputVariable":"requestHeaders"}},{"CacheStorage":{"cacheEntryKey":"${requestid}.requestheaders","cacheId":"log","maxEntries":"1000","maxEntrySizeBytes":"5242880","otherTargetMessageVariable":"requestHeaders","storeSoapFaults":true,"target":"OTHER"}},{"SetVariable":{"contentType":"text/plain; charset=utf-8","dataType":"message","expression":"${response.mainpart}","variable":"response_body"}},{"CacheStorage":{"cacheEntryKey":"${requestid}.response","cacheId":"log","maxEntries":"1000","maxEntrySizeBytes":"10485760","otherTargetMessageVariable":"response_body","storeSoapFaults":true,"target":"OTHER"}},{"OneOrMore":[{"All":[{"Join":{"inputVariable":"response.http.allheadervalues","joinSubstring":"\\n","outputVariable":"responseHeaders"}},{"CacheStorage":{"cacheEntryKey":"${requestid}.responseheaders","cacheId":"log","maxEntries":"1000","maxEntrySizeBytes":"10485760","otherTargetMessageVariable":"responseHeaders","storeSoapFaults":true,"target":"OTHER"}}]},{"True":{}}]},{"CacheStorage":{"cacheEntryKey":"${requestid}.backend","cacheId":"log","maxEntries":"1000","maxEntrySizeBytes":"10485760","otherTargetMessageVariable":"log","storeSoapFaults":true,"target":"OTHER"}},{"CacheStorage":{"cacheEntryKey":"${requestid}.error","cacheId":"log","maxEntries":"1000","maxEntrySizeBytes":"10485760","otherTargetMessageVariable":"errorMessage","storeSoapFaults":true,"target":"OTHER"}}]

even though the file that is holding the policy that is mentioned in the error message is actually present under the path gateway-exploded/tree/Common Modules/Policy Fragments/prepare and store log data-[prepare and store log data-FRAGMENT].policy.json with the following content:

{
  "goid": "626e2e5da33817f6fa69e8022eb7b123",
  "guid": "99893e35-3222-4098-9ab2-e801363e41d4",
  "name": "prepare and store log data",
  "policyType": "FRAGMENT",
  "checksum": "df5a9dd93cd276cee01ace784aed5fd07d1e34ef",
  "folderPath": "/Common Modules/Policy Fragments",
  "soap": false,
  "policy": {
    "json": "{\"All\":[{\"Encapsulated\":{\"encassGuid\":\"ac6f3bf7-329c-48db-b3bc-f30c32113e0d\",\"encassName\":\"request body to string\",\"parameters\":{\"binaryPlaceholder\":\"<Binary content>\"}}},{\"SetVariable\":{\"contentType\":\"text/plain; charset=utf-8\",\"dataType\":\"message\",\"expression\":\"${body}\",\"variable\":\"requestBody\"}},{\"CacheStorage\":{\"cacheEntryKey\":\"${requestid}.request\",\"cacheId\":\"log\",\"maxEntries\":\"1000\",\"maxEntrySizeBytes\":\"10485760\",\"otherTargetMessageVariable\":\"requestBody\",\"storeSoapFaults\":true,\"target\":\"OTHER\"}},{\"Join\":{\"inputVariable\":\"request.http.allheadervalues\",\"joinSubstring\":\"\\\\n\",\"outputVariable\":\"requestHeaders\"}},{\"CacheStorage\":{\"cacheEntryKey\":\"${requestid}.requestheaders\",\"cacheId\":\"log\",\"maxEntries\":\"1000\",\"maxEntrySizeBytes\":\"5242880\",\"otherTargetMessageVariable\":\"requestHeaders\",\"storeSoapFaults\":true,\"target\":\"OTHER\"}},{\"SetVariable\":{\"contentType\":\"text/plain; charset=utf-8\",\"dataType\":\"message\",\"expression\":\"${response.mainpart}\",\"variable\":\"response_body\"}},{\"CacheStorage\":{\"cacheEntryKey\":\"${requestid}.response\",\"cacheId\":\"log\",\"maxEntries\":\"1000\",\"maxEntrySizeBytes\":\"10485760\",\"otherTargetMessageVariable\":\"response_body\",\"storeSoapFaults\":true,\"target\":\"OTHER\"}},{\"OneOrMore\":[{\"All\":[{\"Join\":{\"inputVariable\":\"response.http.allheadervalues\",\"joinSubstring\":\"\\\\n\",\"outputVariable\":\"responseHeaders\"}},{\"CacheStorage\":{\"cacheEntryKey\":\"${requestid}.responseheaders\",\"cacheId\":\"log\",\"maxEntries\":\"1000\",\"maxEntrySizeBytes\":\"10485760\",\"otherTargetMessageVariable\":\"responseHeaders\",\"storeSoapFaults\":true,\"target\":\"OTHER\"}}]},{\"True\":{}}]},{\"CacheStorage\":{\"cacheEntryKey\":\"${requestid}.backend\",\"cacheId\":\"log\",\"maxEntries\":\"1000\",\"maxEntrySizeBytes\":\"10485760\",\"otherTargetMessageVariable\":\"log\",\"storeSoapFaults\":true,\"target\":\"OTHER\"}},{\"CacheStorage\":{\"cacheEntryKey\":\"${requestid}.error\",\"cacheId\":\"log\",\"maxEntries\":\"1000\",\"maxEntrySizeBytes\":\"10485760\",\"otherTargetMessageVariable\":\"errorMessage\",\"storeSoapFaults\":true,\"target\":\"OTHER\"}}]}"
  }
}

When I set the option policyCodeFormat to xml in the graphman.configuration file it works fine.

graju256 commented 2 months ago

Thank you for submitting the issue. It is confirmed that there's a faulty code that is expecting a exploded file to implode. It is kind of conflict of interest in distinguishing the exploded file reference format ({{<filename>}}) from the usual data.

graju256 commented 2 months ago

@res13 submitted the PR (https://github.com/Layer7-Community/graphman-client/pull/56) to fix this issue.