Skip to content

Instantly share code, notes, and snippets.

@blabadi
Last active May 10, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blabadi/d5ba492f610820b388469fec97f35676 to your computer and use it in GitHub Desktop.
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
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