Skip to content

Commit

Permalink
[FAB-6177] Improve Fabric-CA vendoring (scripts)
Browse files Browse the repository at this point in the history
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
troyronda committed Sep 18, 2017
1 parent dab5a98 commit e82eb25
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# populate: populates generated files (not included in git) - currently only vendor
# populate-vendor: populate the vendor directory based on the lock
# populate-clean: cleans up populated files (might become part of clean eventually)
# thirdparty-pin: pulls (and patches) pinned dependencies into the project under internal
#
#
# Instructions to generate .tx files used for creating channels:
Expand All @@ -32,6 +33,8 @@ export DOCKER_NS=hyperledger
export DOCKER_TAG=$(ARCH)-0.3.1
export GO_DEP_COMMIT=v0.3.0 # the version of dep that will be installed by depend-install (or in the CI)

export FABRIC_CA_COMMIT=v1.0.1

# Detect CI
ifdef JENKINS_URL
export FABRIC_SDKGO_DEPEND_INSTALL=true
Expand Down Expand Up @@ -90,6 +93,9 @@ mock-gen:
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api/apiconfig Config | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/apiconfig/mocks/mockconfig.gen.go
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api/apifabca FabricCAClient | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/apifabca/mocks/mockfabriccaclient.gen.go

thirdparty-pin:
UPSTREAM_COMMIT=$(FABRIC_CA_COMMIT) scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh

populate: populate-vendor

populate-vendor:
Expand Down
111 changes: 111 additions & 0 deletions scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh
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
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

1 change: 1 addition & 0 deletions test/scripts/unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ REPO="github.com/hyperledger/fabric-sdk-go"
PKGS=`go list $REPO... 2> /dev/null | \
grep -v ^$REPO/api/ | \
grep -v ^$REPO/pkg/fabric-ca-client/mocks | grep -v ^$REPO/pkg/fabric-client/mocks | \
grep -v ^$REPO/internal/github.com/ | \
grep -v ^$REPO/vendor/ | grep -v ^$REPO/test/`
echo "Running unit tests..."

Expand Down

0 comments on commit e82eb25

Please sign in to comment.