Question
· Jun 5, 2023

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):

<Item Name="shvarov.i14y.ChatOperation" Category="Reddit" ClassName="Telegram.BusinessOperation" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Adapter" Name="SSLConfig">default</Setting>
<Setting Target="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?

Discussion (7)2
Log in or sign up to continue

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']
* 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.py here