forked from cloudfoundry/bosh-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh_key_deleter.go
43 lines (37 loc) · 1007 Bytes
/
ssh_key_deleter.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
package bosh
import (
"fmt"
"github.com/cloudfoundry/bosh-bootloader/storage"
yaml "gopkg.in/yaml.v2"
)
type SSHKeyDeleter struct {
}
func NewSSHKeyDeleter() SSHKeyDeleter {
return SSHKeyDeleter{}
}
func (SSHKeyDeleter) Delete(state storage.State) (storage.State, error) {
var err error
state.Jumpbox.Variables, err = deleteJumpboxSSHKey(state.Jumpbox.Variables)
if err != nil {
return storage.State{}, fmt.Errorf("Jumpbox variables: %s", err)
}
state.BOSH.Variables, err = deleteJumpboxSSHKey(state.BOSH.Variables)
if err != nil {
return storage.State{}, fmt.Errorf("BOSH variables: %s", err)
}
state.KeyPair = storage.KeyPair{}
return state, nil
}
func deleteJumpboxSSHKey(varsString string) (string, error) {
vars := make(map[string]interface{})
err := yaml.Unmarshal([]byte(varsString), &vars)
if err != nil {
return "", err
}
delete(vars, "jumpbox_ssh")
newVars, err := yaml.Marshal(vars)
if err != nil {
return "", err // not tested
}
return string(newVars), nil
}