Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
8da28cb
Added unit tests for add file component
liam-grace Mar 20, 2017
31513ad
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 21, 2017
5cc1d6a
Merge branch 'master' into master
Mar 21, 2017
838b047
Finished add-file component test and edit import to clear stubs
liam-grace Mar 21, 2017
e94dfb3
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 21, 2017
4d26bf5
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 21, 2017
a1d4c45
Merge branch 'master' into master
Jakeeyturner Mar 22, 2017
eb68ef7
Bumped up about.service code coverage
liam-grace Mar 22, 2017
4721dea
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 22, 2017
307abce
Fixed minor linting issues
liam-grace Mar 22, 2017
b6995d8
Removed fdescribe
liam-grace Mar 22, 2017
b38ce58
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 23, 2017
69dc287
Increase code coverage of add-file to 100%
liam-grace Mar 23, 2017
859f0fc
Export AssetRegistry and ParticipantRegistry
liam-grace Mar 23, 2017
f70ffa5
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 23, 2017
5aef7cb
Merge branch 'master' into master
Mar 23, 2017
324c43a
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 23, 2017
fa74980
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 24, 2017
24a344a
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 24, 2017
7647174
Registry unit tests
liam-grace Mar 24, 2017
9d35f2a
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 24, 2017
a396468
Merge branch 'master' into master
Mar 24, 2017
fc18a0f
Merge branch 'master' into master
Mar 27, 2017
e5b3286
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 27, 2017
0780bc0
First trasaction component test
liam-grace Mar 27, 2017
ea885e3
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 27, 2017
8146a1d
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 27, 2017
c9f4766
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 28, 2017
bf41d2e
Transaction component unit tests
liam-grace Mar 28, 2017
c3ab845
Remove fdiscribe
liam-grace Mar 28, 2017
bdaf4c7
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 28, 2017
008d386
Added resource unit tests
liam-grace Mar 28, 2017
351670c
Github components unit tests
liam-grace Mar 29, 2017
d5295fc
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 29, 2017
4c8c021
Added test file
liam-grace Mar 29, 2017
e26e29d
Merge branch 'master' into master
samjsmith Mar 29, 2017
590956f
Merge branch 'master' into master
Mar 30, 2017
e96c67c
Merge branch 'master' into master
Mar 30, 2017
91a5f3f
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 30, 2017
f33e39f
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 31, 2017
9f3f20b
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 31, 2017
75371d5
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 31, 2017
b3cb033
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 3, 2017
3f3e0af
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 3, 2017
3a0fe11
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 5, 2017
6c49e4f
Business network yeoman generator
liam-grace Apr 5, 2017
5f63117
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 5, 2017
690f68f
Clean up template and give transaction template the correct name
liam-grace Apr 5, 2017
ea76594
Added missing semi colon
liam-grace Apr 5, 2017
6808721
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 6, 2017
ff9fa14
Added docs about skeleton business network generator
liam-grace Apr 6, 2017
9e9ebc6
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 6, 2017
02bad51
Added newlines to docs to stop md parse issues
liam-grace Apr 6, 2017
1a6b083
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 6, 2017
9d0dac3
Stop parser accepting floats as string defaults and ranges, and vice …
liam-grace Apr 7, 2017
9b19e8a
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 7, 2017
53f2578
Added option to allow create of models only
liam-grace Apr 7, 2017
40343d9
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 10, 2017
32695db
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 10, 2017
6e13b52
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 11, 2017
da8db71
Fixed truncation of large data when pressing 'Show All'
liam-grace Apr 11, 2017
f679170
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 11, 2017
34ae6b1
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 18, 2017
abfb307
Fixed business network generator issue #668
liam-grace Apr 18, 2017
508678e
Slight imporovement to deploy error message
liam-grace Apr 18, 2017
8340fd1
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 19, 2017
4aa5ddf
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 19, 2017
fc092d8
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 20, 2017
bbbe398
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 21, 2017
0baf213
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 21, 2017
3a449d6
Added checks and tests to solve issue #240
liam-grace Apr 21, 2017
ff593f9
Merge branch 'master' into master
Apr 21, 2017
8556d3b
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 21, 2017
409a544
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Apr 21, 2017
a44d490
Improved code efficiency and robustness
liam-grace Apr 21, 2017
02e6643
Merge branch 'master' into master
Apr 21, 2017
08bdf6f
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 24, 2017
b057b27
Change to open error modal if import fails
liam-grace Apr 24, 2017
2af4f0a
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Apr 24, 2017
f67e266
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 24, 2017
d0cf1cd
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 25, 2017
31a646c
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 27, 2017
14bad3c
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 2, 2017
4477eda
Fixed issue #792 docs problem
liam-grace May 2, 2017
cf5e7cb
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 3, 2017
6b3a1ab
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 4, 2017
04db842
Added event support to base and web runtime
liam-grace May 4, 2017
31a12df
Rebrand cli readme
liam-grace May 4, 2017
7d14ee0
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 5, 2017
32d317a
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 5, 2017
02f8fc9
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 5, 2017
a4cf5be
Web runtime events
liam-grace May 5, 2017
4fa66b1
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 8, 2017
bc404c7
HLFv1 can now emit events
liam-grace May 8, 2017
b60f828
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 8, 2017
2abf60c
GO event hub changes
liam-grace May 8, 2017
4d307f4
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 9, 2017
9359529
merge commit
liam-grace May 10, 2017
b499eeb
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 10, 2017
86602cc
Events given numbers
liam-grace May 10, 2017
f1e6c7e
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 11, 2017
1e877e7
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 11, 2017
7d5f655
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 12, 2017
91b8403
Stop subscribing to events multiple times
liam-grace May 12, 2017
d8d10f0
Merge branch 'master' of github.com:/hyperledger/composer
May 12, 2017
eed5c91
Merge branch 'master' of github.com:/hyperledger/composer
May 15, 2017
956fd30
Latest events
May 15, 2017
cf7a03f
Merge branch 'master' of github.com:/14gracel/fabric-composer
liam-grace May 15, 2017
1182902
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 16, 2017
b722554
Unit tests for events
liam-grace May 17, 2017
ae4bda6
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 17, 2017
8379536
Duktape version fix
liam-grace May 17, 2017
cbabd0a
hlf0.6 event support
liam-grace May 18, 2017
ffd9e13
Merge branch 'master' into master
May 18, 2017
dde7a1b
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 18, 2017
11b9ef2
Logging updates
liam-grace May 18, 2017
6e335d7
Merge branch 'master' of github.com:/14gracel/fabric-composer
liam-grace May 18, 2017
6e849bc
Merge branch 'master' into master
May 18, 2017
aaf4167
Added systests for events
liam-grace May 19, 2017
875806f
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 19, 2017
06da049
Merge branch 'master' of github.com:/14gracel/fabric-composer
liam-grace May 19, 2017
fac629d
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 22, 2017
bf8f0bd
enable couchdb in systemtest
fenglianxu May 23, 2017
084390a
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 24, 2017
e5b8863
Merge branch 'master' into master
cazfletch May 24, 2017
caf73ad
Fixed systests
liam-grace May 24, 2017
587fac1
Merge branch 'master' of github.com:/14gracel/fabric-composer
liam-grace May 24, 2017
5440995
System and unit test fixes
liam-grace May 24, 2017
f2650aa
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 24, 2017
0969e32
rich query support for fabric V1 alpha
fenglianxu May 26, 2017
f1eed89
merge queryService support for rich query
fenglianxu May 26, 2017
639e254
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 30, 2017
b99d648
Removed test program
liam-grace May 30, 2017
06f4404
Removed conflict
liam-grace May 30, 2017
dcf4ad7
Merge branch 'master' into master
May 30, 2017
4597cdf
fix query usage
fenglianxu May 30, 2017
61e6534
Merge branch 'master' of https://github.com/hyperledger/composer
fenglianxu May 31, 2017
91c27c2
Alpha 2 Support
davek-at-ibm Jun 2, 2017
acdbca6
left a .only in
davek-at-ibm Jun 2, 2017
a1bbb1f
Merge branch 'master' of https://github.com/hyperledger/composer
fenglianxu Jun 2, 2017
1192de0
add systest for rich query test
fenglianxu Jun 2, 2017
2af36ca
update query test script
fenglianxu Jun 6, 2017
91c8f20
enable couchdb in systemtest
fenglianxu May 23, 2017
fb3b872
rich query support for fabric V1 alpha
fenglianxu May 26, 2017
910d53f
fix query usage
fenglianxu May 30, 2017
a8530a3
Merges
liam-grace Jun 6, 2017
c839a2b
Fixed docker-compose.yml
liam-grace Jun 6, 2017
f446bb3
Merge branch 'query-systest'
liam-grace Jun 6, 2017
f6d3a6b
Merge branch 'master' of github.com:fenglianxu/composer
liam-grace Jun 6, 2017
6d1afac
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Jun 6, 2017
1f1ce2e
Merge remote-tracking branch 'upstream/hlfv1-latest'
fenglianxu Jun 6, 2017
11b9ec9
Merge pull request #1 from 14gracel/master
fenglianxu Jun 6, 2017
eb54994
query system test
fenglianxu Jun 6, 2017
fa167b4
update queryservice
fenglianxu Jun 6, 2017
72c6f1f
add embedded queryservice
fenglianxu Jun 7, 2017
a7f034e
Merge branch 'master' of https://github.com/hyperledger/composer
fenglianxu Jun 7, 2017
53f13d5
Merge with the latest master branch
fenglianxu Jun 7, 2017
cf0aa72
Merge branch 'master' of https://github.com/hyperledger/composer
fenglianxu Jun 7, 2017
f3d83a7
wallet support, verfication support, tls support
davek-at-ibm Jun 8, 2017
0cc9adb
Squashed commit of the following:
davek-at-ibm Jun 8, 2017
1fa138b
correct package.json to point to working npm modules
davek-at-ibm Jun 8, 2017
c9d77c2
restore lost code
davek-at-ibm Jun 8, 2017
106413c
Fabric beta released
davek-at-ibm Jun 9, 2017
5ed7f5d
Merge branch 'master' into hlfv1-latest
davek-at-ibm Jun 9, 2017
3d8d7c9
Merge branch 'master' into hlfv1-latest
davek-at-ibm Jun 9, 2017
cb180bd
removed merge conflict line
davek-at-ibm Jun 9, 2017
587a1cc
peer review changes plus own code review changes
davek-at-ibm Jun 9, 2017
aeb0475
removed commented out code
davek-at-ibm Jun 9, 2017
c9c5610
Merge branch 'master' into hlfv1-latest
davek-at-ibm Jun 9, 2017
ad28c48
cleanup of one click installer
davek-at-ibm Jun 9, 2017
1aa1598
docker compose yaml was using tls
davek-at-ibm Jun 12, 2017
0a53137
revert change to identityservice.go it didn’t work
davek-at-ibm Jun 12, 2017
30afe75
fixed identity service
davek-at-ibm Jun 12, 2017
4e1e475
save the query test updates
fenglianxu Jun 12, 2017
ea80667
save the query test updates
fenglianxu Jun 12, 2017
8200220
Merge branch 'hlfv0-latest' of https://github.com/hyperledger/composer
fenglianxu Jun 12, 2017
04ab0fd
Merge branch 'master' into hlfv1-latest
davek-at-ibm Jun 12, 2017
7a4af39
Merge branch 'master' of https://github.com/hyperledger/composer
fenglianxu Jun 12, 2017
5b91c07
Merge branch 'hlfv1-latest' of https://github.com/hyperledger/compose…
fenglianxu Jun 12, 2017
5aff033
Merge branch 'master' into hlfv1-latest
Jun 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jspm_packages
.DS_Store
*.swp

