Configure environment

Now you’ll go through the process of updating your environment. First, some of your configuration steps will require the AWS account IDs of the other members of the consortium. Each member of the consortium should execute the following commands from their bash prompts, replacing 123456789012 with the retailer AWS ID and 123456789013 with the supplier AWS ID. Copy the following bash code snippet into a text file on your computer, substitute the account IDs for your two AWS accounts, and then copy the result and paste it into your terminal.

export RETAILER_AWS_ID=123456789012
export SUPPLIER_AWS_ID=123456789013

The Retailer should execute the following step.

export MEMBER_NAME='Retailer'

The Supplier should execute the following step.

export MEMBER_NAME='Supplier'

All members should execute the following steps.

The following commands add environment settings to your bash profile so that each time you open your Cloud9 terminal, it will automatically be configured. Paste the following bash code into your Cloud9 terminal.

cd
add_line_to_profile_if_not_there() { grep -qxF "$1" .bash_profile || echo "$1" >> .bash_profile; }
export line="export GOPATH=\"\$HOME/go\""
add_line_to_profile_if_not_there "$line"
export line="export GOROOT=/usr/local/go"
add_line_to_profile_if_not_there "$line"
export line="export PATH=\"\$GOROOT/bin:\$PATH\""
add_line_to_profile_if_not_there "$line"
export line="export PATH=\"\$PATH:\$HOME/go/src/github.com/hyperledger/fabric-ca/bin\""
add_line_to_profile_if_not_there "$line"
export line="export MEMBER_NAME='$MEMBER_NAME'"
add_line_to_profile_if_not_there "$line"
export line="export MEMBER_ABBREVIATION=\$(case \$MEMBER_NAME in Retailer) echo 'rt';; Supplier) echo 'sp';; esac)"
add_line_to_profile_if_not_there "$line"
export line="export MEMBER_ADMIN=\$(case \$MEMBER_NAME in Retailer) echo 'rtadmin';; Supplier) echo 'spadmin';; esac)"
add_line_to_profile_if_not_there "$line"
export line="export WORKER1_NAME=\$(case \$MEMBER_NAME in Retailer) echo 'rtworker';; Supplier) echo 'spworker';; esac)"
add_line_to_profile_if_not_there "$line"
export line="export WORKER1_PERMISSIONS=\$(case \$MEMBER_NAME in Retailer) echo 'receive_label';; Supplier) echo 'manufacture_ship';; esac)"
add_line_to_profile_if_not_there "$line"
export line="export WORKER2_NAME=\$(case \$MEMBER_NAME in Retailer) echo 'rtseller';; Supplier) echo 'spinspector';; esac)"
add_line_to_profile_if_not_there "$line"
export line="export WORKER2_PERMISSIONS=\$(case \$MEMBER_NAME in Retailer) echo 'sell';; Supplier) echo 'inspect';; esac)"
add_line_to_profile_if_not_there "$line"
export line="export AWS_DEFAULT_REGION=\$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -c -r .region)"
add_line_to_profile_if_not_there "$line"
export line="export NETWORKID=\$(aws managedblockchain list-networks | jq -r '.Networks[] | select(.Name == \"SupplyChain\").Id')"
add_line_to_profile_if_not_there "$line"
export line="export ORDERER=\$(aws managedblockchain get-network --network-id \$NETWORKID | jq -r .Network.FrameworkAttributes.Fabric.OrderingServiceEndpoint)"
add_line_to_profile_if_not_there "$line"
export line="export ORDERERNOPORT=\$(echo \$ORDERER | cut -f1 -d':')"
add_line_to_profile_if_not_there "$line"
export line="export MEMBERID=\$(aws managedblockchain list-members --network-id \$NETWORKID | jq -r \".Members[] | select(.Name == \\\"\$MEMBER_NAME\\\") | .Id\")"
add_line_to_profile_if_not_there "$line"
export line="export BUCKET_NAME=\$(echo \$NETWORKID | tr '[:upper:]' '[:lower:]')-certs"
add_line_to_profile_if_not_there "$line"
export line="export MEMBER_AWS_ID=$(aws sts get-caller-identity --query Account --output text)"
add_line_to_profile_if_not_there "$line"
export line="export RETAILER_AWS_ID=$RETAILER_AWS_ID"
add_line_to_profile_if_not_there "$line"
export line="export SUPPLIER_AWS_ID=$SUPPLIER_AWS_ID"
add_line_to_profile_if_not_there "$line"
export line="export RETAILERID=\$(aws managedblockchain list-members --network-id \$NETWORKID | jq -r \".Members[] | select(.Name == \\\"Retailer\\\") | .Id\")"
add_line_to_profile_if_not_there "$line"
export line="export SUPPLIERID=\$(aws managedblockchain list-members --network-id \$NETWORKID | jq -r \".Members[] | select(.Name == \\\"Supplier\\\") | .Id\")"
add_line_to_profile_if_not_there "$line"
export line="export CASERVICEENDPOINT=\$(aws managedblockchain get-member --network-id \$NETWORKID --member-id \$MEMBERID | jq -r .Member.FrameworkAttributes.Fabric.CaEndpoint)"
add_line_to_profile_if_not_there "$line"
export line="export PEER1ID=\$(aws managedblockchain list-nodes --network-id \$NETWORKID --member-id \$MEMBERID | jq -r \"[.Nodes[] | select(.Status == \\\"AVAILABLE\\\")][0].Id\")"
add_line_to_profile_if_not_there "$line"
export line="export PEER2ID=\$(aws managedblockchain list-nodes --network-id \$NETWORKID --member-id \$MEMBERID | jq -r \"[.Nodes[] | select(.Status == \\\"AVAILABLE\\\")][1].Id\")"
add_line_to_profile_if_not_there "$line"
export line="export PEER1ENDPOINT=\$(aws managedblockchain get-node --network-id \$NETWORKID --member-id \$MEMBERID --node-id \$PEER1ID | jq -r .Node.FrameworkAttributes.Fabric.PeerEndpoint)"
add_line_to_profile_if_not_there "$line"
export line="export PEER1ENDPOINTNOPORT=\$(echo \$PEER1ENDPOINT | cut -f1 -d':')"
add_line_to_profile_if_not_there "$line"
export line="export PEER1EVENTENDPOINT=\$(aws managedblockchain get-node --region \$AWS_DEFAULT_REGION --network-id \$NETWORKID --member-id \$MEMBERID --node-id \$PEER1ID --query 'Node.FrameworkAttributes.Fabric.PeerEventEndpoint' --output text)"
add_line_to_profile_if_not_there "$line"
export line="export PEER2ENDPOINT=\$(aws managedblockchain get-node --network-id \$NETWORKID --member-id \$MEMBERID --node-id \$PEER2ID | jq -r .Node.FrameworkAttributes.Fabric.PeerEndpoint)"
add_line_to_profile_if_not_there "$line"
export line="export PEER2ENDPOINTNOPORT=\$(echo \$PEER2ENDPOINT | cut -f1 -d':')"
add_line_to_profile_if_not_there "$line"
export line="export PEER2EVENTENDPOINT=\$(aws managedblockchain get-node --region \$AWS_DEFAULT_REGION --network-id \$NETWORKID --member-id \$MEMBERID --node-id \$PEER2ID --query 'Node.FrameworkAttributes.Fabric.PeerEventEndpoint' --output text)"
add_line_to_profile_if_not_there "$line"
export line="export TEST_CHANNEL_NAME=\$(echo \$MEMBER_NAME | tr '[:upper:]' '[:lower:]')channel"
add_line_to_profile_if_not_there "$line"

Now apply those changes by sourcing .bash_profile:

source ~/.bash_profile