Repository: XENONnT/straxen (language: python)

Issue:
Added changes for user credentials
**What is the problem / what does the code in this PR do**
In this PR we add the requirement of putting personalized user credentials before queering things from our Slow Control Historian database. The syntax has not changed much as shown in the [the very last section of this notebook](https://github.com/XENONnT/analysiscode/blob/master/StraxTests/ScadaInterface.ipynb).

For some of our automatized services such as the online monitor and CMT we would need an additional "strax user account" which we can store in our .xenon_config file. In order to use this additional user the corresponding tools have to set a flag which is "private" to the interface and not visible from the outside. 

Beside asking for the user credentials I added some quality of life features like a function to ask for the remaining time a token is valid as well as two safeguards to ensure that a query does not fail because of an expired token. In the later case a renewing of the credentials is necessary. 

Further, I had to reduce the complexity of get_values. Hence, I clustered all time related checks and computations in a small helper function.


Discussion / hints:
Hi Daniel, it is indeed perhaps a good idea if some SC people look into this too. Perhaps ACs can help out if more eyes are needed.
terminology: "strax user account"  refers to an account _for_ strax users of the SC historians? 
Hej, thanks for the comments. This PR triggered some discussions if we should not go for a different authentication approach. Hence, it might be that the changes will never come. I will change the PR into a draft should have done this before, I am sorry about that.

> terminology: "strax user account" refers to an account for strax users of the SC historians?
It refers to a SC Historian account for strax. Some of our services as the online monitor and CMT need an account which do not require to manually reenter the credentials every 3 hrs.  
The failed test points to the test of the holoviews waveform plot. Dask dataframes are missing during import. I do not know why it is showing up now since the test was already added some time ago. 
So this PR is ready for merge, but we should wait until the next release since we have to updated the xenon config too. 
Thanks for the thorough review. I addressed your comments. We can merge this PR with the next release, have to time it a little bit though since we have to updated the xenon_config. 

Fix patch:
diff --git a/.github/scripts/create_readonly_utilix_config.sh b/.github/scripts/create_readonly_utilix_config.sh
index 562e8fb83..cb1ea03e3 100644
--- a/.github/scripts/create_readonly_utilix_config.sh
+++ b/.github/scripts/create_readonly_utilix_config.sh
@@ -22,9 +22,11 @@ pymongo_database = $PYMONGO_DATABASE
 [scada]
 scdata_url = $SCADA_URL
 sclastvalue_url = $SCADA_VALUE_URL
-querytype = $SCADA_QUERY_TYPE
-username = $SCADA_USER
-api_key = $SCADA_KEY
+
+sclogin_url = $SCADA_LOGIN_URL
+straxen_username = $SCADA_USER
+straxen_password = $SCADA_PWD
+pmt_parameter_names = no_file_found
 EOF
 echo "YEAH boy, complete github actions voodoo now made you have access to our database!"
 else
diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml
index a0284e514..8805bde48 100644
--- a/.github/workflows/coveralls.yml
+++ b/.github/workflows/coveralls.yml
@@ -35,6 +35,7 @@ jobs:
     - name: patch utilix file
       run: bash .github/scripts/create_readonly_utilix_config.sh
       env:
+        # Database
         RUNDB_API_URL: ${{ secrets.RUNDB_API_URL }}
         RUNDB_API_USER_READONLY: ${{ secrets.RUNDB_API_USER_READONLY }}
         RUNDB_API_PASSWORD_READONLY: ${{ secrets.RUNDB_API_PASSWORD_READONLY}}
@@ -42,11 +43,12 @@ jobs:
         PYMONGO_USER: ${{ secrets.PYMONGO_USER }}
         PYMONGO_PASSWORD: ${{ secrets.PYMONGO_PASSWORD }}
         PYMONGO_DATABASE: ${{ secrets.PYMONGO_DATABASE }}
+        # SCADA
         SCADA_URL: ${{ secrets.SCADA_URL }}
         SCADA_VALUE_URL: ${{ secrets.SCADA_VALUE_URL }}
-        SCADA_QUERY_TYPE: ${{ secrets.SCADA_QUERY_TYPE }}
         SCADA_USER: ${{ secrets.SCADA_USER }}
-        SCADA_KEY: ${{ secrets.SCADA_KEY }}
+        SCADA_LOGIN_URL: ${{ secrets.SCADA_LOGIN_URL }}
+        SCADA_PWD: ${{ secrets.SCADA_PWD }}
     - name: Coveralls
       env:
         NUMBA_DISABLE_JIT: 1


Test patch:
diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml
index a8b356568..2364deea0 100644
--- a/.github/workflows/pytest.yml
+++ b/.github/workflows/pytest.yml
@@ -16,6 +16,7 @@ on:
 
 jobs:
   update:
+    name: Pytest
     runs-on: ubuntu-latest
     strategy:
       matrix:
@@ -38,9 +39,10 @@ jobs:
         uses: py-actions/py-dependency-install@v2
       - name: patch utilix file
         # Since we skip this step for python 3.7, we are testing without the database
-        if: matrix.python-version == 3.6 ||  matrix.python-version == 3.8
+        if: matrix.python-version == 3.6 ||  matrix.python-version == 3.8 || matrix.python-version == 3.9
         run: bash .github/scripts/create_readonly_utilix_config.sh
         env:
+          # Rundb
           RUNDB_API_URL: ${{ secrets.RUNDB_API_URL }}
           RUNDB_API_USER_READONLY: ${{ secrets.RUNDB_API_USER_READONLY }}
           RUNDB_API_PASSWORD_READONLY: ${{ secrets.RUNDB_API_PASSWORD_READONLY}}
@@ -48,11 +50,12 @@ jobs:
           PYMONGO_USER: ${{ secrets.PYMONGO_USER }}
           PYMONGO_PASSWORD: ${{ secrets.PYMONGO_PASSWORD }}
           PYMONGO_DATABASE: ${{ secrets.PYMONGO_DATABASE }}
+          # SCADA
           SCADA_URL: ${{ secrets.SCADA_URL }}
           SCADA_VALUE_URL: ${{ secrets.SCADA_VALUE_URL }}
-          SCADA_QUERY_TYPE: ${{ secrets.SCADA_QUERY_TYPE }}
           SCADA_USER: ${{ secrets.SCADA_USER }}
-          SCADA_KEY: ${{ secrets.SCADA_KEY }}
+          SCADA_LOGIN_URL: ${{ secrets.SCADA_LOGIN_URL }}
+          SCADA_PWD: ${{ secrets.SCADA_PWD }}
       - name: Test package
         run: |
           python setup.py test -v