From 99374fcf0b7f006115db09c42443c6cb9a27a99e Mon Sep 17 00:00:00 2001
From: Khai Do <3697686+zaro0508@users.noreply.github.com>
Date: Fri, 13 Dec 2024 17:01:34 -0800
Subject: [PATCH] [IT-3964] Update synapse client usage (#129)

The latest version of the synapse client no longer supports
authentication with passwords, it now requires a personal access token
---
 .github/workflows/main.yaml |  3 +--
 README.md                   |  7 +++----
 import-data.sh              | 15 +++++++--------
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index 5e1e214..db640e0 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -26,10 +26,9 @@ jobs:
       # use older checkout version due to https://github.com/dawidd6/action-download-artifact/issues/261
       - uses: actions/checkout@v2
       - name: Import Synapse Data
-        run: ./import-data.sh $BRANCH $SYNAPSE_USERNAME $SYNAPSE_PASSWORD $DB_HOST $DB_USER $DB_PASS
+        run: ./import-data.sh $BRANCH $SYNAPSE_PASSWORD $DB_HOST $DB_USER $DB_PASS
         env:
           BRANCH: ${{ github.ref_name }}
-          SYNAPSE_USERNAME: ${{ secrets.SYNAPSE_USERNAME }}
           SYNAPSE_PASSWORD: ${{ secrets.SYNAPSE_PASSWORD }}
           DB_HOST: ${{ secrets.DB_HOST }}
           DB_USER: ${{ secrets.DB_USER }}
diff --git a/README.md b/README.md
index 37d2749..0821942 100644
--- a/README.md
+++ b/README.md
@@ -36,10 +36,9 @@ The following secrets need to be setup in Github for the scripts to deploy datab
 
 Global secrets:
 
-| Variable             | Description                       | Example                     |
-|----------------------|-----------------------------------|-----------------------------|
-| SYNAPSE_USERNAME     | The Synapse service user          | syn-service-user            |
-| SYNAPSE_PASSWORD     | The Synapse service user password | supersecret                 |
+| Variable             | Description                      | Example                          |
+|----------------------|----------------------------------|----------------------------------|
+| SYNAPSE_PASSWORD     | Synapse service user token (PAT) | glY4283tLQHZ...0eXAiOi...JKV1QiL |
 
 
 Context specific secrets for each environment that corresponds to a git branch (develop/staging/prod):
diff --git a/import-data.sh b/import-data.sh
index a8a0c33..7a88cba 100755
--- a/import-data.sh
+++ b/import-data.sh
@@ -6,11 +6,10 @@
 set -e
 
 BRANCH=$1
-SYNAPSE_USERNAME=$2
-SYNAPSE_PASSWORD=$3
-DB_HOST=$4
-DB_USER=$5
-DB_PASS=$6
+SYNAPSE_PASSWORD=$2
+DB_HOST=$3
+DB_USER=$4
+DB_PASS=$5
 
 CURRENT_DIR=$(pwd)
 WORKING_DIR=$CURRENT_DIR
@@ -26,7 +25,7 @@ TEAM_IMAGES_ID=$(cat $WORKING_DIR/data-manifest.json | grep team-images-id | hea
 echo "$BRANCH branch, DATA_VERSION = $DATA_VERSION, manifest id = $DATA_MANIFEST_ID"
 
 # Download the manifest file from synapse
-synapse -u $SYNAPSE_USERNAME -p $SYNAPSE_PASSWORD get --downloadLocation $DATA_DIR -v $DATA_VERSION $DATA_MANIFEST_ID
+synapse -p $SYNAPSE_PASSWORD get --downloadLocation $DATA_DIR -v $DATA_VERSION $DATA_MANIFEST_ID
 
 # Ensure there's a newline at the end of the manifest file; otherwise the last listed file will not be downloaded
 # echo >> $DATA_DIR/data_manifest.csv
@@ -34,11 +33,11 @@ synapse -u $SYNAPSE_USERNAME -p $SYNAPSE_PASSWORD get --downloadLocation $DATA_D
 # Download all files referenced in the manifest from synapse
 cat $DATA_DIR/data_manifest.csv | tail -n +2 | while IFS=, read -r id version; do
   echo Downloading $id,$version
-    synapse -u $SYNAPSE_USERNAME -p $SYNAPSE_PASSWORD get --downloadLocation $DATA_DIR -v $version $id ;
+    synapse -p $SYNAPSE_PASSWORD get --downloadLocation $DATA_DIR -v $version $id ;
   done
 
 # Download team images
-synapse -u $SYNAPSE_USERNAME -p $SYNAPSE_PASSWORD get -r --downloadLocation $TEAM_IMAGES_DIR/ $TEAM_IMAGES_ID
+synapse -p $SYNAPSE_PASSWORD get -r --downloadLocation $TEAM_IMAGES_DIR/ $TEAM_IMAGES_ID
 
 echo "Data Files: "
 ls -al $WORKING_DIR