Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBMTD Agency card server setup #297

Closed
13 tasks done
Tracked by #295
thekaveman opened this issue Aug 16, 2023 · 5 comments
Closed
13 tasks done
Tracked by #295

SBMTD Agency card server setup #297

thekaveman opened this issue Aug 16, 2023 · 5 comments
Assignees
Labels
infrastructure Terraform, Azure, etc.

Comments

@thekaveman
Copy link
Member

thekaveman commented Aug 16, 2023

Depends on #296

Based on notes from when we did this for MST.

Azure

Agency card server

az login --service-principal -u <object id> -p <secret> --tenant <tenant id>
  • Confirm upload command:
az storage blob upload -f <file.txt> --account-name <account> \
  -c <storage container> --name <file.txt> --auth-mode login --overwrite
  • Write the above commands to a file named load.bat
  • Determine table structure and query for Agency card database, e.g.
SELECT U.MobilityPassId as sub, U.LastName as name, 'mobility_pass' AS type
FROM Users U INNER JOIN UserCredentials UC ON U.MobilityPassId = UC.MobilityPassId 
WHERE UC.Active = 1 AND U.LastName <> ''
ORDER BY U.LastName, U.MobilityPassId
  • Use bcp to extract records into UTF-8 encoded (codepoint 65001) CSV with a header row in a file extract.bat:
bcp "SELECT ..." queryout data.txt -T -c -C 65001 -d <DATABASE> -S <SERVER> -t ,

echo sub,name,type >> temp.txt
type data.txt >> temp.txt
del data.txt
ren temp.txt data.txt
  • Install hashfields (and potentially Python as well)
  • Run hashfields, confirm hashed output, then add to a file transform.bat:
hashfields --alg sha512 --skip type -i <file.csv> -o <file.hashed.csv>
  • Create etl.bat file to run all 3 steps in sequence
extract.bat && transform.bat && load.bat
  • Create scheduled task to run etl.bat nightly
@thekaveman thekaveman added the infrastructure Terraform, Azure, etc. label Aug 16, 2023
@thekaveman thekaveman added this to the SBMTD milestone Aug 16, 2023
@thekaveman thekaveman moved this from Todo to Blocked in Digital Services Aug 16, 2023
@thekaveman thekaveman moved this from Blocked to In Progress in Digital Services Sep 1, 2023
@thekaveman
Copy link
Member Author

thekaveman commented Sep 1, 2023

We were seeing the following error in running the bcp extraction script:

SELECT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. 
Verify that SET options are correct for use with indexed views and/or indexes on computed columns 
and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.

This bcp flag may be relevant: https://learn.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2016#-q

See also: https://dba.stackexchange.com/a/310575

@thekaveman
Copy link
Member Author

❗ File encoding matters ❗

We must ensure the bcp command outputs a file encoded in UTF-8, which is the encoding expected by hashfields and eligibility-server.

By default bcp outputs an ANSI encoded file!

Use the -C option to specify a code page, where 65001 is the code page for UTF-8:

bcp "SELECT ..." queryout data.txt -C 65001 ...

@thekaveman thekaveman moved this from In Progress to Paused in Digital Services Sep 18, 2023
@thekaveman thekaveman moved this from Paused to Todo in Digital Services Sep 27, 2023
@thekaveman thekaveman moved this from Todo to In Progress in Digital Services Oct 26, 2023
@thekaveman thekaveman moved this from In Progress to Blocked in Digital Services Oct 31, 2023
@thekaveman
Copy link
Member Author

Waiting to hear back from SBMTD about a network/firewall issue blocking the Azure CLI.

@thekaveman thekaveman moved this from Blocked to In Review in Digital Services Nov 13, 2023
@thekaveman thekaveman moved this from In Review to In Progress in Digital Services Nov 13, 2023
@thekaveman
Copy link
Member Author

SBMTD was able to get passed the network/firewall issue and the az login command succeeded!

@thekaveman
Copy link
Member Author

We met with SBMTD today and got the full end-to-end process working to bring Mobility Pass data from their server into Azure!

Marking this ticket as complete 👍 ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Terraform, Azure, etc.
Projects
Status: Done
Development

No branches or pull requests

3 participants