-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSAMPLE-End-Customer-Upload-To-Blob.sh
80 lines (60 loc) · 2.91 KB
/
SAMPLE-End-Customer-Upload-To-Blob.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
###########################################################
# This is a sample Bash script an end customer can use to upload data to the landing zone
# The customer will need to install "jq" to parse the returned JSON: https://stedolan.github.io/jq/download/
# Note: This does not work with the local storage emulator
###########################################################
###########################################################
# Variables
###########################################################
azureFunctionUrl="https://functionapp00005.azurewebsites.net"
customerId="AcmeInc"
customerSecret="0DC8B9026ECD402C84C66AFB5B87E28C"
azureFunctionazureFunctionCode="baBqKrKC97HA/sLvZvjHtxCq82a43UmevfNSOwJU9DSuUXt6dUAixA=="
today=`date +%Y-%m-%d`
###########################################################
# Call to get SAS token
###########################################################
json=$(curl "$azureFunctionUrl/api/GetAzureStorageSASUploadToken?code=$azureFunctionazureFunctionCode&customerId=$customerId&customerSecret=$customerSecret")
###########################################################
# Parse the returned values
###########################################################
accountName="$(echo -n $json | jq .accountName --raw-output)"
containerName="$(echo -n $json | jq .containerName --raw-output)"
sasToken="$(echo -n $json | jq .sasToken --raw-output)"
echo "Account Name: $accountName"
echo "Container Name: $containerName"
echo "SAS Token: $sasToken"
###########################################################
# Create a Test Sample file to upload
###########################################################
echo "CustomerId,CustomerName" > myFile.csv
echo "1,Microsoft" >> myFile.csv
echo "2,Contoso" >> myFile.csv
echo "3,Acme" >> myFile.csv
echo "4,Walmart" >> myFile.csv
echo "5,Target" >> myFile.csv
###########################################################
# Upload one or many files
#
# NOTES:
# 1. You could use Azure PowerShell (Core)
# 2. You could use Azure CLI
# 3. You could use Azure azcopy commands (*** use this for uploading lots of large files ***)
###########################################################
# Target path
uri="https://$accountName.blob.core.windows.net/$containerName/inbox/$today/myFile.csv$sasToken"
headers="x-ms-blob-type:BlockBlob"
# Upload file using just REST
curl $uri -H $headers --upload-file myFile.csv
###########################################################
# Upload the signal file that we are done uploading
# Single to Azure we are done by putting a marker complete file
# The file MUST end in "end_file.txt"
###########################################################
# Create a marker file
touch end_file.txt
# Target path
uri="https://$accountName.blob.core.windows.net/$containerName/inbox/$today/end_file.txt$sasToken"
headers="x-ms-blob-type:BlockBlob"
# Upload file using just REST
curl $uri -H $headers --upload-file end_file.txt