Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 1f49a61

Browse files
author
Simon Stone
authored
Undo all of the CLI changes for network admins (#2825)
Signed-off-by: Simon Stone <[email protected]>
1 parent 974bf75 commit 1f49a61

File tree

18 files changed

+102
-374
lines changed

18 files changed

+102
-374
lines changed

packages/composer-admin/lib/adminconnection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ class AdminConnection {
549549
* });
550550
* @param {BusinessNetworkDefinition} businessNetworkDefinition - The business network to start
551551
* @param {Object} [startOptions] connector specific start options
552-
* NetworkAdmins: [ { name, certificate } , { name, enrollmentSecret }]
552+
* networkAdmins: [ { userName, certificate } , { userName, enrollmentSecret }]
553553
*
554554
* @return {Promise} A promise that will be fufilled when the business network has been
555555
* deployed - with a MAP of cards key is name

packages/composer-cli/lib/cmds/archive/createCommand.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ module.exports.builder = function (yargs){
4545
// enforce singletons
4646
yargs.check(checkFn);
4747

48-
// grouping for the card options - moves them away from the standard --version etc.
49-
yargs.group(['archiveFile','sourceType','sourceName'],'Archive options');
50-
5148
return yargs;
5249
};
5350

packages/composer-cli/lib/cmds/card/createCommand.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ module.exports.builder = function (yargs) {
4646
// enforce the option after these options
4747
yargs.requiresArg(['file','businessNetworkName','connectionProfileFile','user','enrollSecret','certificate','privateKey','roles']);
4848

49-
// grouping for the card options - moves them away from the standard --version etc.
50-
yargs.group(['f','n','p','u','s','c','k','r'],'Card options');
51-
5249
yargs.implies('certificate','privateKey');
5350
yargs.implies('privateKey','certificate');
5451

packages/composer-cli/lib/cmds/card/deleteCommand.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports.builder = (yargs) => {
2323
name: { alias: 'n', required: true, describe: 'The name of the card to delete', type: 'string' }
2424
});
2525

26-
yargs.group(['n'],'Card options');
2726
yargs.requiresArg(['n']);
2827

2928
return yargs;

packages/composer-cli/lib/cmds/identity/issueCommand.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ module.exports.builder =function (yargs) {
2828
'file': {alias: 'f', required: false, describe: 'The card file name for the new identity', type: 'string' }
2929
});
3030

31-
yargs.group(['c','f'],'Business Network Cards');
32-
yargs.group(['u','a','x'],'Identity Options');
33-
3431
return yargs;
3532
};
3633

packages/composer-cli/lib/cmds/network/deployCommand.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports.builder = function (yargs) {
2626
optionsFile: { alias: 'O', required: false, describe: 'A file containing options that are specific to connection', type: 'string' },
2727
networkAdmin: { alias: 'A', required: true, description: 'The identity name of the business network administrator', type: 'string' },
2828
networkAdminCertificateFile: { alias: 'C', required: false, description: 'The certificate of the business network administrator', type: 'string' },
29-
networkAdminSecret: { alias: 'S', required: false, description: 'The enrollment secret for the business network administrator', type: 'string' },
29+
networkAdminEnrollSecret: { alias: 'S', required: false, description: 'The enrollment secret for the business network administrator', type: 'string' },
3030
card: { alias: 'c', required: true, description: 'The cardname to use to deploy the network', type:'string'},
3131
file: { alias: 'f', required: false, description: 'File name of the card to be created', type: 'string'}
3232
});
@@ -37,9 +37,6 @@ module.exports.builder = function (yargs) {
3737
// Mark the options that conflict
3838
yargs.conflicts('C','S');
3939

40-
// group the options
41-
yargs.group(['loglevel','file','archiveFile','networkAdmin','networkAdminCertificateFile','networkAdminEnrollSecret','card'],'Deploy Options');
42-
4340
return yargs;
4441
};
4542

