Layer7 API Management

 View Only
  • 1.  How to add a Global Policy to execute every time when every service is resolved?

    Posted Jan 06, 2021 04:45 AM
    Global Policy Fragments
    Broadcom remove preview
    Global Policy Fragments
    Global policies are policy fragments that are always applied before or after every service policy in the system. They can be used to configure global behaviors like auditing or logging, where it may not be feasible to manually add the policy logic to all service policies.
    View this on Broadcom >
    Hi There,

    We are using API Gateway v9.4

    We have a Policy Fragment  and we're thinking to make it global such that whenever a service is resolved this policy also should be executed along and this should be done for all the services that are hosted in the API Gateway.

    Have gone through the below techdoc, but not sure which one among these can be used for the same.
    https://techdocs.broadcom.com/us/en/ca-enterprise-software/layer7-api-management/api-gateway/9-4/services-and-policies/working-with-policies/policy-fragments/global-policy-fragments.html

    Can someone please suggest how this can be achieved?  

    Thanks in advance.

    PS


  • 2.  RE: How to add a Global Policy to execute every time when every service is resolved?

    Posted Jan 07, 2021 02:56 AM
    Hi @Pavansai C,
    You can create a message-completed policy fragment which will be handled after a service policy.
    From Create Policy:
    ​Usually we try to use common naming like "Post-processing" so that it is clear what it does.

    ------------------------------
    Integration Consultant
    Enable-U
    Netherlands
    ------------------------------



  • 3.  RE: How to add a Global Policy to execute every time when every service is resolved?

    Broadcom Employee
    Posted Jan 08, 2021 02:16 PM
    You probably want to use a pre-service global policy for this. A pre-service policy is executed immediately prior to the service policy itself.

    As described in the documentation:

    • message-received is run for EVERY request that arrives at the Gateway
    • pre-security is run during service resolution. As a point of clarification, the pre-security and post-security global policies tend to confuse the global policy configuration a bit and I don't use it. They only make sense in the context of a SOAP service that uses WS-* and dynamic service resolution (i.e. the request was routed to /ssg/soap). 
    • pre-service is run immediately prior to executing the service policy
    • post-service is run immediately after the service policy *assuming the service policy did not fail
    • post-security is run AFTER and WS-* security is performed on the SOAP response message (assuming the service policy did not fail), and like pre-security I never use it.
    • message-complete is executed for all messages received


    ------------------------------
    Jay MacDonald - Adoption Architect - Broadcom API Management (Layer 7)
    ------------------------------



  • 4.  RE: How to add a Global Policy to execute every time when every service is resolved?

    Posted Jan 13, 2021 03:15 AM
    Edited by Pavansai C Jan 13, 2021 03:33 AM
    Thanks for that Marco and JayMac.

    I started to use pre-service policy and that seems okay. but now that I can perform something before the service resolves.. How to extract a variable from the Global Pre-Service Fragment to use it in the actual service? is there any way? 
    Because, wanted to use the variables in the Service that are set in the Global Pre-Service Policy. 

    ***** Have used Export Variables from Fragment and checked the required variable to export, but no luck ****



    Please advice. Thanks. ~PS.



  • 5.  RE: How to add a Global Policy to execute every time when every service is resolved?

    Posted Jan 13, 2021 11:37 AM
    Hi @Pavansai C,
    This can be done with the Export Variables assertion.
    https://techdocs.broadcom.com/us/en/ca-enterprise-software/layer7-api-management/api-gateway/10-0/policy-assertions/assertion-palette/policy-logic-assertions/export-variables-from-fragment-assertion.html​

    Make sure to use "request.shared." in front of the variable you want to use.

    Example: Accessing variables from global policy fragment in audit sink policy
    The following example illustrates how to access the "message-received" variable from the audit sink policy:
    • Create a "message-received" global policy fragment containing these assertions:
      Audit Messages in Policy
       
      (WARNING)
       
      Set Context Variable
       
      varMessageReceived as String to: Hello from message-received global policy
       
      Export Variables from Fragment: varMessageReceived
    • Create a custom audit sink policy with this assertion:
      Add Audit Details: log, custom logger "audit": "varMessageReceived=${request.shared.varMessageReceived}"
    • Consume any service.
    • The 
      Layer7 API Gateway
       log will contain this line:
      varMessageReceived=Hello from message-received global policy





    ------------------------------
    Integration Consultant
    Enable-U
    Netherlands
    ------------------------------