-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathupdate-external-connection.sh
More file actions
executable file
·68 lines (51 loc) · 2.06 KB
/
update-external-connection.sh
File metadata and controls
executable file
·68 lines (51 loc) · 2.06 KB
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
#!/usr/bin/env bash
# Copyright IBM Corp. All Rights Reserved.
# Copyright 2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
if [[ -z "${FPC_PATH}" ]]; then
echo "Error: FPC_PATH not set"
exit 1
fi
trap cleanup SIGINT SIGTERM ERR EXIT
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
}
backup() {
FILE=$1
BACKUP="${FILE}.backup"
if [[ -e "${BACKUP}" ]]; then
cp "${BACKUP}" "${FILE}"
else
cp "${FILE}" "${BACKUP}"
fi
}
orgs=("org1" "org2")
user="Admin"
shopt -s nullglob
for org in "${orgs[@]}"; do
ORG_PATH=${FPC_PATH}/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/${org}.example.com
EXTERNAL_CONNECTIONS_PATH=${ORG_PATH}/external-connection-${org}.yaml
CONNECTIONS_PATH=${ORG_PATH}/connection-${org}.yaml
# Copy the file from the connection profile
cp "${CONNECTIONS_PATH}" "${EXTERNAL_CONNECTIONS_PATH}"
backup "${EXTERNAL_CONNECTIONS_PATH}"
# This is needed in both files
yq eval ".\"peer0.org1.example.com\".url = \"grpcs://peer0.org1.example.com:7051\"" -i "$EXTERNAL_CONNECTIONS_PATH"
yq eval ".\"peer0.org2.example.com\".url = \"grpcs://peer0.org2.example.com:9051\"" -i "$EXTERNAL_CONNECTIONS_PATH"
# Check if the org is org1
if [[ "$org" == "org1" ]]; then
# edit localhost urls to use hostnames for org1
yq eval ".peers.\"peer0.org1.example.com\".url = \"grpcs://peer0.org1.example.com:7051\"" -i "$EXTERNAL_CONNECTIONS_PATH"
yq eval ".certificateAuthorities.\"ca.org1.example.com\".url = \"https://ca.org1.example.com:7054\"" -i "$EXTERNAL_CONNECTIONS_PATH"
# Check if the org is org2
elif [[ "$org" == "org2" ]]; then
# edit localhost urls to use hostnames for org2
yq eval ".peers.\"peer0.org2.example.com\".url = \"grpcs://peer0.org2.example.com:9051\"" -i "$EXTERNAL_CONNECTIONS_PATH"
yq eval ".certificateAuthorities.\"ca.org2.example.com\".url = \"https://ca.org2.example.com:8054\"" -i "$EXTERNAL_CONNECTIONS_PATH"
fi
# remove entity matcher
yq eval 'del(.entityMatchers)' -i "$EXTERNAL_CONNECTIONS_PATH"
done
echo "Updated!"