API Connect

 View Only
Expand all | Collapse all

Upload json config file with extention

  • 1.  Upload json config file with extention

    Posted Thu May 25, 2023 04:36 PM

    i need to upload json config  file through extension . Please guide me on this ,I developed custom policy  to read configuration from file and populate some variables to reuse in all APIS . the below code working fine, if created config file through webui. we have multiple gateways in cluster , it is good to do with extensions

    var sm = require('service-metadata');
    var hm = require('header-metadata');
    var fs = require('fs');
    fs.readAsJSON("local:/extension/Tempkey.js",function(error,rmsg) {
        console.error(rmsg.jwkcsu);
        context.set('message.body',rmsg.samplekey);
     
    });


    ------------------------------
    santhoshkumar surisetty
    ------------------------------


  • 2.  RE: Upload json config file with extention

    Posted Thu May 25, 2023 06:01 PM

    Hi Santhoshkumar,

    The easiest approach would be to take your Tempkey.js file and place it into a new zip file, then add a .cfg file (file extension must be .cfg) to that zip file with the following command:

    top;co;copy -f temporary:/filestores/extensions/<your zip file name>.zip/Tempkey.js  local:///extension/Tempkey.js

    Effectively, your zip file will have just the one non-.cfg file and it is deployed to the location in the temporary directory.  The cfg file will copy that file from the temporary directory where your zip file was deployed to wherever in the file system you wish to place it, which your code above is expecting local:/extension/Tempkey.js.

    That zip file will need to be placed into your Gateway-Extension.zip file, and within the extension zip file's manifest.json file you'll need to add an entry for your zip file into the files array ...

        "files": [
          {
            "filename": "<your zip file name>.zip",
            "deploy": "immediate",
            "type": "extension"
          },
          ... other extension files
          ]

    Best Regards,
    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------