Skip to content

Commit

Permalink
Fixes for start plan (hyperledger-archives#3508)
Browse files Browse the repository at this point in the history
Added pem to signedCert property
Updated invalid connection profile names

contributes to hyperledger/composer#3506

Signed-off-by: Caroline Church <[email protected]>
  • Loading branch information
cazfletch authored and nklincoln committed Mar 1, 2018
1 parent db86ed1 commit 4c5ac0c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
51 changes: 34 additions & 17 deletions packages/composer-cli/lib/cmds/card/lib/schema/ccpschema.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
{
"$schema" : "http://json-schema.org/schema#",
"definitions" : {
"client" : {
"type" : "object",
"properties" : {
"organization" : { "type" : "string" }
"organization" : { "type" : "string" }
},
"required" : [ "organization" ]
},
Expand Down Expand Up @@ -57,20 +57,20 @@
"channel-peer" : {
"type" : "object",
"patternProperties": {
"^.*$" : {
"^.*$" : {
"endorsingPeer" : { "type" : "boolean" },
"chaincodeQuery" : { "type" : "boolean" },
"ledgerQuery" : { "type" : "boolean" },
"eventSource" : { "type" : "boolean" }
},
"additionalProperties": false
"additionalProperties": false
},
"minimum" : 1
},
"orderers" : {
"type" : "object",
"patternProperties": {
"^.*$" : { "$ref": "#/definitions/orderer" }
"^.*$" : { "$ref": "#/definitions/orderer" }
},
"minimum": 1
},
Expand Down Expand Up @@ -112,7 +112,7 @@
"^.*$" : { "$ref": "#/definitions/organization" }
},
"minimum": 1
},
},
"organization" : {
"type" : "object",
"properties": {
Expand All @@ -127,34 +127,51 @@
"adminPrivateKey" : {
"type" : "object",
"properties": {
"oneOf" : {
"pem" : { "type" : "string" },
"path" : { "type" : "string" }
"pem" : { "type" : "string" },
"path": {
"type": "string"
}
},
"required" : [ "pem" ]
"oneOf" : [{
"anyOf" : [{
"required" : ["path"]
}, {
"required" : ["pem"]
}
]
}]
},
"signedCert" : {
"type" : "object",
"properties": {
"path" : { "type" : "string" }
"pem" : { "type" : "string" },
"path": {
"type": "string"
}
},
"required" : [ "path" ]
"oneOf" : [{
"anyOf" : [{
"required" : ["path"]
}, {
"required" : ["pem"]
}
]
}]
},
"peers" : {
"type" : "object",
"patternProperties": {
"^.*$" : { "$ref": "#/definitions/peer" }
"^.*$" : { "$ref": "#/definitions/peer" }
},
"minimum": 1
},
"peer" : {
"type" : "object",
"type" : "object",
"properties": {
"url" : { "format" : "uri" },
"eventUrl" : { "format" : "uri" },
"grpcOptions" : { "$ref": "#/definitions/grpcOptions" },
"tlsCACerts" : { "$ref": "#/definitions/tlsCACerts" }
"tlsCACerts" : { "$ref": "#/definitions/tlsCACerts" }
},
"required": [ "url", "eventUrl"]
}
Expand All @@ -173,5 +190,5 @@
"organizations" : { "$ref" : "#/definitions/organizations" },
"peers" : { "$ref": "#/definitions/peers" }
},
"required" : ["name", "x-type", "client", "certificateAuthorities", "channels", "orderers", "peers"]
}
"required" : ["name", "x-type", "client", "certificateAuthorities", "channels", "orderers", "peers"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ class BusinessNetworkCardStore {
* @returns {String} A card name
*/
static getDefaultCardName(card) {
const locationName = card.getBusinessNetworkName() || card.getConnectionProfile().name;
let locationName;
if(card.getBusinessNetworkName()) {
locationName = card.getBusinessNetworkName();
} else {
locationName = card.getConnectionProfile().name;
// take out all invalid characters
locationName = locationName.replace(/[^a-zA-Z0-9-_\s]/g, '');
// swap spaces for -
locationName = locationName.replace(/\s/gi, '-');
}

return card.getUserName() + '@' + locationName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe('BusinessNetworkCardStore', function() {
const result = BusinessNetworkCardStore.getDefaultCardName(card);
result.should.include(metadata.userName).and.include(connectionProfile.name);
});

it('should update the name given in the connection profile if invalid', () => {
const metadata = { userName: 'PeerAdmin', roles: [ 'PeerAdmin', 'ChannelAdmin' ] };
const connectionProfile = { name: 'profile-name_that\'s got spaces and &^%$# characters' };
const card = new IdCard(metadata, connectionProfile);
const result = BusinessNetworkCardStore.getDefaultCardName(card);
result.should.include(metadata.userName).and.include('profile-name_thats-got-spaces-and--characters');
});
});

describe('#get', function() {
Expand Down

0 comments on commit 4c5ac0c

Please sign in to comment.