...

Source file src/github.com/sigstore/rekor/pkg/indexstorage/indexstorage.go

Documentation: github.com/sigstore/rekor/pkg/indexstorage

     1  // Copyright 2023 The Sigstore Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    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) // Returns indices for specified keys
    28  	WriteIndex(context.Context, []string, string) error        // Writes index for specified keys
    29  	Shutdown() error                                           // Method to run on shutdown
    30  }
    31  
    32  // NewIndexStorage instantiates a new IndexStorage provider based on the requested type
    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