Tool to help you manage your Grafana dashboards using Git.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package config
  2. import (
  3. "io/ioutil"
  4. "gopkg.in/yaml.v2"
  5. )
  6. // Config is the Go representation of the configuration file. It is filled when
  7. // parsing the said file.
  8. type Config struct {
  9. Grafana GrafanaSettings `yaml:"grafana"`
  10. Git GitSettings `yaml:"git"`
  11. Webhook WebhookSettings `yaml:"webhook"`
  12. }
  13. // GrafanaSettings contains the data required to talk to the Grafana HTTP API.
  14. type GrafanaSettings struct {
  15. BaseURL string `yaml:"base_url"`
  16. APIKey string `yaml:"api_key"`
  17. }
  18. // GitSettings contains the data required to interact with the Git repository.
  19. type GitSettings struct {
  20. URL string `yaml:"url"`
  21. User string `yaml:"user"`
  22. PrivateKeyPath string `yaml:"private_key"`
  23. ClonePath string `yaml:"clone_path"`
  24. }
  25. // WebhookSettings contains the data required to setup the GitLab webhook.
  26. // We declare the port as a string because, although it's a number, it's only
  27. // used in a string concatenation when creating the webhook.
  28. type WebhookSettings struct {
  29. Interface string `yaml:"interface"`
  30. Port string `yaml:"port"`
  31. Path string `yaml:"path"`
  32. Secret string `yaml:"secret"`
  33. }
  34. func Load(filename string) (cfg *Config, err error) {
  35. rawCfg, err := ioutil.ReadFile(filename)
  36. if err != nil {
  37. return
  38. }
  39. cfg = new(Config)
  40. err = yaml.Unmarshal(rawCfg, cfg)
  41. return
  42. }