forked from garetht/amanar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_flow.go
44 lines (37 loc) · 1.39 KB
/
template_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
44
package amanar
import (
"fmt"
"io"
"log"
)
func NewTemplateFlow(config *TemplateDatasource, writer io.Writer) (*TemplateFlow, error) {
source, err := NewTemplateSource(config, writer)
if err != nil {
return nil, fmt.Errorf("could not create template flow from template datasource: %s", err)
}
return &TemplateFlow{
source: source,
}, nil
}
type TemplateFlow struct {
credentials *Credentials
source *TemplateSource
}
func (tf *TemplateFlow) Name() string {
return "TEMPLATE FLOW"
}
func (tf *TemplateFlow) UpdateWithCredentials(credentials *Credentials) error {
log.Printf("[%s DATASOURCE] Updating template flow with new username %s and password %s", tf.Name(), credentials.Username, credentials.Password)
tf.credentials = credentials
log.Printf("[%s DATASOURCE] Updated template flow with new username %s and password %s", tf.Name(), credentials.Username, credentials.Password)
return nil
}
func (tf *TemplateFlow) PersistChanges() error {
log.Printf("[%s DATASOURCE] Writing new username %s and password %s to template in stdout", tf.Name(), tf.credentials.Username, tf.credentials.Password)
// prints to the configured Writer
if err := tf.source.WriteToDisk(*tf.credentials); err != nil {
return err
}
log.Printf("[%s DATASOURCE] Successfully wrote new username %s and password %s to template in stdout", tf.Name(), tf.credentials.Username, tf.credentials.Password)
return nil
}