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

  1. 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.  
    1. 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."
  2. In server admin, make sure your web user has the following permissions:
     
  3. Go to your CDA swagger page: https://wm.XXX.ds.usace.army.mil:8243/XXX-data/swagger-ui.html.
  4. Go to the Authorization endpoint and open the POST function.
  5. Click “Try it out.”
  6. In the example values dictionary, enter your UPASSID. Or the UPASSID for the ID you want to create a key for.
  7. Enter a key-name. This is a descriptor and can be anything that you can remember.
  8. You can leave the api-key as ‘string’. The function will create an api key for you.
  9. Enter an expiration date in the future. You will need to update your api key before the "expires" date.
  10. After those values have been entered click Execute.
  11. Under the 201 Created response, an API key should be displayed. Save this api-key to be used to write data using CDA. 
  12. You can use your api-key in cwms-python 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). 
    1. 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

  1. Use the newly installed python 3.9.18 version; /wm/wmsoft/python/v3.9.18-Solaris11.4.86.201.2.
  2. Connection for both cwbi-test and your local copy of CDA in python require access to DOD root certificates. Those certificates have been copied to the /wm/wmsoft/certs folder.
  3. To allow the python/request package to access them In your .bashrc file, enter the following: export REQUESTS_CA_BUNDLE=/wm/wmsoft/certs/cacert.pem.
  4. To store and use your api-key to write data in a python script, do the following:
    1. Create a folder .cwms in the /wm/xxx/xxcwpaxx folder that has 700 permissions.
    2. In the folder, create a file cda_api_key that has 700 permissions
    3. In the file, add your API_KEY to a single line.
    4. You can either access the api-key by grabbing and storing it in an environment variable in your .bashrc file, or you can add the following to your .bashrc file to reference the api key file. 
      1. export CWBI_API_KEY=$(< $CWMS_HOME/.cwms/cwbi_api_key)
    5. I would also suggest adding the following to you .bashrc file:
      1. export CDA_API_ROOT=https://wm.XXX.ds.usace.army.mil:8243/XXX-data/
    6. Then in your python scripts you can access it using:
      1. APIROOT = os.environ['CDA_API_ROOT']
  5. Update your symlink in /wm/localsoft/  to python3 to reference the new version of python.
  6. Install cwms-python:
    1. Run python3 -m pip install cwms-python.
  7. Update to a new version of cwms-python:
    1. Run python3 -m pip -U install cwms-python.

Using cwms-python on a workstation

  1. Follow the instructions in the Quick Start section in the cwms-python repo for installing python https://github.com/USACE-WaterManagement/pythonCWMS