Mass-Enable OPTIONS method across multiple APIs?
search cancel

Mass-Enable OPTIONS method across multiple APIs?

book

Article ID: 251198

calendar_today

Updated On:

Products

CA API Gateway

Issue/Introduction

Our API Gateway team is attempting to enable CORS in our APIs in order to enable active-testing from our internally developed API documentation portal.

As part of this, we need to enable the OPTIONS method across our whole inventory of APIs in our Broadcom API Gateway.

Unfortunately it appears OPTIONS method was not enabled by default. As such, we have a few hundred APIs on which we need to enable OPTIONS method. Doing this manually, one-by-one, via Policy Manager  will take dozens of work-hours.

Is there a restman API call or some other scripted / automated method that can enable OPTIONS method en-mass for multiple APIs at once?

If so please provide some info on implementing this.

Environment

Release : 10.1

Component : API GATEWAY

Resolution

Build a Restman PUT call to update a service's policy (in this case, adding the allowed method "OPTIONS")

- the original payload has some syntax issues.

It was explained that when PUT-ing an update to a service, we must first extract only the contents of the <l7:Resource> tag

(i.e. only the lines from <l7:Service...> to </l7:Service...>) of the policy XML returned by a GET call, then use only those lines as our PUT payload.

- Additionally, a xmlns tag was required to be added to the <l7:Service...> section.

 

1.   LAB example:

https://somegateway.net:8443/restman/1.0/services/5084c1dda5ce5d551c79917ab684b5e5

 

2.  From Postman using GET



3. Copy that output on a notepad ++ and edit

On this case was deleted the following lines from Original GET Response :
Line 1

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

 

Line 3 to 14

    <l7:Name>soa</l7:Name>

    <l7:Id>5084c1dda5ce5d551c79917ab684b5e5</l7:Id>

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

    <l7:TimeStamp>2022-09-28T12:23:16.431-07:00</l7:TimeStamp>

    <l7:Link rel="self" uri="https://somegateway.net:8443/restman/1.0/services/5084c1dda5ce5d551c79917ab684b5e5"/>

    <l7:Link rel="template" uri="https://somegateway.net:8443/restman/1.0/services/template"/>

    <l7:Link rel="list" uri="https://somegateway.net:8443/restman/1.0/services"/>

    <l7:Link rel="dependencies" uri="https://somegateway.net:8443/restman/1.0/services/5084c1dda5ce5d551c79917ab684b5e5/dependencies"/>

    <l7:Link rel="versions" uri="https://somegateway.net:8443/restman/1.0/services/5084c1dda5ce5d551c79917ab684b5e5/versions"/>

    <l7:Link rel="parentFolder" uri="https://somegateway.net:8443/restman/1.0/folders/5084c1dda5ce5d551c79917ab684b5a1"/>

    <l7:Resource>

        <l7:Service id="5084c1dda5ce5d551c79917ab684b5e5" version="2">

 

Notes : - Needed to change the “Item” by “Service” on Line#2 (else will send Error Regarding Bad Request id not Allowed on element). 

           - See image Above from Notepad++ comparing the original and modified file

 

From : 

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

 

Changed Item” by “Service” and Also Added

id="5084c1dda5ce5d551c79917ab684b5e5" version="2">  , left  as follow line :

 

<l7:Service xmlns:l7="http://ns.l7tech.com/2010/04/gateway-management" id="5084c1dda5ce5d551c79917ab684b5e5" version="2">

** version=2 , or the version your service currently has on line ServiceDetail

 

Example:  Deleted the empty line#1 and now Line#2 is the first one…copy all this and go to Postman



Added (Line# 13 here)

<l7:Verb>OPTIONS</l7:Verb>

 

At the Bottom/end of the XML file , was deleted

Line 278 and 279

   </l7:Resource>

</l7:Item>

4. In Postman , we need to execute a PUT to update the Service as needed :

Below the Postman Request completed and executed :



Response must be like the showed above:

 

5. Confirming from Policy Manager the “OPTIONS HTTP method” was been added to the service called “soa”