Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Can Flow Variables be set using Resource Files at an organisation or a environment level ?

If a javascript resource file sets the flow variables as follows :

context.setVariable("varname1", "value1"); 
var host = "hostname.com"; 
var contextRoot = "/" + context.getVariable("request.path").split('/').slice(1,3).join('/'); 
var client_id = ""; 
var client_secret = ""; 
var organization = context.getVariable("organization.name"); 
var environment = context.getVariable("environment.name"); 
var proxyName = context.getVariable("apiproxy.name"); 
var proxyRevision = context.getVariable("apiproxy.revision"); 

//proxy.name 

switch(environment) { 
  case "sandbox": 
    client_id = “xxxxxxxxxxxxxxxx”; 
    break;
  case "prod" :
    and so on..
}

context.setVariable("query-host", host); 
context.setVariable("query-path", organization + "-" + environment + "/api-gateway/configs/"); 
context.setVariable("client-id", client_id); 

This seems to take effect at the api proxy level, but not when used as a resource file at the environment or org level.

So, Can Flow variables be set at the env. or org level ?

Solved Solved
1 2 426
1 ACCEPTED SOLUTION

vijay
New Member

Yes, flow variables can be set from within JavaScript source files. Often, the JavaScript is packaged as a resource file in the API Proxy itself. But a JavaScript module can also be uploaded as an environment-wide resource, or an organization-wide resource. Regardless where the JS module is anchored, execution of the JS works the same way.

You can refer to the org-scoped or env-scoped javascript resource files in the JS policy, in the same way that you refer to a proxy-scoped resource file.

<Javascript name='JS-SetResponse' timeLimit='200' >
  <Properties>
    <Property name='prop1'>value-here</Property>
  </Properties>
  <ResourceURL>jsc://setResponse.js</ResourceURL>
</Javascript>

In the above, the policy will first look for the setResponse.js file in the apiproxy, then in the set of environment-scoped resources, and finally in the set of organization-scoped resources.

View solution in original post

2 REPLIES 2