Commit 4f7e7dc7 authored by Marius Momeu's avatar Marius Momeu
Browse files

[Develop] Really useful scripts

parent b55ae051
# config files
configs/*
!configs/*template.json
# web-app ts files
web-app/src/environments/*
!web-app/src/environments/environment-template.ts
!web-app/src/environments/environment.ts
!web-app/src/environments/environment.prod.ts
# package.json and angular.json; when they're changed we need to force-push them
web-app/package.json
web-app/angular.json
# scripts to run auditchain
runnables
main-network
# ctags
......@@ -100,4 +117,3 @@ composer-network/bin/*
# pdf files
*.pdf
......@@ -26,7 +26,7 @@
** S1's REST API listens on port 3002
# Steps to interact with the Business Network:
* `composer card list` - pick one of the user*@auditchain* cards according to the channel you want to check
* `composer card list` - pick one of the user*@auditchain* cards according to the channel you want to interact with
* `composer network list -c <card>` - for checking the registries that the `card` has access to
* `Postman` or `curl` for various REST requests; the available REST Services and their usage can be consulted in `rest-api/modules/v0/assets/RestAPI_Description.txt`
......
{
"business_partner" : "<P>",
"business_partner_bcdb_mnemonic" : "<P>",
"composer_card" : "user1-<CHANNELNAME>-<C>@auditchain-<CHANNELNAME>",
"participant_name" : "user1-<CHANNELNAME>-<C>",
"id" : "<HYPERLEDGER_USER_ID>"
}
{
"name": "M1",
"description": "description of M1",
"logo_path": "M1 logo path",
"rest_api" : {
"port" : 3000,
"crypto_keys_path": "./keys/m1_id_rsa",
"hyperledger" : {
"role": "Manufacturer",
"channels" : [
{
"business_partner" : "S1",
"business_partner_bcdb_mnemonic" : "S1",
"composer_card" : "user1-manufacturer1@auditchain-exchange",
"participant_name" : "user1-manufacturer1",
"id" : "1001"
}
]
}
},
"bigchaindb": {
"mnemonic": "M1",
"app_id": "a6f5b578",
"app_key": "0cdea0b5a369dff5ee7849f42163221a",
"auditChainPublicKey": "6xuKg1qg3ykR45DiJzWTb4eaacmjSpQrWvaUB7aYvZQU",
"bigchainNetworkVersion": "2"
}
}
{
"name": "M2",
"description": "description of M2",
"logo_path": "M2 logo path",
"rest_api" : {
"port" : 3001,
"crypto_keys_path": "./keys/m2_id_rsa",
"hyperledger" : {
"role": "Manufacturer",
"channels" : [
{
"business_partner" : "S1",
"business_partner_bcdb_mnemonic" : "S1",
"composer_card" : "user2-manufacturer2@auditchain-acquisition",
"participant_name" : "user2-manufacturer2",
"id" : "2001"
}
]
}
},
"bigchaindb": {
"mnemonic": "M2",
"app_id": "a6f5b578",
"app_key": "0cdea0b5a369dff5ee7849f42163221a",
"auditChainPublicKey": "6xuKg1qg3ykR45DiJzWTb4eaacmjSpQrWvaUB7aYvZQU",
"bigchainNetworkVersion": "2"
}
}
{
"name": "S1",
"description": "description of S1",
"logo_path": "S1 logo path",
"rest_api" : {
"port" : 3002,
"crypto_keys_path": "./keys/s1_id_rsa",
"hyperledger" : {
"role": "Supplier",
"channels" : [
{
"business_partner" : "M1",
"business_partner_bcdb_mnemonic" : "M1",
"composer_card" : "user1-supplier1@auditchain-exchange",
"participant_name" : "user1-supplier1",
"id" : "1101"
},
{
"business_partner" : "M2",
"business_partner_bcdb_mnemonic" : "M2",
"composer_card" : "user2-supplier1@auditchain-acquisition",
"participant_name" : "user2-supplier1",
"id" : "2101"
}
]
}
},
"bigchaindb": {
"mnemonic": "S1",
"app_id": "a6f5b578",
"app_key": "0cdea0b5a369dff5ee7849f42163221a",
"auditChainPublicKey": "6xuKg1qg3ykR45DiJzWTb4eaacmjSpQrWvaUB7aYvZQU",
"bigchainNetworkVersion": "2"
}
}
{
"name": "<C>",
"description": "description of <C>",
"logo_path": "<C> logo path",
"name": "<COMPANY>",
"description": "description of <COMPANY>",
"logo_path": "<COMPANY> logo path",
"rest_api" : {
"port" : "<REST_API_PORT>",
"crypto_keys_path": "./keys/<C>_id_rsa",
"port" : <REST_API_PORT>,
"crypto_keys_path": "<AUDITCHAIN_PATH>/keys/<COMPANY>_id_rsa",
"hyperledger" : {
"role": "<HYPERLEDGER_ROLE>",
"channels" : [
{
"business_partner" : "<P>",
"business_partner_bcdb_mnemonic" : "<P>",
"composer_card" : "<USERNAME>-<CHANNELNAME>-<C>@auditchain-<CHANNELNAME>",
"participant_name" : "user1-supplier1",
"id" : "<ID>"
}
]
}
},
"bigchaindb": {
"mnemonic": "<C>",
"mnemonic": "<COMPANY>",
"app_id": "a6f5b578",
"app_key": "0cdea0b5a369dff5ee7849f42163221a",
"auditChainPublicKey": "6xuKg1qg3ykR45DiJzWTb4eaacmjSpQrWvaUB7aYvZQU",
......
COMPANY=$1
MANUFACTURER=$2
SUPPLIER=$3
USERNAME=$4
HYPERLEDGER_USER_ID=$5
CONFIG_FILE=../configs/config-$COMPANY.json
CONFIG_CHANNEL_FILE=../configs/config-channel-$COMPANY
CHANNELNAME=$MANUFACTURER-$SUPPLIER
cp ../configs/config-channel-template.json $CONFIG_CHANNEL_FILE
if [ $COMPANY = $MANUFACTURER ]
then
BUSINESS_PARTNER=$SUPPLIER
elif [ $COMPANY = $SUPPLIER ]
then
BUSINESS_PARTNER=$MANUFACTURER
fi
sed -i "s/<P>/$BUSINESS_PARTNER/g" $CONFIG_CHANNEL_FILE
sed -i "s/<USERNAME>/$USERNAME/g" $CONFIG_CHANNEL_FILE
sed -i "s/<CHANNELNAME>/$CHANNELNAME/g" $CONFIG_CHANNEL_FILE
sed -i "s/<C>/$COMPANY/g" $CONFIG_CHANNEL_FILE
sed -i "s/<HYPERLEDGER_USER_ID>/$HYPERLEDGER_USER_ID/g" $CONFIG_CHANNEL_FILE
CHANNEL=$(cat $CONFIG_CHANNEL_FILE)
NEW_CONFIG=$(jq -M ".rest_api.hyperledger.channels[.rest_api.hyperledger.channels| length] |= . + $CHANNEL" $CONFIG_FILE)
echo "$NEW_CONFIG" > $CONFIG_FILE
rm $CONFIG_CHANNEL_FILE
COMPANY=$1
MANUFACTURER=$2
SUPPLIER=$3
CONFIG_JSON=../configs/config-$COMPANY.json
CONFIG_CHANNEL_JSON=../configs/config-channel-$COMPANY
CHANNELNAME=${MANUFACTURER}${SUPPLIER}
cp ../configs/config-channel-template.json $CONFIG_CHANNEL_JSON
if [ $COMPANY = $MANUFACTURER ]
then
BUSINESS_PARTNER=$SUPPLIER
HYPERLEDGER_USER_ID=1001
elif [ $COMPANY = $SUPPLIER ]
then
BUSINESS_PARTNER=$MANUFACTURER
HYPERLEDGER_USER_ID=1002
fi
sed -i "s/<P>/$BUSINESS_PARTNER/g" $CONFIG_CHANNEL_JSON
#sed -i "s/<USERNAME>/$USERNAME/g" $CONFIG_CHANNEL_JSON
sed -i "s/<CHANNELNAME>/$CHANNELNAME/g" $CONFIG_CHANNEL_JSON
sed -i "s/<C>/$COMPANY/g" $CONFIG_CHANNEL_JSON
sed -i "s/<HYPERLEDGER_USER_ID>/$HYPERLEDGER_USER_ID/g" $CONFIG_CHANNEL_JSON
CHANNEL_ENTRY=$(cat $CONFIG_CHANNEL_JSON)
NEW_CONFIG_JSON=$(jq -M ".rest_api.hyperledger.channels[.rest_api.hyperledger.channels| length] |= . + $CHANNEL_ENTRY" $CONFIG_JSON)
echo "$NEW_CONFIG_JSON" > $CONFIG_JSON
rm $CONFIG_CHANNEL_JSON
......@@ -12,8 +12,6 @@ CONFIGURATIONS_SERVE_ENTRY=$(echo "{
\"browserTarget\": \"web-app:build:$COMPANY\"
}")
#CONFIGURATIONS_SERVE_ENTRY=$(echo "$CONFIGURATIONS_SERVE_ENTRY")
NEW_ANGULAR_FILE=$(jq -M --arg c $COMPANY --argjson e "$CONFIGURATIONS_BUILD_ENTRY" '.projects."web-app".architect.build.configurations[$c] = $e' $WEB_APP_DIR/angular.json)
NEW_ANGULAR_FILE=$(echo "$NEW_ANGULAR_FILE" | jq -M --arg c $COMPANY --argjson e "$CONFIGURATIONS_SERVE_ENTRY" '.projects."web-app".architect.serve.configurations[$c] = $e')
......
COMPANY=$1
WEB_APP_PORT=$2
WEB_APP_DIR=~/fabric-dev-servers/auditchain/web-app/
SCRIPTS_ENTRY="ng serve --host 0.0.0.0 --port $WEB_APP_PORT"
NEW_PACKAGE_JSON=$(jq -M --arg c "start-$COMPANY" --arg e "$SCRIPTS_ENTRY" '.scripts[$c] = $e' $WEB_APP_DIR/package.json)
echo "$NEW_PACKAGE_JSON" > $WEB_APP_DIR/package.json
COMPANY=$1
REST_API_PORT=$2
HYPERLEDGER_ROLE=$3
BCDB_VERSION=$4
CONFIG_FILE=../configs/config-$COMPANY.json
cp ../configs/config-template.json $CONFIG_FILE
sed -i "s/<COMPANY>/$COMPANY/g" $CONFIG_FILE
sed -i "s/<REST_API_PORT>/$REST_API_PORT/g" $CONFIG_FILE
sed -i "s/<HYPERLEDGER_ROLE>/$HYPERLEDGER_ROLE/g" $CONFIG_FILE
sed -i "s/<BCDB_VERSION>/$BCDB_VERSION/g" $CONFIG_FILE
COMPANY=$1
REST_API_PORT=$2
HYPERLEDGER_ROLE=$3
BCDB_VERSION=$4
AUDITCHAIN_PATH=~\\\/fabric-dev-servers\\\/auditchain
CONFIG_JSON=../configs/config-$COMPANY.json
cp ../configs/config-template.json $CONFIG_JSON
sed -i "s/<COMPANY>/$COMPANY/g" $CONFIG_JSON
sed -i "s/<REST_API_PORT>/$REST_API_PORT/g" $CONFIG_JSON
sed -i "s/<AUDITCHAIN_PATH>/$AUDITCHAIN_PATH/g" $CONFIG_JSON
sed -i "s/<HYPERLEDGER_ROLE>/$HYPERLEDGER_ROLE/g" $CONFIG_JSON
sed -i "s/<BCDB_VERSION>/$BCDB_VERSION/g" $CONFIG_JSON
COMPANY=$1
AUDITCHAIN_PATH=~\\\/fabric-dev-servers\\\/auditchain
ENVIRONMENTS_DIR=~/fabric-dev-servers/auditchain/web-app/src/environments
ENVIRONMENT_TS=$ENVIRONMENTS_DIR/environment.$COMPANY.ts
cp $ENVIRONMENTS_DIR/environment-template.ts $ENVIRONMENT_TS
sed -i "s/<AUDITCHAIN_PATH>/$AUDITCHAIN_PATH/g" $ENVIRONMENT_TS
sed -i "s/<COMPANY>/$COMPANY/g" $ENVIRONMENT_TS
COMPANY=$1
CONFIG_FILE=~\\\/fabric-dev-servers\\\/auditchain\\\/configs\\\/config-$COMPANY.json
ENVIRONMENTS_DIR=~/fabric-dev-servers/auditchain/web-app/src/environments
ENVIRONMENT_FILE=$ENVIRONMENTS_DIR/environment.$COMPANY.ts
cp $ENVIRONMENTS_DIR/environment-template.ts $ENVIRONMENT_FILE
sed -i "s/<CONFIG_FILE>/$CONFIG_FILE/g" $ENVIRONMENT_FILE
CURRENT_REST_API_PORT=0
CURRENT_REST_API_PORT=3000
CURRENT_WEBAPP_PORT=4200
CURRENT_CA_PORT=8054
GOSSIP_PORT=8051
GOSSIP_TWO_PORT=8053
BCDB_VERSION=3
CONFIGS_DIR=~/fabric-dev-servers/auditchain/configs
RUNNABLES_DIR=~/fabric-dev-servers/auditchain/runnables
mkdir -p $RUNNABLES_DIR
## ------------------------------ Manufacturer M1 ------------------------------ ##
COMPANY=M1
ROLE=Manufacturer
MANUFACTURER=M1
SUPPLIER=S1
./create_config_json_file.sh $COMPANY $CURRENT_REST_API_PORT $ROLE $BCDB_VERSION
./add_channel_to_config_json_file.sh $COMPANY $MANUFACTURER $SUPPLIER
./create_environment_ts_file.sh $COMPANY
./add_configuration_to_angular_json_file.sh $COMPANY
./add_script_to_package_json_file.sh $COMPANY $CURRENT_WEBAPP_PORT
node populate_bcdb.js $CONFIGS_DIR/config-$COMPANY
echo "node ../rest-api/index.js $CONFIGS_DIR/config-$COMPANY" > $RUNNABLES_DIR/start_rest_api_$COMPANY.sh
chmod +x $RUNNABLES_DIR/start_rest_api_$COMPANY.sh
echo "npm run start-$COMPANY --prefix ../web-app" > $RUNNABLES_DIR/start_webapp_$COMPANY.sh
chmod +x $RUNNABLES_DIR/start_webapp_$COMPANY.sh
./create_config_file.sh M1 $CURRENT_REST_API_PORT Manufacturer $BCDB_VERSION
./add_channel_to_config_file.sh M1 M1 S1
node populate.js $CONFIGS_DIR/config-M1
CURRENT_REST_API_PORT=`expr $CURRENT_REST_API_PORT + 1`
echo "node rest-api/index.js $COFNIGS_DIR/config-M1" > start_rest_api_M1.sh
chmod +x start_rest_api_M1.sh
CURRENT_WEBAPP_PORT=`expr $CURRENT_WEBAPP_PORT + 1`
## ------------------------------ Manufacturer M2 ------------------------------ ##
COMPANY=M2
ROLE=Manufacturer
MANUFACTURER=M2
SUPPLIER=S1
./create_config_json_file.sh $COMPANY $CURRENT_REST_API_PORT $ROLE $BCDB_VERSION
./add_channel_to_config_json_file.sh $COMPANY $MANUFACTURER $SUPPLIER
./create_environment_ts_file.sh $COMPANY
./add_configuration_to_angular_json_file.sh $COMPANY
./add_script_to_package_json_file.sh $COMPANY $CURRENT_WEBAPP_PORT
node populate_bcdb.js $CONFIGS_DIR/config-$COMPANY
echo "node ../rest-api/index.js $CONFIGS_DIR/config-$COMPANY" > $RUNNABLES_DIR/start_rest_api_$COMPANY.sh
chmod +x $RUNNABLES_DIR/start_rest_api_$COMPANY.sh
echo "npm run start-$COMPANY --prefix ../web-app" > $RUNNABLES_DIR/start_webapp_$COMPANY.sh
chmod +x $RUNNABLES_DIR/start_webapp_$COMPANY.sh
./create_config_file.sh M2 $CURRENT_REST_API_PORT Manufacturer $BCDB_VERSION
./add_channel_to_config_file.sh M2 M2 S1
node populate.js $CONFIGS_DIR/config-M2
CURRENT_REST_API_PORT=`expr $CURRENT_REST_API_PORT + 1`
echo "node rest-api/index.js $COFNIGS_DIR/config-M2" > start_rest_api_M2.sh
chmod +x start_rest_api_M2.sh
CURRENT_WEBAPP_PORT=`expr $CURRENT_WEBAPP_PORT + 1`
## ------------------------------ Supplier S1 ------------------------------ ##
COMPANY=S1
ROLE=Supplier
MANUFACTURER=M1
SUPPLIER=S1
./create_config_json_file.sh $COMPANY $CURRENT_REST_API_PORT $ROLE $BCDB_VERSION
./add_channel_to_config_json_file.sh $COMPANY $MANUFACTURER $SUPPLIER
./create_environment_ts_file.sh $COMPANY
./add_configuration_to_angular_json_file.sh $COMPANY
./add_script_to_package_json_file.sh $COMPANY $CURRENT_WEBAPP_PORT
node populate_bcdb.js $CONFIGS_DIR/config-$COMPANY
echo "node ../rest-api/index.js $CONFIGS_DIR/config-$COMPANY" > $RUNNABLES_DIR/start_rest_api_$COMPANY.sh
chmod +x $RUNNABLES_DIR/start_rest_api_$COMPANY.sh
echo "npm run start-$COMPANY --prefix ../web-app" > $RUNNABLES_DIR/start_webapp_$COMPANY.sh
chmod +x $RUNNABLES_DIR/start_webapp_$COMPANY.sh
## additional channels Supplier S1
MANUFACTURER=M2
./add_channel_to_config_json_file.sh $COMPANY $MANUFACTURER $SUPPLIER
./create_config_file.sh S1 $CURRENT_REST_API_PORT Manufacturer $BCDB_VERSION
./add_channel_to_config_file.sh S1 M1 S2
./add_channel_to_config_file.sh S1 M2 S2
node populate.js $CONFIGS_DIR/config-S1
CURRENT_REST_API_PORT=`expr $CURRENT_REST_API_PORT + 1`
echo "node rest-api/index.js $COFNIGS_DIR/config-S1" > start_rest_api_S1.sh
chmod +x start_rest_api_S1.sh
CURRENT_WEBAPP_PORT=`expr $CURRENT_WEBAPP_PORT + 1`
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"web-app": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "auditchain",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/web-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "web-app:build"
},
"configurations": {
"production": {
"browserTarget": "web-app:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "web-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.scss"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"web-app-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "web-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "web-app:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "web-app"
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment