forked from garetht/amanar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
querious2_flow.go
61 lines (49 loc) · 1.63 KB
/
querious2_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package amanar
import (
"fmt"
"log"
"errors"
)
func NewQuerious2Flow(config *Querious2Datasource) (*Querious2Flow, error) {
database, err := NewQuerious2SQLiteDatabase(config.Querious2SqlitePath)
if err != nil {
return nil, err
}
return &Querious2Flow{
Querious2Datasource: *config,
database: database,
}, nil
}
type Querious2Flow struct {
Querious2Datasource
database *Querious2SQLiteDatabase
credentials *Credentials
}
func (qf *Querious2Flow) Name() string {
return "QUERIOUS 2"
}
func (qf *Querious2Flow) UpdateWithCredentials(credentials *Credentials) error {
qf.credentials = credentials
return nil
}
func (qf *Querious2Flow) PersistChanges() (err error) {
if qf.credentials == nil {
return errors.New("Please provide credentials to update")
}
err = qf.database.UpdateUsername(qf.DatabaseUUID, qf.credentials.Username)
if err != nil {
return
}
service := fmt.Sprintf("MySQL %s", qf.DatabaseUUID)
log.Printf("[QUERIOUS2 DATASOURCE %s] Writing new username %s and password %s to Keychain", service, qf.credentials.Username, qf.credentials.Password)
// Querious 2 finds its item in the keychain based a hashlike combination of the keychain filepath,
// account, and service. We therefore do not alter any of these things./
// (connection_settings.keychainItemRefMySQL)
err = CreateOrUpdateKeychainEntriesForService(service, "", qf.credentials.Password, []string{})
if err != nil {
log.Print(err)
log.Fatalf("[QUERIOUS2 DATASOURCE %s] Could not create the new keychain entry with username %s and password %s", service, qf.credentials.Username, qf.credentials.Password)
return
}
return nil
}