Spring Boot Application Properties Variable Conversion/Matching when retrieved from ENV variable? - spring-boot

In my application.yaml properties file I have a variable defined as below -
service-account:
# secret: //commented in the yaml file, to indicate that it's used in app but read from ENV variable.
From this SOF post, I understand how . (dots) and - (dashes) are converted.
Now in the ENV variables file - I don't have anything like -
service-account.secret or service-account_secret or service_account_secret etc
instead what i have in the env (file) is - SERVICEACCOUNT_SECRET=xyz
Does spring boot match variable service-account.secret in props file with SERVICEACCOUNT_SECRET env variable.
Can someone confirm.

Does spring boot match variable service-account.secret in props file with SERVICEACCOUNT_SECRET env variable.
Yes. The canonical form of a property is all lower-case with - and . separators. service-account.secret is in the canonical form. To convert from the canonical form to an environment variable, Spring Boot does the following:
Replaces dots (.) with underscores (_)
Removes any dashes (-)
Converts to uppercase
Following these steps, service-account.secret becomes SERVICEACCOUNT_SECRET so you can use the SERVICEACCOUNT_SECRET environment variable to set the service-account.secret property.

Related

strip quotes from variable from .env file included in makefile

I have a situation where I have an environment variable with space character inside. Some tools do not like quoting the value of the variable, as they will treat the quote as part of the variable.
This is set in a .env file.
PIP_EXTRA_INDEX_URL="https://token#repo https://token#repo"
When I include and export this .env file in a Makefile, I get this warning.
WARNING: Location '"https://token#repo' is ignored:
it is either a non-existing path or lacks a specific scheme.
But I have seen this behavior as initially mentioned also with other tools. Is there a way to handle this?
In the Makefile, I include it like below.
include .env
export
build:
docker build --build-arg PIP_EXTRA_INDEX_URL -t myimage .
Makefiles are not shell scripts and it is not possible to use the same syntax to define variables in both the shell and in make, except in very limited situations.
In the shell, you can have multiple assignments on the same line or even run programs on the same line. So, if your assignment has whitespace in it you have to quote it as you've done here.
In make, the syntax of an assignment is that all text after the assignment (and leading whitespace) becomes the value of the variable and there is no quoting needed; any quotes that are seen are kept as part of the variable value.
So, in the shell this assignment:
PIP_EXTRA_INDEX_URL='https://token#repo https://token#repo'
sets the shell variable PIP_EXTRA_INDEX_URL to the value https://token#repo https://token#repo ... note the quotes are stripped from the value by the shell.
In make this assignment:
PIP_EXTRA_INDEX_URL='https://token#repo https://token#repo'
sets the shell variable PIP_EXTRA_INDEX_URL to the value 'https://token#repo https://token#repo' ... note the quotes are not stripped from the value by make.
So if you use this value in a recipe like this:
do something "$(PIP_EXTRA_INDEX_URL)"
then make will expand that variable and you'll get:
do something "'https://token#repo https://token#repo'"
(including quotes) and that's your problem.
It works like this.
build:
docker build --build-arg PIP_EXTRA_INDEX_URL=$(PIP_EXTRA_INDEX_URL) -t myimage .

Using date as an ENV variable in GitHub action

This is very funny but very frustrating problem. I am using an ENV variable, which specifies date. I provide an ISO 8601 compliant version and in application, I retrieve it and parse. When I specify it in GH action workflow, it is get parsed as a date (rather than a string) and formatted. Therefore, my application parsing fails.
Example:
.github/workflows/rust.yaml
env:
MY_DATE: '2020-10-07T12:00:00+01:00'
run: echo $MY_DATE
Result (GH action UI):
env:
TMOU_GAME_END: 10/07/2020 11:00:00
10/07/2020 11:00:00
It is specific to GitHub action and their yaml parsing, it works OK on Heroku, on various local setups, etc.
Things I tried and they don't work:
using no quotes, single quotes ('), double quotes (")
setting another ENV var, LC_TIME to en_DK.UTF-8
using !!str shorthand (see https://yaml.org/spec/1.2/spec.html, section Example 2.23. Various Explicit Tags); this one fails either with  The workflow is not valid. .github/workflows/rust.yml: Unexpected tag 'tag:yaml.org,2002:str' or with The workflow is not valid. .github/workflows/rust.yml: The scalar style 'DoubleQuoted | SingleQuoted' on line 29 and column 24 is not valid with the tag 'tag:yaml.org,2002:str'
Is there any help? Any secret parameter I can turn on? Any escaping sequence? I just wanna GH Actions yaml parser to treat the value as a string.
Surprisingly, it seems GitHub Actions workflow YAML parser does not fully implement the standard and using explicit typing (like !!str) does not work. You can, however, workaround it by setting the environment variable to the desired value not in the YAML file itself but dynamically during workflow execution using a dedicated workflow command:
steps:
- name: Dynamically set MY_DATE environment variable
run: echo "MY_DATE=2020-10-07T12:00:00+01:00" >> $GITHUB_ENV
- name: Test MY_DATE variable
run: echo ${{ env.MY_DATE }}
This should do the trick.

How to use env variable as reference of other env variable?

I am using Laravel 5.4 and vlucas/phpdotenv library.
I wants to take reference of one env variable to other env variable e.g.
APP_NAME: JUSTDOIT
SIGNUP_KEY: JUSTDOIT_SIGNUP
here in SIGNUP_KEY I wants to use whatever APP_NAME it is.
Ahh, I found the answer here, Not removing the question as it may help to other,
It's possible to nest an environment variable within another, useful to cut down on repetition.
This is done by wrapping an existing environment variable in ${…} e.g.
APP_NAME: JUSTDOIT
SIGNUP_KEY: ${APP_NAME}_SIGNUP
additionally if you wants to use space in variable value then encluse this with "quotes" e.g.
SIGNUP_KEY: "${APP_NAME} SIGNUP"
Reference:
https://github.com/vlucas/phpdotenv#nesting-variables

What do double colons with parameter expansion do?

What does subjectAltName = ${ENV::subjectAltName} in a shell script mean? I've tried this locally on MacOS and it just returns null.
I've gone to various tutorials on bash scripting and I have found that something like
subjectAltName = ${ENV:-subjectAltName}
would mean if ENV is unset or null, the expansion of subjectAltName is substituted. Otherwise, the value of ENV is substituted but I have not seen double colons in the context of parameter expansion. See here for that tutorial. Also here.
I've also seen this usage:
$ENV::HOME/.rnd
Here, I expect a concatenation for whatever these variables are.
This is used for an openssl.conf file.
It's not shell syntax, it's a feature unique to openssl.conf and the OpenSSL CONF library. The config(5) man page says:
It is also possible to substitute a value from another section using the syntax $section::name or ${section::name}. By using the form $ENV::name environment variables can be substituted.

Expand tilde path in YAML file

I am trying to use ~/Development/Project in a YAML file but it doesn't get expanded to /Users/revolt/Development/Project:
repos:
- repo: ~/Development/Project
can it somehow access the bash's $HOME variable?
As #tinita mentioned here, YAML is just a serialization language, so it's not possible.
Functionality like this must be implemented in the software that uses the respective file.

Resources