Skip to content

Commit e1399cb

Browse files
committed
FAB-16207 remove calls to WriteBytesToPackage
Replace calls to utility with direct calls to the tar writer. Change-Id: Ia214be2a7a3930da496ebfe73a7790ea4977bef2 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 3b97a65 commit e1399cb

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

core/container/dockercontroller/dockercontroller.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/hyperledger/fabric/core/common/ccprovider"
2828
"github.com/hyperledger/fabric/core/container"
2929
"github.com/hyperledger/fabric/core/container/ccintf"
30-
cutil "github.com/hyperledger/fabric/core/container/util"
3130
pb "github.com/hyperledger/fabric/protos/peer"
3231
"github.com/pkg/errors"
3332
)
@@ -291,13 +290,18 @@ func (vm *DockerVM) Start(ccid ccintf.CCID, ccType string, peerConnection *ccint
291290
tw := tar.NewWriter(gw)
292291

293292
// Note, we goofily base64 encode 2 of the TLS artifacts but not the other for strange historical reasons
294-
cutil.WriteBytesToPackage(TLSClientKeyPath, []byte(base64.StdEncoding.EncodeToString(peerConnection.TLSConfig.ClientKey)), tw)
295-
cutil.WriteBytesToPackage(TLSClientCertPath, []byte(base64.StdEncoding.EncodeToString(peerConnection.TLSConfig.ClientCert)), tw)
296-
cutil.WriteBytesToPackage(TLSClientRootCertPath, peerConnection.TLSConfig.RootCert, tw)
293+
err = addFiles(tw, map[string][]byte{
294+
TLSClientKeyPath: []byte(base64.StdEncoding.EncodeToString(peerConnection.TLSConfig.ClientKey)),
295+
TLSClientCertPath: []byte(base64.StdEncoding.EncodeToString(peerConnection.TLSConfig.ClientCert)),
296+
TLSClientRootCertPath: peerConnection.TLSConfig.RootCert,
297+
})
298+
if err != nil {
299+
return fmt.Errorf("error writing files to upload to Docker instance into a temporary tar blob: %s", err)
300+
}
297301

298302
// Write the tar file out
299303
if err := tw.Close(); err != nil {
300-
return fmt.Errorf("Error writing files to upload to Docker instance into a temporary tar blob: %s", err)
304+
return fmt.Errorf("error writing files to upload to Docker instance into a temporary tar blob: %s", err)
301305
}
302306

303307
gw.Close()
@@ -323,6 +327,26 @@ func (vm *DockerVM) Start(ccid ccintf.CCID, ccType string, peerConnection *ccint
323327
return nil
324328
}
325329

330+
func addFiles(tw *tar.Writer, contents map[string][]byte) error {
331+
for name, payload := range contents {
332+
err := tw.WriteHeader(&tar.Header{
333+
Name: name,
334+
Size: int64(len(payload)),
335+
Mode: 0100644,
336+
})
337+
if err != nil {
338+
return err
339+
}
340+
341+
_, err = tw.Write(payload)
342+
if err != nil {
343+
return err
344+
}
345+
}
346+
347+
return nil
348+
}
349+
326350
// streamOutput mirrors output from the named container to a fabric logger.
327351
func streamOutput(logger *flogging.FabricLogger, client dockerClient, containerName string, containerLogger *flogging.FabricLogger) {
328352
// Launch a few go routines to manage output streams from the container.

0 commit comments

Comments
 (0)