How can I set a Heroku config var to a JSON value? - json

I want to use a JSON value as a environment variable with heroku config:set.
But if I run this command:
heroku config:set FOO_JSON={"abc":"bcd","cde":"def" ... }
all " are removed like this:
FOO_JSON={abc:bcd,cde:def ... }
and I get a parse error.
How can I use JSON in Heroku's environment variables?

Heroku will remove the first and last " but that is fine, I had similar issue recently.
When you fetch the variable in your codebase, it will be wrapped with string quotations back so you can successfully JSON.parse(process.env.VARIABLE)
Example. I had a list of some banned users in my local .env
BANLIST = '["abdu","yak","jek","tosch","krek"]'
So, I can simply set
heroku config:set BANLIST='["abdu","yak","jek","tosch","krek"]'
or
heroku config:set BANLIST=["abdu","yak","jek","tosch","krek"]
Both of them will result to ["abdu","yak","jek","tosch","krek"].
So, when you fetch it back with JSON.parse(process.env.BANLIST), you will get the appropriate array output.
Warning: If you set the config variable wrapped with ' or " with heroku GUI interface, it will not set at all, so just put your array or object JSON without wrapping it with either of those

This is because of how your shell processes quotes. Wrap the whole thing in single quotes:
heroku config:set FOO_JSON='{"abc":"bcd","cde":"def" ... }'

Related

electron-builder generate latest.json instead of latest.yml

electron-builder generates "latest.yml" blockmap and exe for windows. But in production environment yml is not accepted. Need to change "latest.yml" to "latest.json". What are the configuration require to change "latest.yml" to "latest.json"?
electron-builder#^22.9.1
We tried it , there are no configuration options to change to json.We converted from yml to json at jenkins build . Electron-builder is using js-yaml node module to parse the yml response, which will accept both json and yml. If you send json instead of yml present version of electron-updater will accept and works fine.

Github Action Run - Security import is showing "One or more parameters passed to a function were not valid"error

I built the input file (decoded base64 file into p12 file) as CERTIFICATE_PATH, P12_PASSWORD is password in secret, KEYCHAIN_PATH is defined. when I run the command on CLI, I get "1 item imported" success message. but when I run from *.yml file on GitHub action, I get "security: SecKeychainItemImport: One or more parameters passed to a function were not valid." error. any suggestions?
security import $CERTIFICATE_PATH -P $P12_PASSWORD -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
CERTIFICATE_PATH - file that contains cert.p12 data,
KEYCHAIN_PATH is TEMP/app-signing.keychain-db
Another reason in Github actions could be that you are using the wrong environment.
Take a look at this ---> Difference between Github's "Environment" and "Repository" secrets?.
Set the right environment:
environment: production
found the issue.. was passing wrong cert file.. once added correct file in the security build , was able to get it working

spring boot --spring.application.json parameters not being set

I have a spring boot application that currently has a "mysql" profile that sets the following properties:
spring.datasource.url =
spring.datasource.username =
spring.datasource.password =
in /resources/application-mysql.properties file.
This is working great. When I run the mysql profile it connects to the local mysql database. When I don't run the mysql profile it uses the default h2 database. Next I want to get rid of the application.my-sql.properties and pass those values in via the command line. From the documentation here I would expect something like the following to work. But strangely, it never gets these properties and runs the h2 database instead.
java -jar myapp-0.0.1-SNAPSHOT.jar --spring.application.json='{"spring": {"datasource": {"url":"jdbc:mysql://localhost:3306/db", "username":"user","password":"pw"}}}'
I can confirm that this does work. As Vaelyr pointed out in the comments, setting it as system argument worked:
-Dspring.application.json='{"spring":{"datasource":{"username":"yourusername","password":"yourpassword"}}}'

Error passing large text with special characters in a variable to MYSQL

I have an script that connects with SSH to a remote Host, and executes another script there which inserts data into a local MySQL database. I pass all the variables that need to be inserted within the SSH. All works fine excepts for the $textBody variable.I think the problem is that there ara a lot of text in this variable (included special characters that may be causing the error).
ssh -p 22 $user#$IP_ADDRESS "$SCRIPTMYSQL \"$taulaName\" \"$valueType\" \"$valueTitle\" \"$textBODY\" exit"
This is the error I get:
jailshell: -u: command not found
ERROR at line 1: Unknown command '\S'.
If I pass another variable different than $textBODY in his place, no error occurs.
I'm passing double quotes inside the variable.
If $textBODY doesn't contain single quotes ', you can use them:
ssh -p 22 $user#$IP_ADDRESS "$SCRIPTMYSQL \"$taulaName\" \"$valueType\" \"$valueTitle\" '$textBODY' exit"
(that also applies to the other variables, of course).

How to capture JSON result from Azure CLI within NodeJS script

Is there a way to capture the JSON objects from the Azure NodeJS CLI from within a NodeJS script? I could do something like exec( 'azure vm list' ) and write a promise to process the deferred stdout result, or I could hijack the process.stream.write method, but looking at the CLI code, which is quite extensive, I thought there might be a way to pass a callback to the cli function or some other option that might directly return the JSON result. I see you are using the winston logger module -- I might be familiar with this, but perhaps there is a hook there that could be used.
azure vm list does have a --json option:
C:\>azure vm list -h
help: List Azure VMs
help:
help: Usage: vm list [options]
help:
help: Options:
help: -h, --help output usage information
help: -s, --subscription <id> use the subscription id
help: -d, --dns-name <name> only show VMs for this DNS name
help: -v, --verbose use verbose output
help: --json use json output
You can get the json result in the callback of an exec(...) call. Would this work for your?
Yes you can, check this gist: https://gist.github.com/4415326 and you'll see how without doing exec. You basically override the logger hanging off the CLI.
As a side note I am about to publish a new module, azure-cli-buddy that will make it easy to call the CLI using this technique and to receive results in JSON.