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:
- Locate bashrc in the home directory by going to finder and to home directory
- Press command + shift + . To see the hidden .bashrc file
- Open the file
-
Add the credentials
-
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
- Save the file
- Run in the terminal: source ~/.bashrc
- This will execute the bashrc file
-
Optional
-
To check that the variable is there you can run echo $Dev_v01xx_USR
- To list all the environment variables you run printenv
- 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
- 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')
- 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:
ReturnsTo return a dictionary of the credential set, provide the credential prefix:
ReturnsWindows
- Navigate to your home directory
- Create a
.env
file. - Add a test credential:
To manually add credentails to .env file
- Add the credentail and value to a new line in your
.env
file:
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
- 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')
- 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:
ReturnsTo return a dictionary of the credential set, provide the credential prefix:
Returns