-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathupdate-connection.sh
More file actions
executable file
·97 lines (78 loc) · 2.94 KB
/
update-connection.sh
File metadata and controls
executable file
·97 lines (78 loc) · 2.94 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# Copyright IBM Corp. All Rights Reserved.
# Copyright 2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -Eeuo pipefail
if [[ -z "${FPC_PATH}" ]]; then
echo "Error: FPC_PATH not set"
exit 1
fi
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
tmp_dir=$(mktemp -d -t tmp-XXXXXXXXXX --tmpdir="${script_dir}")
trap cleanup SIGINT SIGTERM ERR EXIT
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
rm -rf "${tmp_dir}"
}
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
CONNECTIONS_PATH=${ORG_PATH}/connection-${org}.yaml
backup "${CONNECTIONS_PATH}"
CERTS=("${ORG_PATH}/users/${user}@${org}.example.com/msp/signcerts"/*.pem)
KEYS=("${ORG_PATH}/users/${user}@${org}.example.com/msp/keystore"/*)
# add cryptopath and admin cert / key
yq ".organizations.${org^}.cryptoPath = \"${ORG_PATH}/msp\"" -i "${CONNECTIONS_PATH}"
yq ".organizations.${org^}.users.${user}.cert.path = \"${CERTS[0]}\"" -i "${CONNECTIONS_PATH}"
yq ".organizations.${org^}.users.${user}.key.path = \"${KEYS[0]}\"" -i "${CONNECTIONS_PATH}"
# Create temporary file with channels and entity matchers
temp_yaml=$(mktemp -t temp-XXXXXXXXXX.yaml --tmpdir="${tmp_dir}")
cat > "${temp_yaml}" <<EOF
channels:
_default:
peers:
peer0.${org}.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
entityMatchers:
peer:
- pattern: ([^:]+):(\d+)
urlSubstitutionExp: localhost:\${2}
sslTargetOverrideUrlSubstitutionExp: \${1}
mappedHost: \${1}
orderer:
- pattern: ([^:]+):(\d+)
urlSubstitutionExp: localhost:\${2}
sslTargetOverrideUrlSubstitutionExp: \${1}
mappedHost: \${1}
EOF
# add channels and entity matcher
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i "${CONNECTIONS_PATH}" "${temp_yaml}"
yq "${CONNECTIONS_PATH}" > /dev/null
# fetch all peers from connections
yq '(.peers) as $item ireduce({}; setpath($item | path; $item))' "${CONNECTIONS_PATH}" >> "${tmp_dir}/peers-${org}.yaml"
done
# consolidate all collected peers in a single peers.yaml
yq eval-all '. as $item ireduce ({}; . * $item )' ${tmp_dir}/peers-*.yaml >> "${tmp_dir}/peers.yaml"
# merge peers.yaml into all connection files
for org in "${orgs[@]}"; do
ORG_PATH="${FPC_PATH}/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/${org}.example.com"
CONNECTIONS_PATH="${ORG_PATH}/connection-${org}.yaml"
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' -i "${CONNECTIONS_PATH}" "${tmp_dir}/peers.yaml"
yq "${CONNECTIONS_PATH}" > /dev/null
done
echo "Updated!"