Skip to content

Commit 6b2799e

Browse files
committed
[FAB-6568] Fabric-Samples - update fabcar
Update the fabcar sample with an easier flow Remove hardcoded fields in the invoke program Change-Id: I9a06cdd317c2afec80720ac7d728d38fc62c6f63 Signed-off-by: Bret Harrison <beharrison@nc.rr.com> Signed-off-by: Nick Gaski <ngaski@us.ibm.com>
1 parent cd1b691 commit 6b2799e

10 files changed

+373
-215
lines changed

basic-network/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ services:
1414
environment:
1515
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
1616
- FABRIC_CA_SERVER_CA_NAME=ca.example.com
17+
- FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem
18+
- FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/4239aa0dcd76daeeb8ba0cda701851d14504d31aad1b2ddddbac6a57365e497c_sk
1719
ports:
1820
- "7054:7054"
19-
command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk -b admin:adminpw -d'
21+
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
2022
volumes:
2123
- ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
2224
container_name: ca.example.com

fabcar/creds/PeerAdmin

Lines changed: 0 additions & 1 deletion
This file was deleted.

fabcar/creds/cd96d5260ad4757551ed4a5a991e62130f8008a0bf996e4e4b84cd097a747fec-priv

Lines changed: 0 additions & 5 deletions
This file was deleted.

fabcar/creds/cd96d5260ad4757551ed4a5a991e62130f8008a0bf996e4e4b84cd097a747fec-pub

Lines changed: 0 additions & 14 deletions
This file was deleted.

fabcar/enrollAdmin.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
/*
3+
* Copyright IBM Corp All Rights Reserved
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
/*
8+
* Enroll the admin user
9+
*/
10+
11+
var Fabric_Client = require('fabric-client');
12+
var Fabric_CA_Client = require('fabric-ca-client');
13+
14+
var path = require('path');
15+
var util = require('util');
16+
var os = require('os');
17+
18+
//
19+
var fabric_client = new Fabric_Client();
20+
var fabric_ca_client = null;
21+
var admin_user = null;
22+
var member_user = null;
23+
var store_path = path.join(__dirname, 'hfc-key-store');
24+
console.log(' Store path:'+store_path);
25+
26+
// create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
27+
Fabric_Client.newDefaultKeyValueStore({ path: store_path
28+
}).then((state_store) => {
29+
// assign the store to the fabric client
30+
fabric_client.setStateStore(state_store);
31+
var crypto_suite = Fabric_Client.newCryptoSuite();
32+
// use the same location for the state store (where the users' certificate are kept)
33+
// and the crypto store (where the users' keys are kept)
34+
var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
35+
crypto_suite.setCryptoKeyStore(crypto_store);
36+
fabric_client.setCryptoSuite(crypto_suite);
37+
var tlsOptions = {
38+
trustedRoots: [],
39+
verify: false
40+
};
41+
// be sure to change the http to https when the CA is running TLS enabled
42+
fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', tlsOptions , 'ca.example.com', crypto_suite);
43+
44+
// first check to see if the admin is already enrolled
45+
return fabric_client.getUserContext('admin', true);
46+
}).then((user_from_store) => {
47+
if (user_from_store && user_from_store.isEnrolled()) {
48+
console.log('Successfully loaded admin from persistence');
49+
admin_user = user_from_store;
50+
return null;
51+
} else {
52+
// need to enroll it with CA server
53+
return fabric_ca_client.enroll({
54+
enrollmentID: 'admin',
55+
enrollmentSecret: 'adminpw'
56+
}).then((enrollment) => {
57+
console.log('Successfully enrolled admin user "admin"');
58+
return fabric_client.createUser(
59+
{username: 'admin',
60+
mspid: 'Org1MSP',
61+
cryptoContent: { privateKeyPEM: enrollment.key.toBytes(), signedCertPEM: enrollment.certificate }
62+
});
63+
}).then((user) => {
64+
admin_user = user;
65+
return fabric_client.setUserContext(admin_user);
66+
}).catch((err) => {
67+
console.error('Failed to enroll and persist admin. Error: ' + err.stack ? err.stack : err);
68+
throw new Error('Failed to enroll admin');
69+
});
70+
}
71+
}).then(() => {
72+
console.log('Assigned the admin user to the fabric client ::' + admin_user.toString());
73+
}).catch((err) => {
74+
console.error('Failed to enroll admin: ' + err);
75+
});

0 commit comments

Comments
 (0)