Skip to content

Initial Work

Setting up credentials as an environment variable

The connection class accesses our environment variables saved locally on our computer. It is currently set up to access the bash or zsh file.

MAC OS & Linux

The below example is how you can access your bash file on a Mac. (https://phoenixnap.com/kb/set-environment-variable-mac)

There are 2 methods of saving credentials in your environment: manually or using the stout package.

To manually add credentials to your .bashrc file:

  1. Locate bashrc in the home directory by going to finder and to home directory
  2. Press command + shift + . To see the hidden .bashrc file
  3. Open the file
  4. Add the credentials

  5. In this format: - export [variable_name]=[variable_value] - For these credentials - Dev_v01xx_USR and Dev_v01xx_PWD - Prod_v01xx_USR and Prod_v01xx_PWD - OpenMRS_USR and OpenMRS_PWD - Put all usernames and passwords in double quotes

  6. Save the file
  7. Run in the terminal: source ~/.bashrc
  8. This will execute the bashrc file
  9. Optional

  10. To check that the variable is there you can run echo $Dev_v01xx_USR

  11. To list all the environment variables you run printenv
  12. Then hide the hidden files again in your finder by pressing command + shit + .

To add and save credentials via stout

Prerequisite: stout must be installed as a package 1. Open an instance of python 2. Import stout.credentials.Credential

from stout.credentials import Credential
  1. Instantiate the Credential class and set the credentials using the set_credentiol() method.
creds = Credential()

creds.set_credential(name = 'Prod_v01xx_USR', 
                     value = 'username_here')
creds.set_credential(name = 'Prod_v01xx_PWD', 
                     value = 'password_here')
  1. You can check to make sure the credentials are properly stored by calling either an individual stored credential or a set of credentails using the cred prefix:

To return the value of one:

creds.get_credential(name = 'Prod_v01xx_USR')
creds.get_credential(name = 'Prod_v01xx_PWD')
Returns

username_here
password_here

To return a dictionary of the credential set, provide the credential prefix:

creds.get_cred_set(prefix = 'Prod_v01xx')
Returns

{'USR': 'username_here',
 'PWD': 'password_here'}

Windows

  1. Navigate to your home directory
  2. Create a .env file.
  3. Add a test credential:
testkey='testvalue'

To manually add credentails to .env file

  1. Add the credentail and value to a new line in your .env file:
Prod_v01xx_USR = "username_here"
Prod_v01xx_PWD = "password_here"

To add and save credentials via stout

Prerequisite: stout must be installed as a package 1. Open an instance of python 2. Import stout.credentials.Credential

from stout.credentials import Credential
  1. Instantiate the Credential class and set the credentials using the set_credential() method.
creds = Credential()

creds.set_credential(name = 'Prod_v01xx_USR', 
                     value = 'username_here')
creds.set_credential(name = 'Prod_v01xx_PWD', 
                     value = 'password_here')
  1. You can check to make sure the credentials are properly stored by calling either an individual stored credential or a set of credentails using the cred prefix:

To return the value of one:

creds.get_credential(name = 'Prod_v01xx_USR')
creds.get_credential(name = 'Prod_v01xx_PWD')
Returns

username_here
password_here

To return a dictionary of the credential set, provide the credential prefix:

creds.get_cred_set(prefix = 'Prod_v01xx')
Returns

{'USR': 'username_here',
 'PWD': 'password_here'}