Layer7 API Management

Expand all | Collapse all

[URGENT] Environment Variables in LAC?

Jump to Best Answer
  • 1.  [URGENT] Environment Variables in LAC?

    Posted 11-14-2017 07:54 AM

    As all servers/application has the concept of Environment Variables. I do have a use case where I need this feature in LAC. Here it is - 

     

    When I am creating a Java Script Resource or a Function there I may be calling a resource using

    SysUtility.getResource('URL', {}, {}, {});

     for URL  -  I need to mention the URL of LAC where it is located and now suppose I have two LAC environment - Production & Development.

    When I will move the LAC components (Resources, functions, Request events) from development to production server then I have to make changes to EVERY Resource and function where I have written the URL statement. Its an overhead and rework in case of LAC. Looking for any solution/workaround for this.

     

    Does anyone have a solution for this? Or I am implementing the SysUtility.getResource() function in wrong way.

     

    Thanks in advance!

     

    tarma06 - I always expect help from you.



  • 2.  Re: [URGENT] Environment Variables in LAC?
    Best Answer

    Posted 11-14-2017 09:27 AM

    This question was brought up in a recent training class I attended for LAC and the product does not currently have the type of environment variable functionality you are looking for. The migration process for APIs between environments(Production/Development) involves exporting the API definitions to a json file. You could do a global search/replace in the json file for things such as the environment specific URL used in your example SysUtility.getResource call.

     

    More details around the Best Practices and tools available for migrating APIs between environments can be found here:

    Import and Export APIs

     

    You could also create an Idea(Enhancement Request) on the CA Live API Creator community forum to add Environment Variable functionality here. Ideas are reviewed by the Product Management(PM) team for potential inclusion in a future release of the product. Other customers can vote and comment on these Ideas to let the PM team know they are interested in this feature as well. The PM team will update Ideas once they have been reviewed to let everyone know if they have been rejected, accepted or wait-listed.



  • 3.  Re: [URGENT] Environment Variables in LAC?

    Posted 11-15-2017 02:05 AM

    One way to do this is as a JavaScript library - in API Creator, go to API Properties > Libraries and create a new library containing e.g.:

     

    var topLevelVariables = {

        urlForThis: "https://blah",

        passwordForThat: "supersecret"

    };

     

    If you mark that library as used (checkbox then save), then you'll have those variables available anywhere in your code as e.g. topLevelVariables.urlForThis.

     

    By the way, you don't even have to enclose your variables in a top-level object like this, it's just considered good form in the JavaScript world, to minimize the pollution of the top-level namespace.

     

    Another possibility is to use system variables, which you can then specify when starting Java with e.g. :

     

    java -DmyProperty=myValue etc...

     

    and use in your rules with e.g.:

     

    var myUrl = java.lang.System.getProperty("myProperty");

     

    You can do the same thing with environment variables using e.g.:

     

    var myUrl = java.lang.System.getenv("myEnvironmentVariable");

     

    Which one is right for you depends a great deal on the specific use case. Being able to set the values from the command line is sometimes hugely helpful, but it's not always appropriate, in which case using a library might be a better idea.



  • 4.  Re: [URGENT] Environment Variables in LAC?

    Posted 12-13-2017 07:41 AM

    Thanks for giving the suggestion and alternatives.