-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
47 lines (41 loc) · 1.19 KB
/
factory.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package factory
import (
"context"
"github.com/hyperledger/fabric-ca/lib/server/db"
"github.com/hyperledger/fabric-ca/lib/server/db/mysql"
"github.com/hyperledger/fabric-ca/lib/server/db/postgres"
"github.com/hyperledger/fabric-ca/lib/server/db/sqlite"
"github.com/hyperledger/fabric-ca/lib/tls"
"github.com/hyperledger/fabric/bccsp"
"github.com/pkg/errors"
)
// DB is interface that defines the functions on a database
type DB interface {
Connect() error
PingContext(ctx context.Context) error
Create() (*db.DB, error)
}
// New returns a DB interface for the request database type
func New(
dbType,
datasource,
caName string,
tlsConfig *tls.ClientTLSConfig,
csp bccsp.BCCSP,
metrics *db.Metrics,
) (DB, error) {
switch dbType {
case "sqlite3":
return sqlite.NewDB(datasource, caName, metrics), nil
case "postgres":
return postgres.NewDB(datasource, caName, tlsConfig, metrics), nil
case "mysql":
return mysql.NewDB(datasource, caName, tlsConfig, csp, metrics), nil
default:
return nil, errors.Errorf("Invalid db.type in config file: '%s'; must be 'sqlite3', 'postgres', or 'mysql'", dbType)
}
}