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

Commit a56cd3a

Browse files
author
Aleksandar Likic
committed
[FAB-8766] Move identitymgr implementation to pkg/msp
Change-Id: I676eadab63150530e79f8ed153e7f8244860027c Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
1 parent c826e2f commit a56cd3a

33 files changed

+748
-593
lines changed

pkg/core/config/config.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (c *Config) loadTemplateConfig() error {
274274
}
275275

276276
// if set, use it to load default config
277-
c.configViper.AddConfigPath(substPathVars(templatePath))
277+
c.configViper.AddConfigPath(SubstPathVars(templatePath))
278278
err := c.configViper.ReadInConfig() // Find and read the config file
279279
if err != nil { // Handle errors reading the config file
280280
return errors.Wrap(err, "loading config file failed")
@@ -290,9 +290,9 @@ func (c *Config) Client() (*core.ClientConfig, error) {
290290
}
291291
client := config.Client
292292

293-
client.TLSCerts.Path = substPathVars(client.TLSCerts.Path)
294-
client.TLSCerts.Client.Key.Path = substPathVars(client.TLSCerts.Client.Key.Path)
295-
client.TLSCerts.Client.Cert.Path = substPathVars(client.TLSCerts.Client.Cert.Path)
293+
client.TLSCerts.Path = SubstPathVars(client.TLSCerts.Path)
294+
client.TLSCerts.Client.Key.Path = SubstPathVars(client.TLSCerts.Client.Key.Path)
295+
client.TLSCerts.Client.Cert.Path = SubstPathVars(client.TLSCerts.Client.Cert.Path)
296296

297297
return &client, nil
298298
}
@@ -355,7 +355,7 @@ func (c *Config) CAServerCertPaths(org string) ([]string, error) {
355355

356356
certFileModPath := make([]string, len(certFiles))
357357
for i, v := range certFiles {
358-
certFileModPath[i] = substPathVars(v)
358+
certFileModPath[i] = SubstPathVars(v)
359359
}
360360

361361
return certFileModPath, nil
@@ -396,7 +396,7 @@ func (c *Config) CAClientKeyPath(org string) (string, error) {
396396
if _, ok := config.CertificateAuthorities[strings.ToLower(caName)]; !ok {
397397
return "", errors.Errorf("CA Server Name '%s' not found", caName)
398398
}
399-
return substPathVars(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Key.Path), nil
399+
return SubstPathVars(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Key.Path), nil
400400
}
401401

402402
// CAClientKeyPem Read configuration option for the fabric CA client key pem embedded in the client config
@@ -436,7 +436,7 @@ func (c *Config) CAClientCertPath(org string) (string, error) {
436436
if _, ok := config.CertificateAuthorities[strings.ToLower(caName)]; !ok {
437437
return "", errors.Errorf("CA Server Name '%s' not found", caName)
438438
}
439-
return substPathVars(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Cert.Path), nil
439+
return SubstPathVars(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Cert.Path), nil
440440
}
441441

442442
// CAClientCertPem Read configuration option for the fabric CA client cert pem embedded in the client config
@@ -603,7 +603,7 @@ func (c *Config) OrderersConfig() ([]core.OrdererConfig, error) {
603603
for _, orderer := range config.Orderers {
604604

605605
if orderer.TLSCACerts.Path != "" {
606-
orderer.TLSCACerts.Path = substPathVars(orderer.TLSCACerts.Path)
606+
orderer.TLSCACerts.Path = SubstPathVars(orderer.TLSCACerts.Path)
607607
} else if len(orderer.TLSCACerts.Pem) == 0 && c.configViper.GetBool("client.tlsCerts.systemCertPool") == false {
608608
errors.Errorf("Orderer has no certs configured. Make sure TLSCACerts.Pem or TLSCACerts.Path is set for %s", orderer.URL)
609609
}
@@ -650,7 +650,7 @@ func (c *Config) OrdererConfig(name string) (*core.OrdererConfig, error) {
650650
}
651651

652652
if orderer.TLSCACerts.Path != "" {
653-
orderer.TLSCACerts.Path = substPathVars(orderer.TLSCACerts.Path)
653+
orderer.TLSCACerts.Path = SubstPathVars(orderer.TLSCACerts.Path)
654654
}
655655

656656
return &orderer, nil
@@ -677,7 +677,7 @@ func (c *Config) PeersConfig(org string) ([]core.PeerConfig, error) {
677677
p = *matchingPeerConfig
678678
}
679679
if p.TLSCACerts.Path != "" {
680-
p.TLSCACerts.Path = substPathVars(p.TLSCACerts.Path)
680+
p.TLSCACerts.Path = SubstPathVars(p.TLSCACerts.Path)
681681
}
682682

683683
peers = append(peers, p)
@@ -962,7 +962,7 @@ func (c *Config) PeerConfig(org string, name string) (*core.PeerConfig, error) {
962962
}
963963

964964
if peerConfig.TLSCACerts.Path != "" {
965-
peerConfig.TLSCACerts.Path = substPathVars(peerConfig.TLSCACerts.Path)
965+
peerConfig.TLSCACerts.Path = SubstPathVars(peerConfig.TLSCACerts.Path)
966966
}
967967
return &peerConfig, nil
968968
}
@@ -983,7 +983,7 @@ func (c *Config) peerConfig(name string) (*core.PeerConfig, error) {
983983
}
984984

985985
if peerConfig.TLSCACerts.Path != "" {
986-
peerConfig.TLSCACerts.Path = substPathVars(peerConfig.TLSCACerts.Path)
986+
peerConfig.TLSCACerts.Path = SubstPathVars(peerConfig.TLSCACerts.Path)
987987
}
988988
return &peerConfig, nil
989989
}
@@ -1068,7 +1068,7 @@ func (c *Config) ChannelPeers(name string) ([]core.ChannelPeer, error) {
10681068
}
10691069

10701070
if p.TLSCACerts.Path != "" {
1071-
p.TLSCACerts.Path = substPathVars(p.TLSCACerts.Path)
1071+
p.TLSCACerts.Path = SubstPathVars(p.TLSCACerts.Path)
10721072
}
10731073

10741074
mspID, err := c.PeerMspID(peerName)
@@ -1103,7 +1103,7 @@ func (c *Config) NetworkPeers() ([]core.NetworkPeer, error) {
11031103
}
11041104

11051105
if p.TLSCACerts.Path != "" {
1106-
p.TLSCACerts.Path = substPathVars(p.TLSCACerts.Path)
1106+
p.TLSCACerts.Path = SubstPathVars(p.TLSCACerts.Path)
11071107
}
11081108

11091109
mspID, err := c.PeerMspID(name)
@@ -1244,25 +1244,25 @@ func (c *Config) SecurityProviderLabel() string {
12441244

12451245
// CredentialStorePath returns the user store path
12461246
func (c *Config) CredentialStorePath() string {
1247-
return substPathVars(c.configViper.GetString("client.credentialStore.path"))
1247+
return SubstPathVars(c.configViper.GetString("client.credentialStore.path"))
12481248
}
12491249

12501250
// KeyStorePath returns the keystore path used by BCCSP
12511251
func (c *Config) KeyStorePath() string {
1252-
keystorePath := substPathVars(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
1252+
keystorePath := SubstPathVars(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
12531253
return path.Join(keystorePath, "keystore")
12541254
}
12551255

12561256
// CAKeyStorePath returns the same path as KeyStorePath() without the
12571257
// 'keystore' directory added. This is done because the fabric-ca-client
12581258
// adds this to the path
12591259
func (c *Config) CAKeyStorePath() string {
1260-
return substPathVars(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
1260+
return SubstPathVars(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
12611261
}
12621262

12631263
// CryptoConfigPath ...
12641264
func (c *Config) CryptoConfigPath() string {
1265-
return substPathVars(c.configViper.GetString("client.cryptoconfig.path"))
1265+
return SubstPathVars(c.configViper.GetString("client.cryptoconfig.path"))
12661266
}
12671267

12681268
// TLSClientCerts loads the client's certs for mutual TLS
@@ -1323,11 +1323,11 @@ func loadByteKeyOrCertFromFile(c *core.ClientConfig, isKey bool) ([]byte, error)
13231323
var path string
13241324
a := "key"
13251325
if isKey {
1326-
path = substPathVars(c.TLSCerts.Client.Key.Path)
1326+
path = SubstPathVars(c.TLSCerts.Client.Key.Path)
13271327
c.TLSCerts.Client.Key.Path = path
13281328
} else {
13291329
a = "cert"
1330-
path = substPathVars(c.TLSCerts.Client.Cert.Path)
1330+
path = SubstPathVars(c.TLSCerts.Client.Cert.Path)
13311331
c.TLSCerts.Client.Cert.Path = path
13321332
}
13331333
bts, err := ioutil.ReadFile(path)

pkg/core/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ func teardown() {
941941
}
942942

943943
func crossCheckWithViperConfig(expected string, actual string, message string, t *testing.T) {
944-
expected = substPathVars(expected)
944+
expected = SubstPathVars(expected)
945945
if actual != expected {
946946
t.Fatalf(message)
947947
}

pkg/core/config/subst.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func goPath() string {
2424
return gps[0]
2525
}
2626

27-
// substPathVars replaces instances of '${VARNAME}' (eg ${GOPATH}) with the variable.
27+
// SubstPathVars replaces instances of '${VARNAME}' (eg ${GOPATH}) with the variable.
2828
// As a special case, $GOPATH is also replaced.
2929
// NOTE: this function currently only performs substitution when the path string starts with $
3030
// as the path variables are intended to assist with testing.
31-
func substPathVars(path string) string {
31+
func SubstPathVars(path string) string {
3232
if !strings.HasPrefix(path, "$") {
3333
return path
3434
}

pkg/core/config/subst_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func TestSubstOff(t *testing.T) {
1616
o := "foo${CRYPTOCONFIG_FIXTURES_PATH}${GOPATH}foo"
17-
s := substPathVars(o)
17+
s := SubstPathVars(o)
1818
e := "foo${CRYPTOCONFIG_FIXTURES_PATH}${GOPATH}foo"
1919

2020
if s != e {
@@ -24,7 +24,7 @@ func TestSubstOff(t *testing.T) {
2424

2525
func TestSubstCryptoConfigMiddle(t *testing.T) {
2626
o := "$foo${CRYPTOCONFIG_FIXTURES_PATH}foo"
27-
s := substPathVars(o)
27+
s := SubstPathVars(o)
2828
e := "$foo" + metadata.CryptoConfigPath + "foo"
2929

3030
if s != e {
@@ -34,7 +34,7 @@ func TestSubstCryptoConfigMiddle(t *testing.T) {
3434

3535
func TestSubstCryptoConfigPrefix(t *testing.T) {
3636
o := "$foo${CRYPTOCONFIG_FIXTURES_PATH}"
37-
s := substPathVars(o)
37+
s := SubstPathVars(o)
3838
e := "$foo" + metadata.CryptoConfigPath
3939

4040
if s != e {
@@ -43,7 +43,7 @@ func TestSubstCryptoConfigPrefix(t *testing.T) {
4343
}
4444
func TestSubstCryptoConfigWithPostfix(t *testing.T) {
4545
o := "${CRYPTOCONFIG_FIXTURES_PATH}foo"
46-
s := substPathVars(o)
46+
s := SubstPathVars(o)
4747
e := metadata.CryptoConfigPath + "foo"
4848

4949
if s != e {
@@ -53,7 +53,7 @@ func TestSubstCryptoConfigWithPostfix(t *testing.T) {
5353

5454
func TestSubstCryptoConfigOnly(t *testing.T) {
5555
o := "${CRYPTOCONFIG_FIXTURES_PATH}"
56-
s := substPathVars(o)
56+
s := SubstPathVars(o)
5757
e := metadata.CryptoConfigPath
5858

5959
if s != e {
@@ -63,7 +63,7 @@ func TestSubstCryptoConfigOnly(t *testing.T) {
6363

6464
func TestSubstAlmostVar1(t *testing.T) {
6565
o := "${FOO}"
66-
s := substPathVars(o)
66+
s := SubstPathVars(o)
6767
e := o
6868

6969
if s != e {
@@ -73,7 +73,7 @@ func TestSubstAlmostVar1(t *testing.T) {
7373

7474
func TestSubstAlmostVar2(t *testing.T) {
7575
o := "${FOO${}${}$"
76-
s := substPathVars(o)
76+
s := SubstPathVars(o)
7777
e := o
7878

7979
if s != e {
@@ -83,7 +83,7 @@ func TestSubstAlmostVar2(t *testing.T) {
8383

8484
func TestSubstNoVar(t *testing.T) {
8585
o := "foo"
86-
s := substPathVars(o)
86+
s := SubstPathVars(o)
8787
e := o
8888

8989
if s != e {
@@ -93,7 +93,7 @@ func TestSubstNoVar(t *testing.T) {
9393

9494
func TestSubstEmptyVar(t *testing.T) {
9595
o := ""
96-
s := substPathVars(o)
96+
s := SubstPathVars(o)
9797
e := o
9898

9999
if s != e {
@@ -103,7 +103,7 @@ func TestSubstEmptyVar(t *testing.T) {
103103

104104
func TestSubstGoPath1(t *testing.T) {
105105
o := "$foo${GOPATH}foo"
106-
s := substPathVars(o)
106+
s := SubstPathVars(o)
107107
e := "$foo" + goPath() + "foo"
108108

109109
if s != e {
@@ -113,7 +113,7 @@ func TestSubstGoPath1(t *testing.T) {
113113

114114
func TestSubstGoPath2(t *testing.T) {
115115
o := "$foo${GOPATH}foo"
116-
s := substPathVars(o)
116+
s := SubstPathVars(o)
117117
e := "$foo" + goPath() + "foo"
118118

119119
if s != e {
@@ -123,7 +123,7 @@ func TestSubstGoPath2(t *testing.T) {
123123

124124
func TestSubstGoPathAndVar(t *testing.T) {
125125
o := "$foo${GOPATH}foo${CRYPTOCONFIG_FIXTURES_PATH}"
126-
s := substPathVars(o)
126+
s := SubstPathVars(o)
127127
e := "$foo" + goPath() + "foo" + metadata.CryptoConfigPath
128128

129129
if s != e {
@@ -133,7 +133,7 @@ func TestSubstGoPathAndVar(t *testing.T) {
133133

134134
func TestSubstGoPathOldStyle(t *testing.T) {
135135
o := "$foo$GOPATHfoo"
136-
s := substPathVars(o)
136+
s := SubstPathVars(o)
137137
e := "$foo" + goPath() + "foo"
138138

139139
if s != e {

0 commit comments

Comments
 (0)