This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[config] - Provides ability to read configs and secrets from environm…
…ent variables
- Loading branch information
venkatvghub
committed
Mar 31, 2021
1 parent
6cee427
commit aeb6974
Showing
4 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/util/CustomConfigReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.apache.pinot.thirdeye.util; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class CustomConfigReader { | ||
public String readEnv(String inputStr) { | ||
final String regex = "\\?\\$[A-Z0-9_]*"; | ||
final Pattern pattern = Pattern.compile(regex); | ||
final Matcher matcher = pattern.matcher(inputStr); | ||
|
||
while (matcher.find()) { | ||
String matchStr = matcher.group(0); | ||
String env = matchStr.substring(2); | ||
String value = System.getenv(env); | ||
if (value != null) { | ||
// replace original string with configured env variables | ||
inputStr = inputStr.replace(matchStr, value); | ||
} else { | ||
System.out.format("%s is" + " not assigned.%n", env); | ||
} | ||
} | ||
|
||
return inputStr; | ||
} | ||
} |