# vscode folder
.vscode

#generated jsdoc
packages/composer-website/jekylldocs/jsdoc/

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ matrix:
- env: DOCS=full FC_TASK=docs
- env: SYSTEST=embedded FC_TASK=systest
- env: SYSTEST=hlf FC_TASK=systest
- env: SYSTEST=hlfv1 FC_TASK=systest
- env: SYSTEST=hlfv1_tls FC_TASK=systest
- env: SYSTEST=proxy FC_TASK=systest
- env: SYSTEST=web FC_TASK=systest
dist: trusty
Expand Down
23 changes: 0 additions & 23 deletions .vscode/launch.json

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/composer-admin/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class AdminConnection {
+ Promise update(BusinessNetworkDefinition)
+ Promise ping()
+ Promise list()
+ Promise importIdentity(string,string,string,string)
}
2 changes: 2 additions & 0 deletions packages/composer-admin/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#
Version 0.7.5 {3981adc1fb192a8e53d2250ea8feec9a} 2017-05-22
- added importIdentity method.

Version 0.3.7 {af35a7b1a5872beed588f70d3ee0f345} 2017-01-24
- Move to single version
Expand Down
26 changes: 26 additions & 0 deletions packages/composer-admin/lib/adminconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ class AdminConnection {
return this.connection.list(this.securityContext);
}

