forked from CognitionFoundry/gohfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
79 lines (70 loc) · 1.95 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Copyright: Cognition Foundry. All Rights Reserved.
License: Apache License Version 2.0
*/
package gohfc
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
// ClientConfig holds config data for crypto, peers and orderers
type ClientConfig struct {
CryptoConfig `yaml:"crypto"`
Orderers map[string]OrdererConfig `yaml:"orderers"`
Peers map[string]PeerConfig `yaml:"peers"`
EventPeers map[string]PeerConfig `yaml:"eventPeers"`
}
// CAConfig holds config for Fabric CA
type CAConfig struct {
CryptoConfig `yaml:"crypto"`
Uri string `yaml:"url"`
SkipTLSValidation bool `yaml:"skipTLSValidation"`
MspId string `yaml:"mspId"`
}
// Config holds config values for fabric and fabric-ca cryptography
type CryptoConfig struct {
Family string `yaml:"family"`
Algorithm string `yaml:"algorithm"`
Hash string `yaml:"hash"`
}
// PeerConfig hold config values for Peer. ULR is in address:port notation
type PeerConfig struct {
Host string `yaml:"host"`
UseTLS bool `yaml:"useTLS"`
TlsPath string `yaml:"tlsPath"`
}
// OrdererConfig hold config values for Orderer. ULR is in address:port notation
type OrdererConfig struct {
Host string `yaml:"host"`
UseTLS bool `yaml:"useTLS"`
TlsPath string `yaml:"tlsPath"`
}
// NewFabricClientConfig create config from provided yaml file in path
func NewClientConfig(path string) (*ClientConfig, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
config := new(ClientConfig)
err = yaml.Unmarshal([]byte(data), config)
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
return config, nil
}
// NewCAConfig create new Fabric CA config from provided yaml file in path
func NewCAConfig(path string) (*CAConfig, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
config := new(CAConfig)
err = yaml.Unmarshal([]byte(data), config)
if err != nil {
return nil, err
}
return config, nil
}