Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. 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.

  2. Email the Python script to DataSelf.

  3. Sent Send credentials outside of email (e.g., text).

...

Python’s os.getenv method returns the value of the environment variable key, if it exists.

(For testing on your computer see Create Windows Environment Variables with PowerShell)

os.getenv Usage

Code Block
languagepy
import os

# Retrieve the value of the PASSWORD environment variable
password_credential = os.getenv('PASSWORD')
print(f"Password credential: {password_credential}")

# Optional Default if environment variable does not exist
# Attempt to retrieve a non-existent environment variable with a default value
custom_variable = os.getenv('CUSTOM_VARIABLE', 'default_value')
print(f"Custom Variable: {custom_variable}")

...

Code Block
languagepy
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

...

<CLIENTNAME>_<SCRIPT_NAME>_<VARIABLENAMVARIABLENAME>.

For example: AcmeACME_ACUSCRIPT_APINAME_PASSWORD, AcmeACME_ACUSCRIPT_APINAME_VENDOR_KEY, AcmeACME_ACUSCRIPT_APINAME_USER_KEY

Related Pages

Excerpt
hiddentrue
nameInternal_Note

INTERNAL NOTES:
Why would clients send us Python scripts?
Because they may have expertise in writing Python scripts and/or have existing ones they want us to run.
This includes, but is not limited to the mentions of Python @ ETL+ Data Source List
Jira has a REST API that can be accessed via Python. These scripts can do more than just write to the target DB (i.e., client's DW), btw.