Setting up CDA writes and cwms-python on T7s
Important
This is a living document and are subject to change. Last updated:
Install local CDA instance: https://github.com/USACE/cwms-data-api/wiki/Installing-into-Tomcat
Generate API KEY
- Go to the following URL for your local instance of CDA where xxx is your district code: https://wm.XXX.ds.usace.army.mil:8243/CWMSLogin/login. Select your log in certificate and enter your pin. A agreement will appear. Click accept. An output will show up with your user and the CWMS user roles assigned to your account. In order to write data, the CWMS Users role is needed.
- If you get a “HTTP Status 404” error when trying to access that page then you need to Submit a General Request ticket to the G6 "Unix Web Server Support" Team. In the body of the ticket write: “Forward to Web Team. Web Team please coordinate with HEC to install CWMS Tomcat CAC auth components and CWMSLogin.war on coe-XXXuwa04XXX.XXX.usace.army.mil."
- In server admin, make sure your web user has the following permissions:
- Go to your CDA swagger page: https://wm.XXX.ds.usace.army.mil:8243/XXX-data/swagger-ui (An older version might have .html at the end, try the root XXX-data and a dropdown to confirm if you are not sure)
- Go to the Authorization endpoint and open the POST function.
- Click “Try it out.”
- In the example values dictionary, enter your UPASSID. Or the UPASSID for the ID you want to create a key for. (This is UPass ID on the T7, CAC Common Name on CWBI)
- Enter a key-name. This is a descriptor and can be anything that you can remember. Consider the system/account you are using the key on so you know which keys to revoke later. For production keys do not name it things like "Test-Key".
- Remove the "api-key" row
- If you need an expiration date, set one. Otherwise remove the expiration date. NOTE: Expiration dates will be enforced at a later date.
- Remove any trailing comma you might have that could give you a "JSON String parsing" error. Valid JSON does not end with a
, - After those values have been entered click Execute.
- If it worked, you should get a 201 Created response, an API key should be displayed. Save this api-key to be used to write data using CDA. NOTE: You will not see this key again. If you lose it you must delete the key you made and make another. You can remake it with the same name.
- You can use your api-key in cwms-python, cwms-cli, or using CDA. When using the api-key it needs to be prefixed with the word ‘apikey ’ (without the single quotes and it does need a space between the word apikey and your actual api-key).
- NOTE: If you are storing your API in a file to use in a script, we recommend storing it without the apikey prefix and then adding the prefix in your script itself. For steps on how to do this please follow the steps listed under "5" in the portion "Using CDA and cwms-python Server side" below.
Possible CAC Issues
If you are having strange issues or not getting prompted for a pin or certificate when you expect it, first close all browser windows and try again. Alternatively try a different browser to verify if it is the server or a client issue.
Using CDA and cwms-python Server side
- Use the newly installed python 3.9.18 version; /wm/wmsoft/python/v3.9.18-Solaris11.4.86.201.2.
- Connection for both cwbi-test and your local copy of CDA in python require access to DoW root certificates. Those certificates have been copied to the /wm/wmsoft/certs folder.
- To allow the python/request package to access them In your
.bashrcfile, add the following to the.bashrcfile:export REQUESTS_CA_BUNDLE=/wm/wmsoft/certs/cacert.pem(This is specific to therequestslibrary. Any API calls from other python libraries not using requests will not have the DoD certs included) - To store and use your api-key to write data in a python script, do the following:
- Create a folder .cwms in the /wm/xxx/xxcwpaxx folder that has 700 permissions.
- In the folder, create a file cda_api_key that has 700 permissions
- In the file, add your CDA_API_KEY to a single line.
- You can either access the api-key by grabbing and storing it in an environment variable in your .bashrc file.
- add the following to your .bashrc file to reference the api key file.
export CDA_API_KEY=$(< $CWMS_HOME/.cwms/cwbi_api_key)
- add the following to your .bashrc file to reference the api key file.
- We suggest adding the following to your .bashrc file:
- export CDA_API_ROOT=https://wm.XXX.ds.usace.army.mil:8243/XXX-data/ NOTE: on your COOP you would add the COOP address. The key would be the same!
- Then in your python scripts you can access it using:
CDA_API_ROOT = os.environ['CDA_API_ROOT']
- Update your symlink in /wm/localsoft/ to python3 to reference the new version of python.
- Install cwms-python:
- Run python3 -m pip install cwms-python.
- Update to a new version of cwms-python:
- Run python3 -m pip -U install cwms-python.
Using cwms-python on a workstation
- Follow the instructions in the Quick Start section in the cwms-python repo for installing python https://github.com/USACE-WaterManagement/pythonCWMS.
