Last active
October 30, 2016 14:19
-
-
Save nl5887/7c219c822ce6c4dac11f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package honeycast | |
| import ( | |
| "io/ioutil" | |
| "regexp" | |
| "github.com/imdario/mergo" | |
| "gopkg.in/yaml.v2" | |
| ) | |
| type ( | |
| Config struct { | |
| Token string `yaml:"token"` | |
| Template string `yaml:"template"` | |
| Proxies ProxiesConfig `yaml:"proxies"` | |
| } | |
| ) | |
| type ProxiesConfig struct { | |
| SSH SSHProxyConfig `yaml:"ssh"` | |
| HTTP HTTPProxyConfig `yaml:"http"` | |
| } | |
| type HTTPProxyConfig struct { | |
| Port string `yaml:"port"` | |
| } | |
| type SSHProxyConfig struct { | |
| Key string `yaml:"key"` | |
| Port string `yaml:"port"` | |
| Banner string `yaml:"banner"` | |
| } | |
| func (pc *SSHProxyConfig) PrivateKey() (ssh.Signer, error) { | |
| b, err := ioutil.ReadFile(pc.Key) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return ssh.ParsePrivateKey(b) | |
| } | |
| var DefaultConfig = Config{ | |
| Token: "token", | |
| Template: "c1", | |
| Proxies: ProxiesConfig{ | |
| HTTP: HTTPProxyConfig{ | |
| Port: ":8020", | |
| }, | |
| SSH: SSHProxyConfig{ | |
| Key: "./perms/id_rsa.key", | |
| Port: ":8022", | |
| }, | |
| }, | |
| } | |
| func NewConfig() (*Config, error) { | |
| c := DefaultConfig | |
| return &c, nil | |
| } | |
| func (c *Config) Load(file string) error { | |
| data, err := ioutil.ReadFile(file) | |
| if err != nil { | |
| return err | |
| } | |
| conf := Config{} | |
| err = yaml.Unmarshal(data, &conf) | |
| if err != nil { | |
| return err | |
| } | |
| return mergo.MergeWithOverwrite(c, conf) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template: "test" | |
| token: test | |
| proxies: | |
| http: | |
| port: :8080 | |
| ssh: | |
| port: :8022 | |
| key: "./perm/perms" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| config, err := NewConfig() | |
| if err != nil { | |
| fmt.Fprintf(os.Stdout, err.Error()) | |
| return | |
| } | |
| if err := config.Load("config.yaml"); err != nil { | |
| fmt.Fprintf(os.Stdout, err.Error()) | |
| return | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment