forked from garetht/amanar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_flow.go
43 lines (36 loc) · 1.43 KB
/
shell_flow.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 amanar
import (
"fmt"
"log"
)
func NewShellFlow(config *ShellDatasource) (*ShellFlow, error) {
parsedFile, err := NewShellFile(config.Filepath)
if err != nil {
return nil, fmt.Errorf("could not open and parse shell file path '%s': %s", config.Filepath, err)
}
return &ShellFlow{
ShellDatasource: *config,
parsedFile: parsedFile,
}, nil
}
type ShellFlow struct {
ShellDatasource
credentials *Credentials
parsedFile *ShellFile
}
func (sf *ShellFlow) Name() string {
return "SHELL"
}
func (sf *ShellFlow) UpdateWithCredentials(credentials *Credentials) error {
log.Printf("[%s DATASOURCE] Updating parsed shell AST %s with new username %s and password %s", sf.Name(), sf.Filepath, credentials.Username, credentials.Password)
sf.parsedFile.UpdateCredentials(sf.UsernameVariable, sf.PasswordVariable, credentials)
sf.credentials = credentials
log.Printf("[%s DATASOURCE] Updated parsed shell AST %s with new username %s and password %s", sf.Name(), sf.Filepath, credentials.Username, credentials.Password)
return nil
}
func (sf *ShellFlow) PersistChanges() error {
log.Printf("[%s DATASOURCE] Writing new username %s and password %s to shell script file", sf.Name(), sf.credentials.Username, sf.credentials.Password)
sf.parsedFile.WriteToDisk()
log.Printf("[%s DATASOURCE] Successfully wrote new username %s and password %s to shell script file", sf.Name(), sf.credentials.Username, sf.credentials.Password)
return nil
}