-
Notifications
You must be signed in to change notification settings - Fork 90
/
embedded_store.go
55 lines (46 loc) · 1.47 KB
/
embedded_store.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
package kotsstore
import (
"fmt"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/persistence"
"github.com/rqlite/gorqlite"
)
func (s *KOTSStore) GetEmbeddedClusterAuthToken() (string, error) {
db := persistence.MustGetDBSession()
query := `select value from kotsadm_params where key = ?`
rows, err := db.QueryOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{"embedded.cluster.auth.token"},
})
if err != nil {
return "", fmt.Errorf("failed to query: %v: %v", err, rows.Err)
}
if !rows.Next() {
return "", ErrNotFound
}
var token string
if err := rows.Scan(&token); err != nil {
return "", errors.Wrap(err, "scan embedded cluster auth token")
}
return token, nil
}
func (s *KOTSStore) SetEmbeddedClusterAuthToken(token string) error {
db := persistence.MustGetDBSession()
query := `delete from kotsadm_params where key = ?`
wr, err := db.WriteOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{"embedded.cluster.auth.token"},
})
if err != nil {
return fmt.Errorf("delete embedded cluster auth token: %v: %v", err, wr.Err)
}
query = `insert into kotsadm_params (key, value) values (?, ?)`
wr, err = db.WriteOneParameterized(gorqlite.ParameterizedStatement{
Query: query,
Arguments: []interface{}{"embedded.cluster.auth.token", token},
})
if err != nil {
return fmt.Errorf("insert embedded cluster auth token: %v: %v", err, wr.Err)
}
return nil
}