-
Notifications
You must be signed in to change notification settings - Fork 28
/
config.go
executable file
·56 lines (46 loc) · 2.07 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
package main
import (
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type SSHConfig struct {
Global SSHConfigGlobal `yaml:"global"`
Servers map[string]SSHConfigServer `yaml:"servers"`
ACLs map[string]SSHConfigACL `yaml:"acls"`
Users map[string]SSHConfigUser `yaml:"users"`
}
type SSHConfigGlobal struct {
MOTDPath string `yaml:"motd_path"`
LogPath string `yaml:"log_path"`
HostKeyPaths []string `yaml:"host_keys"`
AuthType string `yaml:"auth_type"`
LDAP_Server string `yaml:"ldap_server"`
LDAP_Domain string `yaml:"ldap_domain"`
PassPassword bool `yaml:"pass_password"`
ListenPath string `yaml:"listen_path"`
}
type SSHConfigServer struct {
HostPubKeyFiles []string `yaml:"host_pubkeys"`
ConnectPath string `yaml:"connect_path"`
LoginUser string `yaml:"login_user"`
}
type SSHConfigACL struct {
AllowedServers []string `yaml:"allow_list"`
}
type SSHConfigUser struct {
ACL string `yaml:"acl"`
AuthorizedKeysFile string `yaml:"authorized_keys_file"`
}
func fetchConfig(filename string) (*SSHConfig, error) {
configData, err := ioutil.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("Failed to open config file: %s", err)
}
config := &SSHConfig{}
err = yaml.Unmarshal(configData, config)
if err != nil {
return nil, fmt.Errorf("Unable to parse YAML config file: %s", err)
}
return config, nil
}