packages/composer-cli/lib/cmds/network/lib/start.js

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Start {
7777
// grab the network admins
7878
// what we want is an array of the following
7979
// {userName, certificate, secret, file}
80-
startOptions.networkAdmins = networkAdmins = Start.createNetworkAdmins(argv);
80+
startOptions.networkAdmins = networkAdmins = cmdUtil.parseNetworkAdmins(argv);
8181
cmdUtil.log(chalk.bold.blue('Processing these Network Admins: '));
8282
startOptions.networkAdmins.forEach((e)=>{
8383
cmdUtil.log(chalk.blue('\tuserName: ')+e.userName);
@@ -150,67 +150,5 @@ class Start {
150150
}
151151
return archiveFileContents;
152152
}
153-
154-
/** Parse the argv structure to get an array of Network Admins
155-
* @param {array} argv standard YARGS structure
156-
* @return {array} simple objects with details of the network admins to create
157-
*/
158-
static createNetworkAdmins(argv){
159-
let networkAdmins;
160-
if (typeof argv.networkAdmin.id === 'object'){
161-
162-
networkAdmins = Object.keys(argv.networkAdmin.id).map((index)=>{
163-
let admin={};
164-
admin.userName = argv.networkAdmin.id[index];
165-
if (argv.networkAdmin.cert && argv.networkAdmin.cert[index]){
166-
admin.certificate = argv.networkAdmin.cert[index];
167-
}
168-
169-
if (!admin.certificate && argv.networkAdmin.secret) {
170-
admin.secret = argv.networkAdmin.secret[index];
171-
} else {
172-
throw new Error('Need to have certificate or secret');
173-
}
174-
175-
if (argv.networkAdmin.file && argv.networkAdmin.file[index]){
176-
admin.file = argv.networkAdmin.file[index];
177-
}
178-
return admin;
179-
});
180-
181-
} else if (typeof argv.networkAdmin === 'object') {
182-
let admin={};
183-
admin.userName = argv.networkAdmin.id;
184-
if (argv.networkAdmin.certificate){
185-
admin.certificate = argv.networkAdmin.certificate;
186-
} else if (argv.networkAdmin.secret){
187-
admin.enrollmentSecret = argv.networkAdmin.secret;
188-
} else {
189-
throw new Error('Need to have certificate or secret');
190-
}
191-
192-
if (argv.networkAdmin.file){
193-
admin.file = argv.networkAdmin.file;
194-
}
195-
networkAdmins = [ admin ];
196-
} else {
197-
// old school
198-
let admin={};
199-
admin.userName = argv.networkAdmin;
200-
if (argv.networkAdminCertificateFile){
201-
admin.certificate = argv.networkAdminCertificateFile;
202-
} else if (argv.networkAdminSecret){
203-
admin.enrollmentSecret = argv.networkAdminSecret;
204-
} else {
205-
throw new Error('Need to have certificate or secret');
206-
}
207-
208-
if (argv.file){
209-
admin.file = argv.file;
210-
}
211-
networkAdmins = [ admin ];
212-
}
213-
return networkAdmins;
214-
}
215153
}
216154
module.exports = Start;

packages/composer-cli/lib/cmds/network/startCommand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports.builder = function (yargs) {
2626
optionsFile: { alias: 'O', required: false, describe: 'A file containing options that are specific to connection', type: 'string' },
2727
networkAdmin: { alias: 'A', required: true, description: 'The identity name of the business network administrator', type: 'string' },
2828
networkAdminCertificateFile: { alias: 'C', required: false, description: 'The certificate of the business network administrator', type: 'string' },
29-
networkAdminSecret: { alias: 'S', required: false, description: 'The enrollment secret for the business network administrator', type: 'string', default: undefined },
29+
networkAdminEnrollSecret: { alias: 'S', required: false, description: 'The enrollment secret for the business network administrator', type: 'string', default: undefined },
3030
card: { alias: 'c', required: true, description: 'The cardname to use to start the network', type:'string'},
3131
file: { alias: 'f', required: false, description: 'File name of the card to be created', type: 'string'}
3232
});

packages/composer-cli/lib/cmds/participant/addCommand.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ module.exports.builder = (yargs) =>{
4141

4242
yargs.check(checkFn);
4343

44-
yargs.group(['card','data'],'Participant options');
45-
4644
return yargs;
4745
};
4846

packages/composer-cli/lib/cmds/utils/cmdutils.js

Lines changed: 21 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ const AdminConnection = require('composer-admin').AdminConnection;
1818
const BusinessNetworkCardStore = require('composer-common').BusinessNetworkCardStore;
1919
const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
2020
const fs = require('fs');
21-
const Logger = require('composer-common').Logger;
2221
const prompt = require('prompt');
2322