/**
* import an identity into a profiles' wallet
*
* @param {string} connectionProfile Name of the connection profile
* @param {string} id The id to associate with this identity
* @param {string} publicKey The signer cert in PEM format
* @param {string} privateKey The private key in PEM format
* @returns {Promise} A promise which is resolved when the identity is imported
*
* @memberOf AdminConnection
*/
importIdentity(connectionProfile, id, publicKey, privateKey) {
let savedConnectionManager;
return this.connectionProfileManager.getConnectionManager(connectionProfile)
.then((connectionManager) => {
savedConnectionManager = connectionManager;
return this.getProfile(connectionProfile);
})
.then((profileData) => {
return savedConnectionManager.importIdentity(profileData, id, publicKey, privateKey);
})
.catch((error) => {
throw new Error('failed to import identity. ' + error.message);
});
}

}

module.exports = AdminConnection;
25 changes: 25 additions & 0 deletions packages/composer-admin/test/adminconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('AdminConnection', () => {
mockConnectionManager.connect.resolves(mockConnection);
adminConnection = new AdminConnection();
sinon.stub(adminConnection.connectionProfileManager, 'connect').resolves(mockConnection);
sinon.stub(adminConnection.connectionProfileManager, 'getConnectionManager').resolves(mockConnectionManager);
sinon.stub(adminConnection.connectionProfileStore, 'save').withArgs('testprofile', sinon.match.any).resolves();
sinon.stub(adminConnection.connectionProfileStore, 'load').withArgs('testprofile').resolves(config);
sinon.stub(adminConnection.connectionProfileStore, 'loadAll').resolves({ profile1: config, profile2: config2 });
Expand Down Expand Up @@ -253,4 +254,28 @@ describe('AdminConnection', () => {

});

describe('#importIdentity', () => {
it('should be able to import an identity', () => {
mockConnectionManager.importIdentity = sinon.stub();
adminConnection.connection = mockConnection;
adminConnection.securityContext = mockSecurityContext;
return adminConnection.importIdentity('testprofile', 'anid', 'acerttosign', 'akey')
.then(() => {
sinon.assert.calledOnce(mockConnectionManager.importIdentity);
sinon.assert.calledWith(mockConnectionManager.importIdentity, config, 'anid', 'acerttosign', 'akey');
});
});

it('should throw an error if import fails', () => {
mockConnectionManager.importIdentity = sinon.stub();
mockConnectionManager.importIdentity.rejects(new Error('no identity imported'));
adminConnection.connection = mockConnection;
adminConnection.securityContext = mockSecurityContext;
return adminConnection.importIdentity('testprofile', 'anid', 'acerttosign', 'akey')
.should.be.rejectedWith(/no identity imported/);
});


});

});
5 changes: 3 additions & 2 deletions packages/composer-cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ let results = yargs
.version(function() {
return getInfo('composer-cli')+
getInfo('composer-admin')+getInfo('composer-client')+
getInfo('composer-common')+getInfo('composer-runtime')+
getInfo('composer-connector-hlfv1')+getInfo('composer-runtime-hlfv1');
getInfo('composer-common')+getInfo('composer-runtime-hlf')+
getInfo('composer-connector-hlf')+getInfo('composer-runtime-hlfv1')+
getInfo('composer-connector-hlfv1');
})
.describe('v', 'show version information')
.command(
Expand Down
34 changes: 34 additions & 0 deletions packages/composer-cli/lib/cmds/identity/importCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const Import = require ('./lib/import.js');

module.exports.command = 'import [options]';
module.exports.describe = 'Import an identity to wallet defined by the connection profile';
module.exports.builder = {
connectionProfileName: {alias: 'p', required: true, describe: 'The connection profile name', type: 'string' },
userId: { alias: 'u', required: true, describe: 'The user ID for the new identity', type: 'string' },
publicKeyFile: { alias: 'c', required: true, describe: 'File containing the public key', type: 'string' },
privateKeyFile: { alias: 'k', required: true, describe: 'File containing the private key', type: 'string' }
};

module.exports.handler = (argv) => {
argv.thePromise = Import.handler(argv)
.then(() => {
console.log ('Command completed successfully.');
});
return argv.thePromise;
};
65 changes: 65 additions & 0 deletions packages/composer-cli/lib/cmds/identity/lib/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const fs = require('fs');

const cmdUtil = require('../../utils/cmdutils');

/**
* <p>
* Composer "identity issue" command
* </p>
* <p><a href="diagrams/Deploy.svg"><img src="diagrams/deploy.svg" style="width:100%;"/></a></p>
* @private
*/
class Import {

/**
* Command process for deploy command
* @param {string} argv argument list from composer command
* @return {Promise} promise when command complete
*/
static handler(argv) {
let userId;
let publicKeyFile;
let privateKeyFile;
let connectionProfileName;

userId = argv.userId;
publicKeyFile = argv.publicKeyFile;
privateKeyFile = argv.privateKeyFile;
connectionProfileName = argv.connectionProfileName;
let adminConnection = cmdUtil.createAdminConnection();
let signerCert;
let key;
try {
signerCert = fs.readFileSync(publicKeyFile).toString();
} catch(error) {
return Promise.reject(new Error('Unable to read public key file ' + publicKeyFile + '. ' + error.message));
}
try {
key = fs.readFileSync(privateKeyFile).toString();
} catch(error) {
return Promise.reject(new Error('Unable to read private key file ' + privateKeyFile + '. ' + error.message));
}
return adminConnection.importIdentity(connectionProfileName, userId, signerCert, key)
.then((result) => {
console.log(`An identity was imported with name '${userId}' successfully`);
});
}
}

module.exports = Import;
115 changes: 115 additions & 0 deletions packages/composer-cli/test/identity/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const Client = require('composer-admin');

const Import = require('../../lib/cmds/identity/importCommand.js');
const CmdUtil = require('../../lib/cmds/utils/cmdutils.js');
const fs = require('fs');

const sinon = require('sinon');
require('sinon-as-promised');
const chai = require('chai');
chai.should();
chai.use(require('chai-as-promised'));

const PROFILE_NAME = 'myprofile';
const USER_ID = 'SuccessKid';
const CERT_PATH = 'someCertPath';
const KEY_PATH = 'someKeyPath';

describe('composer identity import CLI unit tests', () => {

let sandbox;
let mockAdminConnection;

beforeEach(() => {
sandbox = sinon.sandbox.create();
mockAdminConnection = sinon.createStubInstance(Client.AdminConnection);
sandbox.stub(CmdUtil, 'createAdminConnection').returns(mockAdminConnection);
sandbox.stub(process, 'exit');
});

afterEach(() => {
sandbox.restore();
});

it('should import a new identity using the specified profile', () => {
let argv = {
connectionProfileName: PROFILE_NAME,
userId: USER_ID,
publicKeyFile: CERT_PATH,
privateKeyFile: KEY_PATH
};

let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).returns('acert');
fsStub.withArgs(KEY_PATH).returns('akey');
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').resolves();
return Import.handler(argv)
.then(() => {
sinon.assert.calledOnce(mockAdminConnection.importIdentity);
sinon.assert.calledWith(mockAdminConnection.importIdentity, PROFILE_NAME, USER_ID, 'acert', 'akey');
});
});

it('should fail gracefully if importIdentity fails', () => {
let argv = {
connectionProfileName: PROFILE_NAME,
userId: USER_ID,
publicKeyFile: CERT_PATH,
privateKeyFile: KEY_PATH
};

let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).returns('acert');
fsStub.withArgs(KEY_PATH).returns('akey');
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').rejects('some error');
return Import.handler(argv)
.should.be.rejectedWith(/some error/);
});

it('should fail gracefully if cert file cannot be found', () => {
let argv = {
connectionProfileName: PROFILE_NAME,
userId: USER_ID,
publicKeyFile: CERT_PATH,
privateKeyFile: KEY_PATH
};

let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).throws(new Error('no file found'));
fsStub.withArgs(KEY_PATH).returns('akey');
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').resolves();
return Import.handler(argv)
.should.be.rejectedWith(/no file found/);

});

