forked from cloudfoundry/bosh-bootloader
/
rotate.go
52 lines (42 loc) · 1 KB
/
rotate.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
package commands
import (
"fmt"
"github.com/cloudfoundry/bosh-bootloader/storage"
)
type sshKeyDeleter interface {
Delete() error
}
type Rotate struct {
stateValidator stateValidator
sshKeyDeleter sshKeyDeleter
up up
}
func NewRotate(stateValidator stateValidator, sshKeyDeleter sshKeyDeleter, up up) Rotate {
return Rotate{
stateValidator: stateValidator,
sshKeyDeleter: sshKeyDeleter,
up: up,
}
}
func (r Rotate) CheckFastFails(subcommandFlags []string, state storage.State) error {
err := r.stateValidator.Validate()
if err != nil {
return fmt.Errorf("validate state: %s", err)
}
err = r.up.CheckFastFails(subcommandFlags, state)
if err != nil {
return fmt.Errorf("up: %s", err)
}
return nil
}
func (r Rotate) Execute(args []string, state storage.State) error {
err := r.sshKeyDeleter.Delete()
if err != nil {
return fmt.Errorf("delete ssh key: %s", err)
}
err = r.up.Execute(args, state)
if err != nil {
return fmt.Errorf("up: %s", err)
}
return nil
}