Is it possible to use ENV variables for production parameters?
Hi folks!
Is it possible to use Environment variables for production settings?
E.g. I have a telegram adapter for which I need to setup token(part of the production below):
<ItemName="shvarov.i14y.ChatOperation"Category="Reddit"ClassName="Telegram.BusinessOperation"PoolSize="1"Enabled="true"Foreground="false"Comment=""LogTraceEvents="false"Schedule=""><SettingTarget="Adapter"Name="SSLConfig">default</Setting><SettingTarget="Adapter"Name="Token">"some-telegram-token"</Setting></Item>Is it possible to point the expression for Token setting "some-telegram-token" which will collect it from env-variable?
Comments
Hi Evegny,
You can do it in the following way:
- in the production settings, with DefaultSettings docs here
- but default settings is a kind of replacement for environment variables
- you can to it in the code :
- ObjectScript:
$system.Util.GetEnviron("MY_ENV_VAR") - Python:
os.environ['MY_ENV_VAR']
- ObjectScript:
- you can use
iop(interoperabilty on python) to import production in python way :
settings.py
import os
PRODUCTIONS = [
{
'shvarov.i14y.Production': {
"Item": [
{
"@Name": "shvarov.i14y.ChatOperation",
"@ClassName": "Telegram.BusinessOperation",
"@Category": "Reddit",
"@PoolSize": "1",
"@Enabled": "true",
"@Foreground": "false",
"@Comment": "",
"@LogTraceEvents": "false",
"@Schedule": "",
"Setting": [
{
"@Target": "Adapter",
"@Name": "SSLConfig",
"#text": "default"
},
{
"@Target": "Adapter",
"@Name": "Token",
"#text": os.environ['TELEGRAM_TOKEN']
}
]
}
]
}
}
]
and then in the terminal:
$ iop -M settings.py
More information about iop and settings.pyhere
Thanks @Guillaume Rongier !
Is it possible to use your export/import mechanism to change only one element of the production?
For now it ended in the following way:
USER>d ##class(shvarov.telegramgpt.Setup).Init($system.Util.GetEnviron("TG_BOT_TOKEN"),$system.Util.GetEnviron("OPENAPI_KEY"))This is how we can setup production after docker build and start in the following project. Thank you, @Guillaume Rongier
Would this make sense as an enhancement to System Default Settings?
So in System Default Settings input to a new "Environment Name" field instead of completing "Value" field?
Have created idea: https://ideas.intersystems.com/ideas/DPI-I-381
https://docs.intersystems.com/irisforhealth20232/csp/docbook/DocBook.UI…
.png)
Good idea, it environment variable is not found switch to settings value.
I like it.
Voted!