-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-6177] Improve Fabric-CA vendoring (scripts)
This patch adds selective vendoring capability for hyperledger/fabric-ca. The script pulls a specified version, applies patches needed for better vendoring, and rewrites imports to be in the SDK namespace. Change-Id: I79bc7569dfb14461cd5d7eb9100b972471f41ce6 Signed-off-by: Troy Ronda <troy@troyronda.com>
- Loading branch information
Showing
4 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# This script fetches code used in the SDK originating from other Hyperledger Fabric projects | ||
# These files are checked into internal paths. | ||
# Note: This script must be adjusted as upstream makes adjustments | ||
|
||
UPSTREAM_PROJECT="github.com/hyperledger/fabric-ca" | ||
INTERNAL_PATH="internal/${UPSTREAM_PROJECT}" | ||
UPSTREAM_BRANCH="release" | ||
PATCHES_PATH="scripts/third_party_pins/fabric-ca/patches" | ||
|
||
# TODO - in a future CS, fabric imports need to have imports rewritten. | ||
#IMPORT_FABRIC_SUBST='s/github.com\/hyperledger\/fabric/github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric/g' | ||
IMPORT_FABRICCA_SUBST='s/github.com\/hyperledger\/fabric-ca/github.com\/hyperledger\/fabric-sdk-go\/internal\/github.com\/hyperledger\/fabric-ca/g' | ||
|
||
declare -a PKGS=( | ||
"api" | ||
"lib" | ||
"lib/tls" | ||
"lib/tcert" | ||
"lib/spi" | ||
"util" | ||
) | ||
|
||
declare -a FILES=( | ||
"api/client.go" | ||
"api/net.go" | ||
|
||
"lib/client.go" | ||
"lib/identity.go" | ||
"lib/signer.go" | ||
"lib/clientconfig.go" | ||
"lib/util.go" | ||
"lib/serverstruct.go" | ||
|
||
"lib/tls/tls.go" | ||
|
||
"lib/tcert/api.go" | ||
"lib/tcert/util.go" | ||
"lib/tcert/tcert.go" | ||
"lib/tcert/keytree.go" | ||
|
||
"lib/spi/affiliation.go" | ||
"lib/spi/userregistry.go" | ||
|
||
"util/util.go" | ||
"util/args.go" | ||
"util/csp.go" | ||
"util/struct.go" | ||
"util/flag.go" | ||
) | ||
|
||
#### | ||
# Clone and patch packages into repo | ||
|
||
# Cleanup existing internal packages | ||
echo 'Removing current upstream project from working directory ...' | ||
rm -Rf $INTERNAL_PATH | ||
mkdir -p $INTERNAL_PATH | ||
|
||
# Create directory structure for packages | ||
for i in "${PKGS[@]}" | ||
do | ||
mkdir -p $INTERNAL_PATH/${i} | ||
done | ||
|
||
# Clone original project into temporary directory | ||
echo "Fetching upstream project ($UPSTREAM_PROJECT:$UPSTREAM_COMMIT) ..." | ||
CWD=`pwd` | ||
TMP=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` | ||
|
||
TMP_PROJECT_PATH=$TMP/src/$UPSTREAM_PROJECT | ||
mkdir -p $TMP_PROJECT_PATH | ||
cd ${TMP_PROJECT_PATH}/.. | ||
|
||
git clone https://${UPSTREAM_PROJECT}.git | ||
cd $TMP_PROJECT_PATH | ||
git checkout $UPSTREAM_BRANCH | ||
git reset --hard $UPSTREAM_COMMIT | ||
|
||
echo "Patching upstream project ..." | ||
git am ${CWD}/${PATCHES_PATH}/* | ||
|
||
cd $CWD | ||
|
||
# Apply global import patching | ||
echo "Patching import paths on upstream project ..." | ||
for i in "${FILES[@]}" | ||
do | ||
# TODO Patch fabric paths (in upcoming change set) | ||
#sed -i '' -e $IMPORT_FABRIC_SUBST $INTERNAL_PATH/${i} | ||
sed -i '' -e $IMPORT_FABRICCA_SUBST $TMP_PROJECT_PATH/${i} | ||
goimports -w $TMP_PROJECT_PATH/${i} | ||
done | ||
|
||
# Copy patched project into internal paths | ||
echo "Copying patched upstream project into working directory ..." | ||
for i in "${FILES[@]}" | ||
do | ||
TARGET_PATH=`dirname $INTERNAL_PATH/${i}` | ||
cp $TMP_PROJECT_PATH/${i} $TARGET_PATH | ||
done | ||
|
||
# Cleanup temporary files from patch application | ||
echo "Removing temporary files ..." | ||
rm -Rf $TMP |
53 changes: 53 additions & 0 deletions
53
...ty_pins/fabric-ca/patches/0001-Decouple-server-structs-needed-for-client-compilatio.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
From 51527a5dd56b66d5452e68bc9453b6850a5dbf85 Mon Sep 17 00:00:00 2001 | ||
From: Troy Ronda <t.....@securekey.com> | ||
Date: Fri, 15 Sep 2017 14:06:59 -0400 | ||
Subject: [PATCH] Decouple server structs needed for client compilation | ||
|
||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
|
||
Signed-off-by: Troy Ronda <t.....@securekey.com> | ||
--- | ||
lib/serverstruct.go | 30 ++++++++++++++++++++++++++++++ | ||
1 file changed, 30 insertions(+) | ||
create mode 100644 lib/serverstruct.go | ||
|
||
diff --git a/lib/serverstruct.go b/lib/serverstruct.go | ||
new file mode 100644 | ||
index 0000000..3bc2be5 | ||
--- /dev/null | ||
+++ b/lib/serverstruct.go | ||
@@ -0,0 +1,30 @@ | ||
+/* | ||
+Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
+ | ||
+SPDX-License-Identifier: Apache-2.0 | ||
+*/ | ||
+ | ||
+package lib | ||
+ | ||
+// CAConfig ... | ||
+type CAConfig struct { | ||
+} | ||
+ | ||
+// ServerConfig ... | ||
+type ServerConfig struct { | ||
+ CAcfg CAConfig `skip:"true"` | ||
+} | ||
+ | ||
+type serverInfoResponseNet struct { | ||
+ // CAName is a unique name associated with fabric-ca-server's CA | ||
+ CAName string | ||
+ // Base64 encoding of PEM-encoded certificate chain | ||
+ CAChain string | ||
+} | ||
+ | ||
+type enrollmentResponseNet struct { | ||
+ // Base64 encoded PEM-encoded ECert | ||
+ Cert string | ||
+ // The server information | ||
+ ServerInfo serverInfoResponseNet | ||
+} | ||
-- | ||
2.14.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters