Excerpt |
---|
For security we do not run Python scripts containing embedded credentials or other confidential information on DataSelf cloud servers. Nor do we want to send or receive scripts with credentials via email. How to prepare Python scripts to read credentials and other secure information from Windows environment variables. |
...
Use Python’s
os.getenv
method to replace constants and literal values of credentials and other secure values with calls to Window’s environment variables.For testing on your computer see Create Windows Environment Variables with PowerShell.
Email the Python script to DataSelf.
Sent Send credentials outside of email (e.g., text).
...
Code Block | ||
---|---|---|
| ||
import os body={ "name" : "gshuabcd", "password" : os.getenv('CONNECTEDACME_ACUSCRIPT_APINAME_PASSWORD'), #Modify this to get password "company" : "ConnectedACME", "branch" : "2J1", "locale" : "en-US" } def get_metrc_encoding(): vendor_key = os.getenv('AcmeACME_ACUSCRIPT_APINAME_VENDOR_KEY') # Modify this to get vendor key user_key = os.getenv('AcmeACME_ACUSCRIPT_APINAME_USER_KEY') # Modify this to get user key encoding_str = f"{vendor_key}:{user_key}" encoding = base64.b64encode(encoding_str.encode()) encoding = encoding.decode('ASCII') return encoding |
vendor_key = os.getenv('CONNECTED_ACU_API_VENDOR_KEY') # Modify this to get vendor key
Naming Convention
DataSelf’s naming convention for environment variables used in scripts is:
<CLIENTNAME>_<SCRIPT_NAME>_<VARIABLENAMVARIABLENAME>.
For example: AcmeACME_ACUSCRIPT_APINAME_PASSWORD, AcmeACME_ACUSCRIPT_APINAME_VENDOR_KEY, AcmeACME_ACUSCRIPT_APINAME_USER_KEY
Related Pages
https://www.w3schools.com/python/ref_os_getenv.asp Python os.getenv() Method
Excerpt | ||||
---|---|---|---|---|
| ||||
INTERNAL NOTES: |