Skip to content

Commit b17d88f

Browse files
denyeartmastersingh24
authored andcommitted
[FAB-13463] Document vendoring for shim extensions
Add documentation to clarify how to vendor shim extensions into chaincode. Change-Id: Ic568e00c19cd512cfd2160b109ac9090c8a38901 Signed-off-by: David Enyeart <enyeart@us.ibm.com>
1 parent 99959b9 commit b17d88f

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

docs/source/chaincode4ade.rst

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ and walk through the purpose of each method in the Chaincode Shim API.
2525
Chaincode API
2626
-------------
2727

28-
.. note:: There is another set of chaincode APIs that allow the client (submitter)
29-
identity to be used for access control decisions, whether that is based
30-
on client identity itself, or the org identity, or on a client identity
31-
attribute. For example an asset that is represented as a key/value may
32-
include the client's identity, and only this client may be authorized
33-
to make updates to the key/value. The client identity library has APIs
34-
that chaincode can use to retrieve this submitter information to make
35-
such access control decisions.
36-
37-
We won't cover that in this tutorial, however it is
38-
`documented here <https://github.com/hyperledger/fabric/blob/master/core/chaincode/shim/ext/cid/README.md>`_.
39-
4028
Every chaincode program must implement the ``Chaincode`` interface:
4129

4230
- `Go <https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#Chaincode>`__
@@ -508,6 +496,28 @@ By default, we mount only ``sacc``. However, you can easily test different
508496
chaincodes by adding them to the ``chaincode`` subdirectory and relaunching
509497
your network. At this point they will be accessible in your ``chaincode`` container.
510498

499+
Chaincode access control
500+
------------------------
501+
502+
Chaincode can utilize the client (submitter) certificate for access
503+
control decisions by calling the GetCreator() function. Additionally
504+
the Go shim provides extension APIs that extract client identity
505+
from the submitter's certificate to be used for access control decisions,
506+
whether that is based on client identity itself, or the org identity,
507+
or on a client identity attribute.
508+
509+
For example an asset that is represented as a key/value may include the
510+
client's identity as part of the value (for example as a JSON attribute
511+
indicating that asset owner), and only this client may be authorized
512+
to make updates to the key/value in the future. The client identity
513+
library extension APIs can be used within chaincode to retrieve this
514+
submitter information to make such access control decisions.
515+
516+
See the `client identity (CID) library documentation <https://github.com/hyperledger/fabric/blob/master/core/chaincode/shim/ext/cid/README.md>`_
517+
for more details.
518+
519+
To add the client identity shim extension to your chaincode as a dependency, see vendoring_.
520+
511521
Chaincode encryption
512522
--------------------
513523

@@ -531,10 +541,18 @@ that the sample encryption chaincode then leverages. As such, the chaincode can
531541
now marry the basic shim APIs of ``Get`` and ``Put`` with the added functionality of
532542
``Encrypt`` and ``Decrypt``.
533543

544+
To add the encryption entities extension to your chaincode as a dependency, see vendoring_.
545+
546+
.. _vendoring:
547+
534548
Managing external dependencies for chaincode written in Go
535549
----------------------------------------------------------
536-
If your chaincode requires packages not provided by the Go standard library, you will need
537-
to include those packages with your chaincode. There are `many tools available <https://github.com/golang/go/wiki/PackageManagementTools>`__
550+
If your chaincode requires packages not provided by the Go standard library,
551+
you will need to include those packages with your chaincode. It is also a
552+
good practice to add the shim and any extension libraries to your chaincode
553+
as a dependency.
554+
555+
There are `many tools available <https://github.com/golang/go/wiki/PackageManagementTools>`__
538556
for managing (or "vendoring") these dependencies. The following demonstrates how to use
539557
``govendor``:
540558

@@ -544,7 +562,11 @@ for managing (or "vendoring") these dependencies. The following demonstrates ho
544562
govendor add +external // Add all external package, or
545563
govendor add github.com/external/pkg // Add specific external package
546564
547-
This imports the external dependencies into a local ``vendor`` directory. ``peer chaincode package``
565+
This imports the external dependencies into a local ``vendor`` directory.
566+
If you are vendoring the Fabric shim or shim extensions, clone the
567+
Fabric repository to your $GOPATH src/github.com/hyperledger directory.
568+
569+
Once dependencies are vendored in your chaincode directory, ``peer chaincode package``
548570
and ``peer chaincode install`` operations will then include code associated with the
549571
dependencies into the chaincode package.
550572

docs/source/endorsement-policies.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ following functions apply:
165165
GetPrivateDataValidationParameter(collection, key string) ([]byte, error)
166166
167167
To help set endorsement policies and marshal them into validation
168-
parameter byte arrays, the shim provides convenience functions that allow the
169-
chaincode developer to deal with endorsement policies in terms of the MSP
170-
identifiers of organizations(`KeyEndorsementPolicy <https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim/ext/statebased#KeyEndorsementPolicy>`_):
168+
parameter byte arrays, the Go shim provides an extension with convenience
169+
functions that allow the chaincode developer to deal with endorsement policies
170+
in terms of the MSP identifiers of organizations, see `KeyEndorsementPolicy <https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim/ext/statebased#KeyEndorsementPolicy>`_:
171171

172172
.. code-block:: Go
173173
@@ -192,6 +192,8 @@ required to endorse the key change, pass both org ``MSPIDs`` to ``AddOrgs()``,
192192
and then call ``Policy()`` to construct the endorsement policy byte array that
193193
can be passed to ``SetStateValidationParameter()``.
194194

195+
To add the shim extension to your chaincode as a dependency, see :ref:`vendoring`.
196+
195197
Validation
196198
----------
197199

0 commit comments

Comments
 (0)