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

Environment Specific Property Sets

Hi,

In the documentation (https://cloud.google.com/apigee/docs/api-platform/cache/property-sets#property-set-files) for property sets, there's mention of using environment-specific files as a use case:

For example:

  • The prod-env.properties property set contains the property log-level=error
  • The test-env.properties property set contains the property log-level=debug

Is there a documented way to do this? I can package only the target environment file at deploy time, but wanted to check there wasn't a way to do this intrinsically.

Thanks!

Solved Solved
0 3 204
1 ACCEPTED SOLUTION

I came up with a solution to this. I couldn't find any reference to a variable that exposed which project you are in, so I created a property set to map between environment names and projects. I then used used the format 

<project>.<property>=<value>

and then used AssignMessage to map the env to a project, and then use that to find the value for that project.

Admittedly you could just do the same with `environment.name` as the discriminator, but I needed the project name to use in my Cloud Logging path anyway.

View solution in original post

3 REPLIES 3

Hi @kcacciatore,

I noticed your question hasn’t been answered yet. Don’t worry—we’ll keep an eye on it and try to get some input from other members soon.

I came up with a solution to this. I couldn't find any reference to a variable that exposed which project you are in, so I created a property set to map between environment names and projects. I then used used the format 

<project>.<property>=<value>

and then used AssignMessage to map the env to a project, and then use that to find the value for that project.

Admittedly you could just do the same with `environment.name` as the discriminator, but I needed the project name to use in my Cloud Logging path anyway.

I'm glad you solved it.

There is an "organization.name" variable which is the same as the GCP project name, in Apigee X and hybrid.

That might get you what you want in a different way.

Also, you can apply multiple levels of indirection via AssignMessage/AssignVariable. What I mean is this: suppose you have a properties file that has property names that depend on the environment.name. (If you use an environment-scoped properties file, you wouldn't do this, but ... the idea extends beyond environment-scoped properties. It could be properties based on API Product name, or ... anything).

Suppose your properties file looks like this:

 

target1-dev=https://my-dev-server.com
target1-eval=https://my-eval-server.com
target1-prod=https://my-prod-server.com

 

And in the proxy you would like to get the value for the current environment. How? You can do this with 2 cascades of indirection. It looks like this:

 

<AssignMessage name='AM-Eval-Settings'>

  <AssignVariable>
    <Name>target-variable</Name>
    <Template>propertyset.settings.target1-{environment.name}</Template>
  </AssignVariable>
  <!-- result of the above is propertyset.settings.target1-dev,   for example. -->

  <AssignVariable>
    <Name>target-template</Name>
    <Template> { {target-variable} } </Template>  <!-- see note below -->
  </AssignVariable>
  <!-- result of the above is {propertyset.settings.target1-dev}, for example. -->
  <!-- it's suitable for use as a message template. -->


  <AssignVariable>
    <Name>resolved-target</Name>
    <Template ref='target-template'/>
  </AssignVariable>
  <!-- the above just resolves that message template.  so the value will be -->
  <!-- https://my-dev-server.com -->

</AssignMessage>

 

Please note , you must collapse the double-curlies. I cannot post the correct code without spaces here, for some reason.