This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
executable file
·59 lines (51 loc) · 1.74 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
/*
Copyright Xilinx Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package fmprotocol
import (
"github.com/spf13/viper"
)
// Orgnization in config file
type Organization struct {
Name string
Certs []struct {
Role string
Cert string
}
}
// loadIdentityTable read certificates from config file and write to certificate table
func loadIdentityTable(roles []string, organizations []Organization) (errno int) {
errno = 0
role_to_id := make(map[string]int)
for role_id, role := range roles {
role_to_id[role] = role_id
}
for org_id, organization := range organizations {
user_id_record := [4]int{0, 0, 0, 0}
for _, cer := range organization.Certs {
role_id := role_to_id[cer.Role]
org_name := organization.Name
user_id := user_id_record[role_id]
cer_path := cer.Cert
installCertificateFile(cer_path, generateId(user_id, org_id, role_id), org_name)
user_id_record[role_id]++
}
}
return errno
}
// readConfig reads config file and call related functions
func readConfig() {
viper.SetConfigName("fabric_machine") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath("/etc/hyperledger/fabricmachine") // path to look for the config file in
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
logger.Errorf("Fatal error config file: %s \n", err)
return
}
roles := viper.GetStringSlice("Roles")
organizations := make([]Organization, 0)
viper.UnmarshalKey("Organizations", &organizations)
loadIdentityTable(roles, organizations)
}