24-
const LOG = Logger.getLog('CmdUtil');
25-
2623
/**
2724
* Internal Utility Class
2825
* <p><a href="diagrams/util.svg"><img src="diagrams/util.svg" style="width:100%;"/></a></p>
@@ -114,7 +111,7 @@ class CmdUtil {
114111
const certificateFile = networkAdminCertificateFiles[index];
115112
const certificate = fs.readFileSync(certificateFile, { encoding: 'utf8' });
116113
return {
117-
name: networkAdmin,
114+
userName: networkAdmin,
118115
certificate
119116
};
120117

@@ -134,10 +131,10 @@ class CmdUtil {
134131
return networkAdmins.map((networkAdmin, index) => {
135132

136133
// Grab the secret for the network admin.
137-
const secret = networkAdminEnrollSecrets[index];
134+
const enrollmentSecret = networkAdminEnrollSecrets[index];
138135
return {
139-
name: networkAdmin,
140-
secret
136+
userName: networkAdmin,
137+
enrollmentSecret
141138
};
142139

143140
});
@@ -155,6 +152,7 @@ class CmdUtil {
155152
const networkAdmins = CmdUtil.arrayify(argv.networkAdmin);
156153
const networkAdminCertificateFiles = CmdUtil.arrayify(argv.networkAdminCertificateFile);
157154
const networkAdminEnrollSecrets = CmdUtil.arrayify(argv.networkAdminEnrollSecret);
155+
const files = CmdUtil.arrayify(argv.file);
158156

159157
// It's valid not to specify any network administrators.
160158
if (networkAdmins.length === 0) {
@@ -167,85 +165,32 @@ class CmdUtil {
167165
}
168166

169167
// Check that enough certificate files have been specified.
168+
let result;
170169
if (networkAdmins.length === networkAdminCertificateFiles.length) {
171-
return CmdUtil.parseNetworkAdminsWithCertificateFiles(networkAdmins, networkAdminCertificateFiles);
170+
result = CmdUtil.parseNetworkAdminsWithCertificateFiles(networkAdmins, networkAdminCertificateFiles);
172171
}
173172

174173
// Check that enough enrollment secrets have been specified.
175-
if (networkAdmins.length === networkAdminEnrollSecrets.length) {
176-
return CmdUtil.parseNetworkAdminsWithEnrollSecrets(networkAdmins, networkAdminEnrollSecrets);
174+
else if (networkAdmins.length === networkAdminEnrollSecrets.length) {
175+
result = CmdUtil.parseNetworkAdminsWithEnrollSecrets(networkAdmins, networkAdminEnrollSecrets);
177176
}
178177

179178
// Not enough certificate files or enrollment secrets!
180-
throw new Error('You must specify certificate files or enrollment secrets for all network administrators');
181-
182-
}
179+
else {
180+
console.log(JSON.stringify(argv, null, 4));
181+
throw new Error('You must specify certificate files or enrollment secrets for all network administrators');
182+
}
183183

184-
/**
185-
* Build the bootstrap transactions for any business network administrators specified on the command line.
186-
* @param {BusinessNetworkDefinition} businessNetworkDefinitinon The business network definition.
187-
* @param {Object} argv The command line arguments as parsed by yargs.
188-
* @return {Object[]} The bootstrap transactions.
189-
*/
190-
static buildBootstrapTransactions(businessNetworkDefinitinon, argv) {
191-
const method = 'buildBootstrapTransactions';
192-
LOG.entry(method, businessNetworkDefinitinon, argv);
193-
194-
// Grab the useful things from the business network definition.
195-
const factory = businessNetworkDefinitinon.getFactory();
196-
const serializer = businessNetworkDefinitinon.getSerializer();
197-
198-
// Parse the network administrators.
199-
const networkAdmins = CmdUtil.parseNetworkAdmins(argv);
200-
201-
// Convert the network administrators into add participant transactions.
202-
const addParticipantTransactions = networkAdmins.map((networkAdmin) => {
203-
const participant = factory.newResource('org.hyperledger.composer.system', 'NetworkAdmin', networkAdmin.name);
204-
const targetRegistry = factory.newRelationship('org.hyperledger.composer.system', 'ParticipantRegistry', participant.getFullyQualifiedType());
205-
const addParticipantTransaction = factory.newTransaction('org.hyperledger.composer.system', 'AddParticipant');
206-
Object.assign(addParticipantTransaction, {
207-
resources: [ participant ],
208-
targetRegistry
184+
// If any files specified, check we have enough, and merge them into the result.
185+
if (files.length && files.length !== result.length) {
186+
throw new Error('If you specify a network administrators card file name, you must specify one for all network administrators');
187+
} else if (files.length) {
188+
files.forEach((file, index) => {
189+
result[index].file = file;
209190
});
210-
LOG.debug(method, 'Created bootstrap transaction to add participant', addParticipantTransaction);
211-
return addParticipantTransaction;
212-
});
213-
214-
// Convert the network administrators into issue or bind identity transactions.
215-
const identityTransactions = networkAdmins.map((networkAdmin) => {
216-
217-
// Handle a certificate which requires a bind identity transaction.
218-
let identityTransaction;
219-
if (networkAdmin.certificate) {
220-
identityTransaction = factory.newTransaction('org.hyperledger.composer.system', 'BindIdentity');
221-
Object.assign(identityTransaction, {
222-
participant: factory.newRelationship('org.hyperledger.composer.system', 'NetworkAdmin', networkAdmin.name),
223-
certificate: networkAdmin.certificate
224-
});
225-
LOG.debug(method, 'Created bootstrap transaction to bind identity', identityTransaction);
226-
}
227-
228-
// Handle an enrollment secret which requires an issue identity transactiom.
229-
if (networkAdmin.secret) {
230-
identityTransaction = factory.newTransaction('org.hyperledger.composer.system', 'IssueIdentity');
231-
Object.assign(identityTransaction, {
232-
participant: factory.newRelationship('org.hyperledger.composer.system', 'NetworkAdmin', networkAdmin.name),
233-
identityName: networkAdmin.name
234-
});
235-
LOG.debug(method, 'Created bootstrap transaction to issue identity', identityTransaction);
236-
}
237-
return identityTransaction;
238-
239-
});
240-
241-
// Serialize all of the transactions into a single array.
242-
const transactions = addParticipantTransactions.concat(identityTransactions);
243-
const json = transactions.map((transaction) => {
244-
return serializer.toJSON(transaction);
245-
});
191+
}
192+
return result;
246193

247-
LOG.exit(method, json);
248-
return json;
249194
}
250195

251196
/**

0 commit comments

Comments
 (0)