forked from cloudfoundry/bosh-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment_validator.go
54 lines (44 loc) · 1.35 KB
/
environment_validator.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
package aws
import (
"github.com/cloudfoundry/bosh-bootloader/application"
"github.com/cloudfoundry/bosh-bootloader/bosh"
"github.com/cloudfoundry/bosh-bootloader/storage"
)
type EnvironmentValidator struct {
infrastructureManager infrastructureManager
boshClientProvider boshClientProvider
}
type infrastructureManager interface {
Exists(stackName string) (bool, error)
}
type boshClientProvider interface {
Client(directorAddress, directorUsername, directorPassword string) bosh.Client
}
func NewEnvironmentValidator(infrastructureManager infrastructureManager, boshClientProvider boshClientProvider) EnvironmentValidator {
return EnvironmentValidator{
infrastructureManager: infrastructureManager,
boshClientProvider: boshClientProvider,
}
}
func (e EnvironmentValidator) Validate(state storage.State) error {
if state.Stack.Name == "" && state.TFState == "" {
return application.BBLNotFound
}
if state.Stack.Name != "" {
stackExists, err := e.infrastructureManager.Exists(state.Stack.Name)
if err != nil {
return err
}
if !stackExists {
return application.BBLNotFound
}
}
if !state.NoDirector {
boshClient := e.boshClientProvider.Client(state.BOSH.DirectorAddress, state.BOSH.DirectorUsername, state.BOSH.DirectorPassword)
_, err := boshClient.Info()
if err != nil {
return application.BBLNotFound
}
}
return nil
}