-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
91 lines (78 loc) · 5.86 KB
/
setup.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
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# first argument is the docker compose file to use.
# Defaults to docker-compose-nginx.yml if no argument is provided. The setup is independent of the PEP, so usually fine to not set.
DOCKER_FILE=${1-docker-compose-nginx.yml}
echo "----------------------------------------"
echo "Removing data and restarting nodes..."
echo "----------------------------------------"
# stop all containers so we can delete all data
docker compose -f ${DOCKER_FILE} down
sleep 0.5 # If containers fail to restart below, make this longer
# delete all data
rm -r ./docker-compose/{left,right}/data/*/*
rm -r ./docker-compose/{left,right}/config/demo/customers.json
touch ./docker-compose/{left,right}/config/demo/customers.json # or docker will create directories for these mounts during startup
docker compose -f ${DOCKER_FILE} up --wait
echo "----------------------------------------"
echo "Creating DIDs..."
echo "----------------------------------------"
DID_LEFT=$(docker exec nuts-demo-ehr-node-left-1 curl -sS -X POST "http://localhost:8081/internal/vdr/v2/did" | jq -r .id)
DID_RIGHT=$(docker exec nuts-demo-ehr-node-right-1 curl -sS -X POST "http://localhost:8081/internal/vdr/v2/did" | jq -r .id)
echo "DID_LEFT: $DID_LEFT"
echo "DID_RIGHT: $DID_RIGHT"
echo "----------------------------------------"
echo "Issuing NutsOrganizationCredentials..."
echo "----------------------------------------"
# issue Left
REQUEST="{\"type\":\"NutsOrganizationCredential\",\"issuer\":\"${DID_LEFT}\", \"credentialSubject\": {\"id\":\"${DID_LEFT}\", \"organization\":{\"name\":\"Left\", \"city\":\"Enske\"}},\"withStatusList2021Revocation\": false}"
RESPONSE=$(echo $REQUEST | docker exec -i nuts-demo-ehr-node-left-1 curl -sS -X POST --data-binary @- http://localhost:8081/internal/vcr/v2/issuer/vc -H "Content-Type:application/json")
if echo $RESPONSE | grep -q "VerifiableCredential"; then
echo "NutsOrganizationCredential issued for Left"
else
echo "FAILED: Could not issue NutsOrganizationCredential for Left" 1>&2
echo $RESPONSE
fi
# add to wallet Left
RESPONSE=$(echo $RESPONSE | docker exec -i nuts-demo-ehr-node-left-1 curl -sS -X POST --data-binary @- http://localhost:8081/internal/vcr/v2/holder/${DID_LEFT}/vc -H "Content-Type:application/json")
if [[ $RESPONSE -eq "" ]]; then
echo "VC stored in wallet"
else
echo "FAILED: Could not load NutsOrganizationCredential for Left" 1>&2
echo $RESPONSE
fi
# issue Right
REQUEST="{\"type\":\"NutsOrganizationCredential\",\"issuer\":\"${DID_RIGHT}\", \"credentialSubject\": {\"id\":\"${DID_RIGHT}\", \"organization\":{\"name\":\"Right\", \"city\":\"Enske\"}},\"withStatusList2021Revocation\": false}"
RESPONSE=$(echo $REQUEST | docker exec -i nuts-demo-ehr-node-right-1 curl -sS -X POST --data-binary @- http://localhost:8081/internal/vcr/v2/issuer/vc -H "Content-Type:application/json")
if echo $RESPONSE | grep -q "VerifiableCredential"; then
echo "NutsOrganizationCredential issued for Right"
else
echo "FAILED: Could not issue NutsOrganizationCredential for Right" 1>&2
echo $RESPONSE
fi
# add to wallet Right
RESPONSE=$(echo $RESPONSE | docker exec -i nuts-demo-ehr-node-right-1 curl -sS -X POST --data-binary @- http://localhost:8081/internal/vcr/v2/holder/${DID_RIGHT}/vc -H "Content-Type:application/json")
if [[ $RESPONSE -eq "" ]]; then
echo "VC stored in wallet"
else
echo "FAILED: Could not load NutsOrganizationCredential for Left" 1>&2
echo $RESPONSE
fi
echo "----------------------------------------"
echo "Registering DIDs on Discovery Service..."
echo "----------------------------------------"
SERVICE="urn:nuts.nl:usecase:eOverdrachtDemo2024"
docker exec nuts-demo-ehr-node-left-1 curl -sS -X POST http://localhost:8081/internal/discovery/v1/${SERVICE}/${DID_LEFT}
docker exec nuts-demo-ehr-node-right-1 curl -sS -X POST http://localhost:8081/internal/discovery/v1/${SERVICE}/${DID_RIGHT}
echo "----------------------------------------"
echo "Adding services to DIDs..."
echo "----------------------------------------"
docker exec nuts-demo-ehr-node-left-1 curl -sS -X POST "http://localhost:8081/internal/vdr/v2/did/$DID_LEFT/service" -H "Content-Type: application/json" -d "{\"type\": \"eOverdracht-sender\",\"serviceEndpoint\": {\"auth\": \"https://node.left.local/oauth2/$DID_LEFT/authorize\",\"fhir\": \"https://left.local/fhir/1\"}}"
docker exec nuts-demo-ehr-node-left-1 curl -sS -X POST "http://localhost:8081/internal/vdr/v2/did/$DID_LEFT/service" -H "Content-Type: application/json" -d "{\"type\": \"eOverdracht-receiver\",\"serviceEndpoint\": {\"auth\": \"https://node.left.local/oauth2/$DID_LEFT/authorize\",\"notification\": \"https://left.local/web/external/transfer/notify\"}}"
docker exec nuts-demo-ehr-node-right-1 curl -sS -X POST "http://localhost:8081/internal/vdr/v2/did/$DID_RIGHT/service" -H "Content-Type: application/json" -d "{\"type\": \"eOverdracht-sender\",\"serviceEndpoint\": {\"auth\": \"https://node.right.local/oauth2/$DID_RIGHT/authorize\",\"fhir\": \"https://right.local/fhir/1\"}}"
docker exec nuts-demo-ehr-node-right-1 curl -sS -X POST "http://localhost:8081/internal/vdr/v2/did/$DID_RIGHT/service" -H "Content-Type: application/json" -d "{\"type\": \"eOverdracht-receiver\",\"serviceEndpoint\": {\"auth\": \"https://node.right.local/oauth2/$DID_RIGHT/authorize\",\"notification\": \"https://right.local/web/external/transfer/notify\"}}"
echo "----------------------------------------"
echo "Creating customers.json for demo-ehr..."
echo "----------------------------------------"
printf "{\n\t\"1\":{\"active\":false,\"city\":\"Enske\",\"did\":\"$DID_LEFT\",\"domain\":\"\",\"id\":1,\"name\":\"Left\"}\n}\n" > ./docker-compose/left/config/demo/customers.json
printf "{\n\t\"1\":{\"active\":false,\"city\":\"Enske\",\"did\":\"$DID_RIGHT\",\"domain\":\"\",\"id\":1,\"name\":\"Right\"}\n}\n" > ./docker-compose/right/config/demo/customers.json
docker compose -f ${DOCKER_FILE} down # at the minimum a restart is needed to load the new customers.json file