Layer7 API Management

 View Only
  • 1.  How do I use restman or GMU to export a policy xml?

    Posted Aug 26, 2015 05:59 AM

    Hi,

     

    The question is how to export the contents of a policy (the active version) in plain xml format.

    I want to do this via GMU or restman APIs.

     

    The /bundle, /policies and /services resources in restman does not seem to have a way of doing this, since they expose the policies as xml escaped "Resource" content, like

    "<?xml version="1.0" encoding="UTF-8"?>....."


    I want the unescaped xml format like when manually exported from within Policy Manager.


    We need to be able to script exports for version controlling policies, and the bundle format is no good for that purpose.

     

    BR,

    Tony

     

    Message was edited by: Tony Svedlund



  • 2.  Re: How do I use restman or GMU to export a policy xml?

    Broadcom Employee
    Posted Aug 26, 2015 11:32 AM

    Here’s a document that can help when moving policies from one environment to the next.

     

     

    Thanks,

     

    Derek Orr

     

    CA Technologies |885 West Georgia Street Ste 500 | Vancouver, BC V6C 3G1

    Office: 1-778-328-5285 | Mobile: +1 778 980 0029 | Derek.Orr@ca.com

     

    <mailto:>[CA]

     

    <http://www.ca.com/us/default.aspx>[Twitter]<http://twitter.com/CAInc>[LinkedIn]<http://www.linkedin.com/company/1372?goback=.cps_1244823420724_1>[Facebook]<https://www.facebook.com/CATechnologies>[YouTube]<http://www.youtube.com/user/catechnologies>[Google]<https://plus.google.com/CATechnologies>[Slideshare]<http://www.slideshare.net/cainc>

    Attachment(s)

    pptx
    GMU July 2015-actual.pptx   675 KB 1 version


  • 3.  Re: How do I use restman or GMU to export a policy xml?

    Posted Aug 26, 2015 12:05 PM

    Thanks Derek.

    However, my issue is not regarding migration of policies, but rather version controlling them in an external SCM, such as Git.

     

    So the question is if there is a way to export policies (for services, fragments and encas) in a readable non-escaped format without manually using export in the Policy Manager (or do some scripting to convert the XML-escaped content that is the result of an export using e.g. GMU migrateOut or /restman/bundle api).

     

    BR,

    Tony



  • 4.  Re: How do I use restman or GMU to export a policy xml?

    Posted Aug 28, 2015 10:01 AM

    The issue you seem to be concerned about is that the actual policy components of the service are percent-encoded (as opposed to escaped), correct? If that is the case then here is a possible solution that might work using a Web API published in the Gateway:

    1. Publish the RESTMAN API
    2. Publish a separate Web API (henceforce, "scraper")
    3. Route to the RESTMAN API from the scraper service
    4. Use an Evaluate Response XPath assertion to select only the portion of the RESTMAN response that contains a policy
    5. Use the Encode/Decode data assertion to URL decode the targeted XPath


  • 5.  Re: How do I use restman or GMU to export a policy xml?

    Posted Sep 01, 2015 06:36 AM

    Hi Eric,

     

    I mean that the policy content in the xml response is in PCDATA format with &lt; &quot; and so forth, e.g (in bold);

     

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    <l7:Item xmlns:l7="http://ns.l7tech.com/2010/04/gateway-management">

        <l7:Name>resetpassword</l7:Name>

        <l7:Id>1a4b4e04dc13b35423193f2aebc8c025</l7:Id>

        <l7:Type>SERVICE</l7:Type>

        <l7:TimeStamp>2015-09-01T12:09:28.293+02:00</l7:TimeStamp>

        <l7:Link rel="self" uri="https://localhost:8443/restman/1.0/services/1a4b4e04dc13b35423193f2aebc8c025"/>

    ...

                <l7:Resources>

                    <l7:ResourceSet tag="policy">

                        <l7:Resource type="policy" version="12">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

    &lt;wsp:Policy xmlns:L7p=&quot;http://www.layer7tech.com/ws/policy" xmlns:wsp=&quot;http://schemas.xmlsoap.org/ws/2002/12/policy">

        &lt;wsp:All wsp:Usage=&quot;Required&quot;&gt;

            &lt;L7p:SetVariable&gt;

                &lt;L7p:Base64Expression stringValue=&quot;YXBwbGljYXRpb24vanNvbg==&quot;/&gt;

                &lt;L7p:VariableToSet stringValue=&quot;resp.content-type&quot;/&gt;

            &lt;/L7p:SetVariable&gt;

            &lt;wsp:OneOrMore wsp:Usage=&quot;Required&quot;&gt;

                &lt;wsp:All wsp:Usage=&quot;Required&quot;&gt;

                    &lt;L7p:ContentType&gt;

                        &lt;L7p:ChangeContentType booleanValue=&quot;true&quot;/&gt;

                        &lt;L7p:NewContentTypeValue stringValue=&quot;application/json&quot;/&gt;

                    &lt;/L7p:ContentType&gt;

                    &lt;L7p:AuditDetailAssertion&gt;

                        &lt;L7p:Detail stringValue=&quot;Evaluate request body&quot;/&gt;

                        &lt;L7p:Level stringValue=&quot;WARNING&quot;/&gt;

                    &lt;/L7p:AuditDetailAssertion&gt;

                    &lt;L7p:HttpRoutingAssertion&gt;

                        &lt;L7p:AssertionComment assertionComment=&quot;included&quot;&gt;

                            &lt;L7p:Properties mapValue=&quot;included&quot;&gt;

                                &lt;L7p:entry&gt;

                                    &lt;L7p:key stringValue=&quot;RIGHT.COMMENT

    etc...

     

    Whereas when exported from PolicyManager i get the "unescaped" XML, such as:

     

    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
      <wsp:All wsp:Usage="Required">
      <L7p:SetVariable>
      <L7p:Base64Expression stringValue="YXBwbGljYXRpb24vanNvbg=="/>
      <L7p:VariableToSet stringValue="resp.content-type"/>
      </L7p:SetVariable>
      <wsp:OneOrMore wsp:Usage="Required">
      <wsp:All wsp:Usage="Required">
      <L7p:ContentType>
      <L7p:ChangeContentType booleanValue="true"/>
      <L7p:NewContentTypeValue stringValue="application/json"/>
      </L7p:ContentType>
      <L7p:AuditDetailAssertion>
      <L7p:Detail stringValue="Evaluate request body"/>
      <L7p:Level stringValue="WARNING"/>
      </L7p:AuditDetailAssertion>
      <L7p:HttpRoutingAssertion>
      <L7p:AssertionComment assertionComment="included">
      <L7p:Properties mapValue="included">
      <L7p:entry>
      <L7p:key stringValue="RIGHT.COMMENT"/>



  • 6.  Re: How do I use restman or GMU to export a policy xml?

    Posted Sep 01, 2015 09:45 AM

    You can leverage the same recommendation specified previously to perform a find-and-replace. There is no capability to force the Gateway to return that component in XML format that I am aware of.



  • 7.  Re: How do I use restman or GMU to export a policy xml?

    Posted Aug 28, 2015 10:03 AM

    Its also worth noting that there is more configuration management in a service than just the policy. The return from GET /restman/1.0/services also includes other service description information such as the allowed HTTP methods, resolution paths, GOIDs, and other metadata that is not encapsulated in the policy. While I can appreciate the need to capture the raw policy--make sure that you are capturing everything that you need from the service description or else the configuration management is only halfhearted.