Access environment variables from Optimize plugin

hi - when building a custom plugin for Optimize, e.g We've moved! | docs.camunda.org, is there a way to access the environment variables defined in the environment yaml ?

Any documentation or snippets of code appreciated.

thanks

Hey Eleco!

there is not yet an official way, however you could add the optimize-backend-2.x.x.jar as a local dependency to your project and would then be able to use and inject the internal ConfigurationService like this.

import org.camunda.optimize.service.util.configuration.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;

public class EngineRestFilterWithConfig implements EngineRestFilter {

@Autowired
private ConfigurationService configurationService;

@Override
public void filter(ClientRequestContext requestContext, String engineAlias, String engineName) throws IOException {
 System.out.println(configurationService.getContainerHost());
}

}

Assuming you only need access to already defined configuration entries you could do it like that, but you won’t be able to access any custom entries.

What is your use case if I may ask?

Sebastian

2 Likes

thanks @Sebastian_Bathke

our use case - we’d like to configure the way optimize authenticates against the bpmn engine, based on custom parameters stored in the environmnent.yaml. The alternative being to use system properties if custom entries are not accessible.

1 Like

Has anything changed in this regard since the last post in this thread? Is there now an official way to pass some config values to a plugin? Ideally, I’d like to be able to use Spring wiring in the plugin.

If using Spring is possible: Where should I put the configuration files and how would I specify the active profiles?

Thanks!

Hello @fml2 ,

Unfortunately there is still no way to access custom enviroment variables defined in the environment yaml, but you can try using the jar proposed by @Sebastian_Bathke to access already defined configuration variables.

I hope you find this solution helpful.

Cheers,
Andrea

Hello Andrea,

thank you for the quick response!

It disappoints me that there has been no progress on this since so long. Apparently, no serious thoughts have been put into how optimize plugins can be developed. This is sad.

As for the solution proposed by @Sebastian_Bathke: If I want to use a config value that is not there yet in the standard configuration, then the only way I can think of is to set as the value of an existing key some XML or JSON which then would contain all the necessary config values. This is ugly but should work.

Thank you again and, if you are a member of the optimize development team, please consider making plugin development more of a pleasure than workarounds :slight_smile:

Hello @fml2,

I had a second look and it seems that the snippet provided by Sebastian earlier is not working anymore. I am linking you here to a commit which shows how you can access custom environment variables which are passed in Optimize. The example shows you can access the following variable:

customToken: “some value”

from a file called

custom-config.yaml

You could also use the environment-config.yaml file we provide, but we strongly recomment to keep custom configurations on a seperate file. I hope you find this helpful.

Cheers,
Andrea

2 Likes

Thank you!

Hello Andrea,

may I ask you one more question? In the example, a config file is read. If the file contains some placeholders (like ${myValue}) then I’d have to somehow replace them in my code, right? I mean, the optimize utility does not do this. Is my understanding correct?

Thank you.

Hey @fml2,

I am not sure what you mean exactly, would you perhaps be able to provide an example?

Thank you in advance.

Kind regards,
Andrea

Hello Andrea,

I mean this: if

  • I have something like customToken: ${theTokenValue} in the YAML file and
  • I have e.g. the environment variable theTokenValue set to MyValue

What would then a call configJsonContext.read("customToken") return: "${theTokenValue}" or "MyValue"? I.e. does the call to configJsonContext.read substitute the place holders like e.g. Spring does it?

Thank you.

@fml2 I just checked it on my machine and it will return “MyValue”!

Hope this is helpful

1 Like