...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package indexstorage
16
17 import (
18 "context"
19 "fmt"
20
21 "github.com/sigstore/rekor/pkg/indexstorage/mysql"
22 "github.com/sigstore/rekor/pkg/indexstorage/redis"
23 "github.com/spf13/viper"
24 )
25
26 type IndexStorage interface {
27 LookupIndices(context.Context, []string) ([]string, error)
28 WriteIndex(context.Context, []string, string) error
29 Shutdown() error
30 }
31
32
33 func NewIndexStorage(providerType string) (IndexStorage, error) {
34 switch providerType {
35 case redis.ProviderType:
36 return redis.NewProvider(viper.GetString("redis_server.address"), viper.GetString("redis_server.port"), viper.GetString("redis_server.password"), viper.GetBool("redis_server.enable-tls"), viper.GetBool("redis_server.insecure-skip-verify"))
37 case mysql.ProviderType:
38 return mysql.NewProvider(viper.GetString("search_index.mysql.dsn"),
39 mysql.WithConnMaxIdleTime(viper.GetDuration("search_index.mysql.conn_max_idletime")),
40 mysql.WithConnMaxLifetime(viper.GetDuration("search_index.mysql.conn_max_lifetime")),
41 mysql.WithMaxIdleConns(viper.GetInt("search_index.mysql.max_idle_connections")),
42 mysql.WithMaxOpenConns(viper.GetInt("search_index.mysql.max_open_connections")))
43 default:
44 return nil, fmt.Errorf("invalid index storage provider type: %v", providerType)
45 }
46 }
47
View as plain text