diff --git a/Makefile b/Makefile index 0868dd1f8a..14593e321e 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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 @@ -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: diff --git a/scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh b/scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh new file mode 100755 index 0000000000..dee6df3734 --- /dev/null +++ b/scripts/third_party_pins/fabric-ca/apply_fabric_ca.sh @@ -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 \ No newline at end of file diff --git a/scripts/third_party_pins/fabric-ca/patches/0001-Decouple-server-structs-needed-for-client-compilatio.patch b/scripts/third_party_pins/fabric-ca/patches/0001-Decouple-server-structs-needed-for-client-compilatio.patch new file mode 100644 index 0000000000..8581726f5e --- /dev/null +++ b/scripts/third_party_pins/fabric-ca/patches/0001-Decouple-server-structs-needed-for-client-compilatio.patch @@ -0,0 +1,53 @@ +From 51527a5dd56b66d5452e68bc9453b6850a5dbf85 Mon Sep 17 00:00:00 2001 +From: Troy Ronda +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 +--- + 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 + diff --git a/test/scripts/unit.sh b/test/scripts/unit.sh index aa9b6adaf9..75248666cd 100755 --- a/test/scripts/unit.sh +++ b/test/scripts/unit.sh @@ -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..."