How to set environment variables in GAE with Java - not showing up in main code? Or another way to hide the keys used by the application?

I am developing a GAE web application with Java, and I am going to open the code for this web application on Github.

But I do not like to expose some API keys in the code. So, I’m looking for a way to save some data that an application can get without showing this data in a working application code published on Github.

For example, this servlet https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/appengine/mailgun/src/main/java/com/example/appengine/mailgun/MailgunServlet.java gets the API key using System .getenv () and usually environment variables written in appengine-web.xml Is there any other way? To set environment variables from the Google Developers Console or to safely store and retrieve them from the GAE data store?

+4
source share
1 answer

.properties ( Properties ). , -, ( ). , Github ( .gitignore).

3 resources:

  • myapp.prod.properties
  • myapp.dev.properties
  • myapp.test.properties

( , prod.properties, lib).

: https://docs.oracle.com/javase/tutorial/essential/environment/properties.html JavaDoc https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html

- :

Properties props = new Properties();
String name;
if (SystemProperty.Environment.Value.Development == SystemProperty.environment.value()) {
    name = "myapp.dev.properties";
} else {
    name = "myapp.prod.properties";
}
props.load(Classname.class.getClassLoader().getResourceAsStream(name));

- Java . , Spring , @PropertySource ConfigurableApplicationContext

+2

All Articles