-
Notifications
You must be signed in to change notification settings - Fork 13
/
parsing.go
92 lines (74 loc) · 2.7 KB
/
parsing.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
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2014-2017 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package configuration
import (
"github.com/bitmark-inc/bitmarkd/command/bitmark-cli/encrypt"
"github.com/bitmark-inc/bitmarkd/configuration"
"path/filepath"
)
const (
DefaultNetwork = "testing"
)
type Configuration struct {
Default_identity string `libucl:"default_identity" json:"default_identity"`
Network string `libucl:"network" json:"network"`
Connect string `libucl:"connect" json:"connect"`
Identity []encrypt.IdentityType `libucl:"identity" json:"identity"`
}
// form of configuration in the config file
// used by write.go
const configurationTemplate = `# bitmark-cli.conf -*- mode: libucl -*-
default_identity = "{{.Default_identity}}"
network = "{{.Network}}"
connect = "{{.Connect}}"
{{range .Identity}}
identity {
name = "{{.Name}}"
description = "{{.Description}}"
public_key = "{{.Public_key}}"
private_key = "{{.Private_key}}"
seed = "{{.Seed}}"
private_key_config {
salt = "{{.Private_key_config.Salt}}"
}
}
{{end}}
`
// restricted access to data (excludes private items)
type InfoIdentityType struct {
Name string `libucl:"name" json:"name"`
Description string `libucl:"description" json:"description"`
Public_key string `libucl:"public_key" json:"public_key"`
Account string `libucl:"account" json:"account"`
}
type InfoConfiguration struct {
Default_identity string `libucl:"default_identity" json:"default_identity"`
Network string `libucl:"network" json:"network"`
Connect string `libucl:"connect" json:"connect"`
Identity []InfoIdentityType `libucl:"identity" json:"identity"`
}
// full access to data (includes private data)
func GetConfiguration(configurationFileName string, variables map[string]string) (*Configuration, error) {
configurationFileName, err := filepath.Abs(filepath.Clean(configurationFileName))
if nil != err {
return nil, err
}
options := &Configuration{}
if err := configuration.ParseConfigurationFile(configurationFileName, options, variables); err != nil {
return nil, err
}
return options, nil
}
// restricted access to data (excludes private items)
func GetInfoConfiguration(configurationFileName string, variables map[string]string) (*InfoConfiguration, error) {
configurationFileName, err := filepath.Abs(filepath.Clean(configurationFileName))
if nil != err {
return nil, err
}
options := &InfoConfiguration{}
if err := configuration.ParseConfigurationFile(configurationFileName, options, variables); err != nil {
return nil, err
}
return options, nil
}