This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
114 lines (99 loc) · 2.13 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import "C"
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/jmoiron/sqlx"
"github.com/ory/fosite"
"github.com/ory/hydra/client"
"github.com/ory/hydra/jwk"
"github.com/ory/hydra/pkg"
"github.com/ory/hydra/warden/group"
"github.com/ory/ladon"
"github.com/pkg/errors"
_ "gopkg.in/rana/ora.v4"
)
func main() {
Execute()
}
func Connect(u string) (*sqlx.DB, error) {
host, database := GetDatabase(u)
db, err := sqlx.Open("ora", host)
if err != nil {
return nil, errors.WithStack(err)
}
if err := db.Ping(); err != nil {
return nil, errors.WithStack(err)
}
if _, err := db.Exec(fmt.Sprintf("ALTER SESSION SET CURRENT_SCHEMA = %s", database)); err != nil {
return nil, errors.WithStack(err)
}
return db, nil
}
func NewClientManager(db *sqlx.DB, hasher fosite.Hasher) client.Manager {
return &ClientManager{
DB: db,
Hasher: hasher,
Table: "hyd_clt",
}
}
func NewGroupManager(db *sqlx.DB) group.Manager {
return &GroupManager{
DB: db,
Table: "hyd_grp",
}
}
func NewJWKManager(db *sqlx.DB, cipher *jwk.AEAD) jwk.Manager {
return &JWKManager{
DB: db,
Cipher: cipher,
Table: "hyd_jwk",
}
}
func NewOAuth2Manager(db *sqlx.DB, cm client.Manager, logger logrus.FieldLogger) pkg.FositeStorer {
return &FositeStore{
Manager: cm,
DB: db,
L: logger,
Table: "hyd_oa2",
}
}
func NewPolicyManager(db *sqlx.DB) ladon.Manager {
return &PolicyManager{
DB: db,
Table: "hyd_pol",
}
}
func CreateSchemas(db *sqlx.DB) error {
if _, err := (&ClientManager{
DB: db,
Table: "hyd_clt",
}).CreateSchemas(); err != nil {
return errors.WithStack(err)
}
if _, err := (&GroupManager{
DB: db,
Table: "hyd_grp",
}).CreateSchemas(); err != nil {
return errors.WithStack(err)
}
if _, err := (&JWKManager{
DB: db,
Table: "hyd_jwk",
}).CreateSchemas(); err != nil {
return errors.WithStack(err)
}
if _, err := (&FositeStore{
DB: db,
Table: "hyd_oa2",
}).CreateSchemas(); err != nil {
return errors.WithStack(err)
}
if _, err := (&PolicyManager{
DB: db,
Table: "hyd_pol",
}).CreateSchemas(); err != nil {
return errors.WithStack(err)
}
return nil
}