Last active
May 10, 2019 17:30
-
-
Save blabadi/d5ba492f610820b388469fec97f35676 to your computer and use it in GitHub Desktop.
a script to convert java properties into env vars instead of manually typing them, it takes into account arrays in keys. the output format is specifically useful for kubernetes yaml env object
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
const convertJavaPropertiesToEnvVars = function(configs) { | |
const configLines = configs.split('\n'); | |
let out = '' | |
for (let idx in configLines) { | |
const line = configLines[idx] | |
const key = line.split('=')[0].toUpperCase() | |
.replace(/\[/g, '.') | |
.replace(/\]/g, '') | |
.replace(/\./g, '_') | |
const value = line.split('=')[1] | |
out += ` | |
- name : ${key} | |
value: "${value}" | |
` | |
} | |
return out; | |
} | |
// example: | |
// use https://www.toyaml.com/index.html to convert yaml to key,val properties | |
const configs = `server.port=80 | |
maestro.kafka.broker=10.11.7.31:9092 | |
maestro.kafka.indexing_topic=maestro_index_requests | |
maestro.repositories[0].code=collab | |
maestro.failure_log.dir=\${user.home}/logs/maestro` | |
console.log(convertJavaPropertiesToEnvVars(configs)) | |
// output: | |
/* | |
- name : SERVER_PORT | |
value: 80 | |
- name : MAESTRO_KAFKA_BROKER | |
value: 10.11.7.31:9092 | |
- name : MAESTRO_KAFKA_INDEXING_TOPIC | |
value: maestro_index_requests | |
- name : MAESTRO_REPOSITORIES_0_CODE | |
value: collab | |
- name : MAESTRO_FAILURE_LOG_DIR | |
value: ${user.home}/logs/maestro | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment