Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit bf29760

Browse files
author
Baha Shaaban
committed
[FAB-6275] Add Default GO SDK config
Change-Id: I338a8a59e586321930dc8b62ff0175c573b44995 Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
1 parent 3b6d77b commit bf29760

File tree

8 files changed

+428
-63
lines changed

8 files changed

+428
-63
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
134134
go test
135135
```
136136

137+
#### Using default config
138+
139+
Default SDK Go configurations are found in the code under /pkg/config/config.yaml
140+
141+
To override the default in non Dev environment, set the default path in the following environment variable:
142+
143+
**FABRIC_SDK_CONFIG_PATH**=/path/to/default/config yaml(without specifying the yaml file name)
144+
145+
This path value must be a directory. It must contain a default 'config.yaml' file.
146+
Note that this default config is used only if environment configuration yaml file is missing to ensure all environment variables are created regardless of their values.
147+
137148
#### Testing with Local Build of Fabric (Advanced)
138149

139150
Alternatively you can build and run Fabric on your own box using the following commands:

pkg/config/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"strings"
1919
"time"
2020

21+
"path/filepath"
22+
2123
"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
2224
bccspFactory "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
2325
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/pkcs11"
@@ -56,6 +58,10 @@ func InitConfigWithCmdRoot(configFile string, cmdRootPrefix string) (*Config, er
5658
myViper.AutomaticEnv()
5759
replacer := strings.NewReplacer(".", "_")
5860
myViper.SetEnvKeyReplacer(replacer)
61+
err := loadDefaultConfig()
62+
if err != nil {
63+
return nil, err
64+
}
5965
if configFile != "" {
6066
// create new viper
6167
myViper.SetConfigFile(configFile)
@@ -85,6 +91,23 @@ func InitConfigWithCmdRoot(configFile string, cmdRootPrefix string) (*Config, er
8591
return &Config{tlsCertPool: x509.NewCertPool()}, nil
8692
}
8793

94+
// load Default confid
95+
func loadDefaultConfig() error {
96+
// get Environment Default Config Path
97+
defaultPath := os.Getenv("FABRIC_SDK_CONFIG_PATH")
98+
if defaultPath != "" { // if set, use it to load default config
99+
myViper.AddConfigPath(strings.Replace(defaultPath, "$GOPATH", os.Getenv("GOPATH"), -1))
100+
} else { // else fallback to default DEV path
101+
devPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "hyperledger", "fabric-sdk-go", "pkg", "config")
102+
myViper.AddConfigPath(devPath)
103+
}
104+
err := myViper.ReadInConfig() // Find and read the config file
105+
if err != nil { // Handle errors reading the config file
106+
return fmt.Errorf("fatal error config file: %s", err)
107+
}
108+
return nil
109+
}
110+
88111
// Client returns the Client config
89112
func (c *Config) Client() (*apiconfig.ClientConfig, error) {
90113
config, err := c.NetworkConfig()

pkg/config/config.yaml

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#
2+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
#
7+
# Default GO SDK Configuration
8+
#
9+
# The network connection profile provides client applications the information about the target
10+
# blockchain network that are necessary for the applications to interact with it. These are all
11+
# knowledge that must be acquired from out-of-band sources. This file provides such a source.
12+
#
13+
name: "default-network"
14+
15+
#
16+
# Any properties with an "x-" prefix will be treated as application-specific, exactly like how naming
17+
# in HTTP headers or swagger properties work. The SDK will simply ignore these fields and leave
18+
# them for the applications to process. This is a mechanism for different components of an application
19+
# to exchange information that are not part of the standard schema described below. In particular,
20+
# the "x-type" property with the "hlfv1" value example below is used by Hyperledger Composer to
21+
# determine the type of Fabric networks (v0.6 vs. v1.0) it needs to work with.
22+
#
23+
x-type: "hlfv1"
24+
x-loggingLevel: info
25+
26+
#
27+
# Describe what the target network is/does.
28+
#
29+
description: "The network description"
30+
31+
#
32+
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
33+
#
34+
version: 1.0.0
35+
36+
#
37+
# The client section used by GO SDK.
38+
#
39+
client:
40+
# Which organization does this application instance belong to? The value must be the name of an org
41+
# defined under "organizations"
42+
organization: match_value_with_one_of_organizations
43+
44+
logging:
45+
level: info
46+
47+
# set connection timeouts for the peer and orderer for the client
48+
connection:
49+
timeout:
50+
peer:
51+
endorser: 3s
52+
eventHub: 3s
53+
eventReg: 3s
54+
orderer: 3s
55+
56+
# Needed to load users crypto keys and certs.
57+
cryptoconfig:
58+
path: path/to/cryptoconfig
59+
60+
# enable/disable tls for the client
61+
tls:
62+
enabled: true
63+
64+
# Some SDKs support pluggable KV stores, the properties under "credentialStore"
65+
# are implementation specific
66+
credentialStore:
67+
# [Optional]. Not used by Go SDK. Others SDKs may use it if using an alternative impl
68+
# Could be used if SDK would require an object for properties like url, db name, etc.
69+
path: unused/by/sdk/go
70+
71+
# [Optional]. Specific to the CryptoSuite implementation used by GO SDK. Software-based implementations
72+
# requiring a key store. PKCS#11 based implementations does not.
73+
cryptoStore:
74+
# Specific to the underlying KeyValueStore that backs the crypto key store.
75+
path: /usually/it/is/tmp/msp
76+
77+
# [Optional]. Specific to Composer environment. Not used by SDK Go.
78+
wallet: wallet-name-unused-by-sdk-go
79+
80+
# BCCSP config for the client. Used by GO SDK.
81+
BCCSP:
82+
security:
83+
enabled: true
84+
default:
85+
# provider: "SW"
86+
provider: ""
87+
# hashAlgorithm: "SHA2"
88+
hashAlgorithm: ""
89+
softVerify: true
90+
ephemeral: false
91+
level: 256
92+
pin: "somepin"
93+
label: "ForFabric"
94+
#library: "/usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so, /usr/lib/softhsm/libsofthsm2.so ,/usr/lib/s390x-linux-gnu/softhsm/libsofthsm2.so, /usr/lib/powerpc64le-linux-gnu/softhsm/libsofthsm2.so, /usr/local/Cellar/softhsm/2.1.0/lib/softhsm/libsofthsm2.so"
95+
library: "add BCCSP library here"
96+
97+
#
98+
# [Optional]. But most apps would have this section so that channel objects can be constructed
99+
# based on the content below. If an app is creating channels, then it likely will not need this
100+
# section.
101+
#
102+
channels:
103+
# name of the channel
104+
# mychannel:
105+
# Required. list of orderers designated by the application to use for transactions on this
106+
# channel. This list can be a result of access control ("org1" can only access "ordererA"), or
107+
# operational decisions to share loads from applications among the orderers. The values must
108+
# be "names" of orgs defined under "organizations/peers"
109+
# orderers:
110+
# - orderer.example.com
111+
112+
# Required. list of peers from participating orgs
113+
# peers:
114+
# peer0.org1.example.com:
115+
# [Optional]. will this peer be sent transaction proposals for endorsement? The peer must
116+
# have the chaincode installed. The app can also use this property to decide which peers
117+
# to send the chaincode install request. Default: true
118+
# endorsingPeer: true
119+
120+
# [Optional]. will this peer be sent query proposals? The peer must have the chaincode
121+
# installed. The app can also use this property to decide which peers to send the
122+
# chaincode install request. Default: true
123+
# chaincodeQuery: true
124+
125+
# [Optional]. will this peer be sent query proposals that do not require chaincodes, like
126+
# queryBlock(), queryTransaction(), etc. Default: true
127+
# ledgerQuery: true
128+
129+
# [Optional]. will this peer be the target of the SDK's listener registration? All peers can
130+
# produce events but the app typically only needs to connect to one to listen to events.
131+
# Default: true
132+
# eventSource: true
133+
134+
135+
# [Optional]. what chaincodes are expected to exist on this channel? The application can use
136+
# this information to validate that the target peers are in the expected state by comparing
137+
# this list with the query results of getInstalledChaincodes() and getInstantiatedChaincodes()
138+
# chaincodes:
139+
# the format follows the "canonical name" of chaincodes by fabric code
140+
# - example02:v1
141+
# - marbles:1.0
142+
143+
#
144+
# list of participating organizations in this network
145+
#
146+
organizations:
147+
# org1:
148+
# mspid: Org1MSP
149+
150+
# peers:
151+
# - peer0.org1.example.com
152+
153+
# [Optional]. Certificate Authorities issue certificates for identification purposes in a Fabric based
154+
# network. Typically certificates provisioning is done in a separate process outside of the
155+
# runtime network. Fabric-CA is a special certificate authority that provides a REST APIs for
156+
# dynamic certificate management (enroll, revoke, re-enroll). The following section is only for
157+
# Fabric-CA servers.
158+
# certificateAuthorities:
159+
# - ca-org1
160+
161+
# [Optional]. If the application is going to make requests that are reserved to organization
162+
# administrators, including creating/updating channels, installing/instantiating chaincodes, it
163+
# must have access to the admin identity represented by the private key and signing certificate.
164+
# Both properties can be the PEM string or local path to the PEM file. Note that this is mainly for
165+
# convenience in development mode, production systems should not expose sensitive information
166+
# this way. The SDK should allow applications to set the org admin identity via APIs, and only use
167+
# this route as an alternative when it exists.
168+
# adminPrivateKey:
169+
# pem: "-----BEGIN PRIVATE KEY----- <etc>"
170+
# signedCert:
171+
# path: "/tmp/somepath/signed-cert.pem"
172+
173+
174+
#
175+
# List of orderers to send transaction and channel create/update requests to. For the time
176+
# being only one orderer is needed. If more than one is defined, which one get used by the
177+
# SDK is implementation specific. Consult each SDK's documentation for its handling of orderers.
178+
#
179+
orderers:
180+
# orderer.example.com:
181+
# url: orderer.example.com:7050
182+
183+
# these are standard properties defined by the gRPC library
184+
# they will be passed in as-is to gRPC client constructor
185+
# grpcOptions:
186+
# ssl-target-name-override: orderer.example.com
187+
# grpc-max-send-message-length: 15
188+
189+
# tlsCACerts:
190+
# Certificate location absolute path
191+
# path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
192+
193+
#
194+
# List of peers to send various requests to, including endorsement, query
195+
# and event listener registration.
196+
#
197+
peers:
198+
# peer0.org1.example.com:
199+
# this URL is used to send endorsement and query requests
200+
# url: peer0.org1.example.com:7051
201+
202+
# this URL is used to connect the EventHub and registering event listeners
203+
# eventUrl: peer0.org1.example.com:7053
204+
205+
# grpcOptions:
206+
# ssl-target-name-override: peer0.org1.example.com
207+
# grpc.http2.keepalive_time: 15
208+
209+
# tlsCACerts:
210+
# Certificate location absolute path
211+
# path: path/to/tls/cert/for/peer0/org1
212+
213+
#
214+
# Fabric-CA is a special kind of Certificate Authority provided by Hyperledger Fabric which allows
215+
# certificate management to be done via REST APIs. Application may choose to use a standard
216+
# Certificate Authority instead of Fabric-CA, in which case this section would not be specified.
217+
#
218+
certificateAuthorities:
219+
# ca-org1:
220+
# url: https://ca_peerOrg1:7054
221+
# the properties specified under this object are passed to the 'http' client verbatim when
222+
# making the request to the Fabric-CA server
223+
# httpOptions:
224+
# verify: true
225+
# tlsCACerts:
226+
# Comma-Separated list of paths
227+
# path: path/to/tls/cert/for/ca-org1
228+
# Client key and cert for SSL handshake with Fabric CA
229+
# client:
230+
# keyfile: path/to/client_fabric_client-key.pem
231+
# certfile: path/to/client_fabric_client.pem
232+
233+
# Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is
234+
# needed to enroll and invoke new users.
235+
# registrar:
236+
# enrollId: usualy-it-is_admin
237+
# enrollSecret: adminpasswd
238+
# [Optional] The optional name of the CA.
239+
# caName: ca-org1

0 commit comments

Comments
 (0)