@@ -137,6 +137,9 @@ def __init__(self, name):
137
137
# Which networks this organization belongs to
138
138
self .networks = []
139
139
140
+ def getSelfSignedCert (self ):
141
+ return self .signedCert
142
+
140
143
def createCertificate (self , certReq ):
141
144
numYrs = 1
142
145
return createCertificate (certReq , (self .signedCert , self .pKey ), 1000 , (0 , 60 * 60 * 24 * 365 * numYrs ))
@@ -413,6 +416,66 @@ def getEnv(self, composition, context, env):
413
416
env ["ORDERER_GENERAL_GENESISIFILE" ]= self .getGenesisFilePath (composition , pathType = PathType .Container )
414
417
415
418
419
+ class PeerCompositionCallback (compose .CompositionCallback ):
420
+ 'Responsible for setting up Peer nodes upon composition'
421
+
422
+ def __init__ (self , context ):
423
+ self .context = context
424
+ self .volumeRootPathInContainer = "/var/hyperledger/bddtests"
425
+ compose .Composition .RegisterCallbackInContext (context , self )
426
+
427
+ def getVolumePath (self , composition , pathType = PathType .Local ):
428
+ assert pathType in PathType , "Expected pathType of {0}" .format (PathType )
429
+ basePath = "."
430
+ if pathType == PathType .Container :
431
+ basePath = self .volumeRootPathInContainer
432
+ return "{0}/volumes/peer/{1}" .format (basePath , composition .projectName )
433
+
434
+ def getPeerList (self , composition ):
435
+ return [serviceName for serviceName in composition .getServiceNames () if "peer" in serviceName ]
436
+
437
+ def getLocalMspConfigPath (self , composition , peerService , pathType = PathType .Local ):
438
+ return "{0}/{1}/localMspConfig" .format (self .getVolumePath (composition , pathType ), peerService )
439
+
440
+ def _createLocalMspConfigDirs (self , mspConfigPath ):
441
+ os .makedirs ("{0}/{1}" .format (mspConfigPath , "signcerts" ))
442
+ os .makedirs ("{0}/{1}" .format (mspConfigPath , "admincerts" ))
443
+ os .makedirs ("{0}/{1}" .format (mspConfigPath , "cacerts" ))
444
+ os .makedirs ("{0}/{1}" .format (mspConfigPath , "keystore" ))
445
+
446
+
447
+ def composing (self , composition , context ):
448
+ 'Will copy local MSP info over at this point for each peer node'
449
+
450
+ directory = getDirectory (context )
451
+
452
+ for peerService in self .getPeerList (composition ):
453
+ localMspConfigPath = self .getLocalMspConfigPath (composition , peerService )
454
+ self ._createLocalMspConfigDirs (localMspConfigPath )
455
+ # Loop through directory and place Peer Organization Certs into cacerts folder
456
+ for peerOrg in [org for orgName ,org in directory .organizations .items () if Network .Peer in org .networks ]:
457
+ with open ("{0}/cacerts/{1}.pem" .format (localMspConfigPath , peerOrg .name ), "w" ) as f :
458
+ f .write (crypto .dump_certificate (crypto .FILETYPE_PEM , peerOrg .getSelfSignedCert ()))
459
+
460
+ # Find the peer signer Tuple for this peer and add to signcerts folder
461
+ for pnt , cert in [(peerNodeTuple ,cert ) for peerNodeTuple ,cert in directory .ordererAdminTuples .items () if peerService in peerNodeTuple .user and "signer" in peerNodeTuple .user .lower ()]:
462
+ # Put the PEM file in the signcerts folder
463
+ with open ("{0}/signcerts/{1}.pem" .format (localMspConfigPath , pnt .user ), "w" ) as f :
464
+ f .write (crypto .dump_certificate (crypto .FILETYPE_PEM , cert ))
465
+ # Put the associated private key into the keystore folder
466
+ user = directory .getUser (pnt .user , shouldCreate = False )
467
+ with open ("{0}/keystore/{1}.pem" .format (localMspConfigPath , pnt .user ), "w" ) as f :
468
+ f .write (crypto .dump_privatekey (crypto .FILETYPE_PEM , user .pKey ))
469
+
470
+
471
+ def decomposing (self , composition , context ):
472
+ 'Will remove the orderer volume path folder for the context'
473
+ shutil .rmtree (self .getVolumePath (composition ))
474
+
475
+ def getEnv (self , composition , context , env ):
476
+ for peerService in self .getPeerList (composition ):
477
+ localMspConfigPath = self .getLocalMspConfigPath (composition , peerService , pathType = PathType .Container )
478
+ env ["{0}_CORE_PEER_MSPCFGPATH" .format (peerService .upper ())]= localMspConfigPath
416
479
417
480
def setOrdererBootstrapGenesisBlock (genesisBlock ):
418
481
'Responsible for setting the GensisBlock for the Orderer nodes upon composition'
0 commit comments