it('should fail gracefully if key file cannot be found', () => {
let argv = {
connectionProfileName: PROFILE_NAME,
userId: USER_ID,
publicKeyFile: CERT_PATH,
privateKeyFile: KEY_PATH
};

let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).returns('acert');
fsStub.withArgs(KEY_PATH).throws(new Error('no key file found'));
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').resolves();
return Import.handler(argv)
.should.be.rejectedWith(/no key file found/);

});

});
14 changes: 14 additions & 0 deletions packages/composer-common/lib/connectionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ class ConnectionManager {
return Promise.reject(new Error('abstract function called'));
}

/**
* Import an identity into a profile wallet or keystore
*
* @param {object} profileDefinition the profile definition
* @param {string} id the id to associate with the identity
* @param {string} publicKey the public key
* @param {string} privateKey the private key
* @returns {Promise} a promise which resolves when the identity is imported
*
* @memberOf HLFConnectionManager
*/
importIdentity(profileDefinition, id, publicKey, privateKey) {
return Promise.reject(new Error('Import identity not supported by this connection profile'));
}
/**
* Stop serialization of this object.
* @return {Object} An empty object.
Expand Down
1 change: 0 additions & 1 deletion packages/composer-common/lib/connectionprofilemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class ConnectionProfileManager {
* @abstract
*/
connect(connectionProfile, businessNetworkIdentifier, additionalConnectOptions) {

LOG.info('connect','Connecting using ' + connectionProfile, businessNetworkIdentifier);

let connectOptions;
Expand Down
Loading