forked from garetht/amanar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postico_flow.go
64 lines (53 loc) · 1.68 KB
/
postico_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
62
63
64
package amanar
import (
"fmt"
"log"
)
func NewPosticoFlow(config *PosticoDatasource) (*PosticoFlow, error) {
database, err := NewPosticoSQLiteDatabase(config.PosticoSqlitePath)
if err != nil {
return nil, err
}
return &PosticoFlow{
PosticoDatasource: *config,
database: database,
}, nil
}
type PosticoFlow struct {
PosticoDatasource
database *PosticoSQLiteDatabase
credentials *Credentials
}
func (pf *PosticoFlow) Name() string {
return "POSTICO"
}
func (pf *PosticoFlow) UpdateWithCredentials(credentials *Credentials) error {
pf.credentials = credentials
return nil
}
func (pf *PosticoFlow) PersistChanges() (err error) {
err = pf.database.UpdateUsername(pf.DatabaseUUID, pf.credentials.Username)
if err != nil {
return
}
uuidRow, err := pf.database.GetFavoriteFromUUID(pf.DatabaseUUID)
if err != nil {
return
}
var host string
if uuidRow.Host.Valid {
host = uuidRow.Host.String
}
service := fmt.Sprintf("postgresql://%s", host)
log.Printf("[%s DATASOURCE %s] Writing new username %s and password %s to Keychain", pf.Name(), service, pf.credentials.Username, pf.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, pf.credentials.Username, pf.credentials.Password, []string{})
if err != nil {
log.Print(err)
log.Fatalf("[%s DATASOURCE %s] Could not create the new keychain entry with username %s and password %s", pf.Name(), service, pf.credentials.Username, pf.credentials.Password)
return
}
return nil
}