-
Notifications
You must be signed in to change notification settings - Fork 23
/
sanity_checks.go
59 lines (42 loc) · 1.65 KB
/
sanity_checks.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
package main
import (
"errors"
"fmt"
"os"
"github.com/mdevilliers/redishappy/configuration"
"github.com/mdevilliers/redishappy/util"
)
type HAProxyConfigContainsRequiredSections struct{}
func (c *HAProxyConfigContainsRequiredSections) Check(config configuration.Configuration) (bool, error) {
if config.HAProxy.TemplatePath == "" {
return false, errors.New("Configuration doesn't contain a 'HAProxy.TemplatePath' configuration.")
}
if config.HAProxy.OutputPath == "" {
return false, errors.New("Configuration doesn't contain a 'HAProxy.OutputPath' configuration.")
}
if config.HAProxy.ReloadCommand == "" {
return false, errors.New("Configuration doesn't contain a 'HAProxy.ReloadCommand' configuration.")
}
return true, nil
}
type CheckPermissionToWriteToHAProxyConfigFile struct{}
func (c *CheckPermissionToWriteToHAProxyConfigFile) Check(config configuration.Configuration) (bool, error) {
file, err := os.OpenFile(config.HAProxy.OutputPath, os.O_RDWR|os.O_APPEND, 0660)
defer file.Close()
if err != nil {
return false, fmt.Errorf("Configuration file at %s is not able to be opened.", config.HAProxy.OutputPath)
}
_, err = file.Write([]byte{' '})
if err != nil {
return false, fmt.Errorf("Configuration file at %s : error writing a empty byte.", config.HAProxy.OutputPath)
}
return true, nil
}
type CheckHAProxyTemplateFileExists struct{}
func (c *CheckHAProxyTemplateFileExists) Check(config configuration.Configuration) (bool, error) {
exists := util.FileExists(config.HAProxy.TemplatePath)
if exists {
return true, nil
}
return false, fmt.Errorf("HAProxy Template file at %s : does not exist.", config.HAProxy.TemplatePath)
}