Skip to content

Commit

Permalink
FABN-1096 NodeSDK add member_only_read
Browse files Browse the repository at this point in the history
SideDB needs to support member_only_read attribute
on collection definitions

Change-Id: Ia79792359b17e13c2c736579ecb262498496e479
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Jan 17, 2019
1 parent f7d05b1 commit b787847
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
7 changes: 6 additions & 1 deletion fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,12 @@ const Channel = class {
* data expires. For instance if the value is set to 10, a key last modified by block
* number 100 will be purged at block number 111. A zero value is treated same as MaxUint64,
* where the data will not be purged.
* @property {Policy} policy - The
* @property {boolean} member_read_only - The member only read access denotes
* whether only collection member clients can read the private data (if set
* to true), or even non members can read the data (if set to false, for
* example if you want to implement more granular access logic in the
* chaincode)
* @property {Policy} policy - The "member_orgs_policy" policy
*/

/**
Expand Down
27 changes: 22 additions & 5 deletions fabric-client/lib/SideDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CollectionConfig {
* @property {number} maxPeerCount integer
* @property {number} requiredPeerCount integer
* @property {!Long|number|string|!{low: number, high: number, unsigned: boolean}} blockToLive param will be converted to unsigned int64 as Long
* @property {boolean} memberOnlyRead denotes whether only collection member clients can read the private data
*/

/**
Expand Down Expand Up @@ -71,8 +72,10 @@ class CollectionConfig {
* @returns {collectionConfig}
*/
static checkCollectionConfig(collectionConfig) {
const method = 'checkCollectionConfig';
let {
blockToLive
blockToLive,
memberOnlyRead
} = collectionConfig;

const {
Expand Down Expand Up @@ -107,19 +110,31 @@ class CollectionConfig {
throw new Error(format('CollectionConfig Requires Param "blockToLive" of type unsigned int64, found %j(type: %s)', blockToLive, typeof blockToLive));
} else {
const test = Long.fromValue(blockToLive, true);
logger.debug('checkCollectionConfig blockToLive parse from %j and parsed to %s)', blockToLive, test);
logger.debug('%s blockToLive parse from %j and parsed to %s)', method, blockToLive, test);

if (test.toString() !== blockToLive.toString()) {
throw new Error(format('CollectionConfig Requires Param "blockToLive" to be a valid unsigned int64, input is %j and parsed to %s)', blockToLive, test));
}
}

if (typeof memberOnlyRead !== 'undefined') {
if (typeof memberOnlyRead === 'boolean') {
logger.debug('%s - memberOnlyRead has value of %s', method, memberOnlyRead);
} else {
throw new Error('CollectionConfig Requires Param "memberOnlyRead" to be boolean, input is %s', memberOnlyRead);
}
} else {
logger.debug('%s - memberOnlyRead defaulting to false', method);
memberOnlyRead = false;
}

return {
name,
policy,
maxPeerCount,
requiredPeerCount,
blockToLive
blockToLive,
memberOnlyRead
};
}

Expand All @@ -133,15 +148,17 @@ class CollectionConfig {
policy,
maxPeerCount,
requiredPeerCount,
blockToLive
blockToLive,
memberOnlyRead
} = this.checkCollectionConfig(collectionConfig);

const static_collection_config = {
name,
member_orgs_policy: {},
required_peer_count: requiredPeerCount,
maximum_peer_count: maxPeerCount,
block_to_live: blockToLive
block_to_live: blockToLive,
member_only_read: memberOnlyRead
};

const principals = [];
Expand Down
5 changes: 5 additions & 0 deletions fabric-client/lib/protos/common/collection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ message StaticCollectionConfig {
// For instance if the value is set to 10, a key last modified by block number 100
// will be purged at block number 111. A zero value is treated same as MaxUint64
uint64 block_to_live = 5;
// The member only read access denotes whether only collection member clients
// can read the private data (if set to true), or even non members can
// read the data (if set to false, for example if you want to implement more granular
// access logic in the chaincode)
bool member_only_read = 6;
}


Expand Down
1 change: 1 addition & 0 deletions fabric-client/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ declare namespace Client { // tslint:disable-line:no-namespace
required_peer_count: number;
maximum_peer_count: number;
block_to_live: number;
member_only_read: boolean;
}

export interface Response {
Expand Down
3 changes: 2 additions & 1 deletion test/integration/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ async function startChaincode(t, client, channel, orderer, peers, chaincode_id,
'policy': policy,
'requiredPeerCount': 0,
'maxPeerCount': 1,
'blockToLive': 100
'blockToLive': 100,
'memberOnlyRead': true
}
]
};
Expand Down
2 changes: 2 additions & 0 deletions test/integration/e2e/getCollectionsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ test('getCollectionsConfig from peer', async (t) => {
t.equal(results[0].required_peer_count, 1);
t.equal(results[0].maximum_peer_count, 1);
t.equal(results[0].block_to_live, 100);
t.equal(results[0].member_only_read, false);
t.deepEqual(results[0].policy.identities, [{msp_identifier: 'Org1MSP', role: 'MEMBER'}, {msp_identifier: 'Org2MSP', role: 'MEMBER'}]);

t.equal(results[1].type, 'static_collection_config');
t.equal(results[1].name, 'sensitiveCol');
t.equal(results[1].required_peer_count, 0);
t.equal(results[1].maximum_peer_count, 1);
t.equal(results[1].block_to_live, 100);
t.equal(results[1].member_only_read, false);
t.deepEqual(results[1].policy.identities, [{msp_identifier: 'Org1MSP', role: 'MEMBER'}]);
t.end();
} catch (err) {
Expand Down

0 comments on commit b787847

Please sign in to comment.