Skip to content

Commit

Permalink
Adds the possibility to use env key for data folder and config file
Browse files Browse the repository at this point in the history
  • Loading branch information
nkcr committed Apr 9, 2021
1 parent 2d322e9 commit 3d4ded9
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cmd/grpc/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import (
_ "google.golang.org/grpc/encoding/gzip"
)

const (
configEnvKey = "VPIR_CONFIG"
dataEnvKey = "VPIR_SKS_ROOT"

defaultConfigFile = "config.toml"
defaultSksPath = "data"
)

func main() {
// flags
sid := flag.Int("id", -1, "Server ID")
Expand Down Expand Up @@ -71,7 +79,12 @@ func main() {
}

// configs
config, err := utils.LoadConfig("config.toml")
configPath := os.Getenv(configEnvKey)
if configPath == "" {
configPath = defaultConfigFile
}

config, err := utils.LoadConfig(configPath)
if err != nil {
log.Fatalf("could not load the server config file: %v", err)
}
Expand All @@ -96,7 +109,7 @@ func main() {
log.Fatalf("impossible to construct real keys db: %v", err)
}
default:
log.Fatal("unknow vpir scheme")
log.Fatal("unknown vpir scheme")
}

// GC after db creation
Expand Down Expand Up @@ -209,7 +222,12 @@ func (s *vpirServer) Query(ctx context.Context, qr *proto.QueryRequest) (

func loadPgpDB(filesNumber int, rebalanced bool) (*database.DB, error) {
log.Println("Starting to read in the DB data")
sksDir := filepath.Join("data", pgp.SksParsedFolder)

sksDir := os.Getenv(dataEnvKey)
if sksDir == "" {
sksDir = filepath.Join(defaultSksPath, pgp.SksParsedFolder)
}

files, err := pgp.GetAllFiles(sksDir)
if err != nil {
return nil, err
Expand Down

0 comments on commit 3d4ded9

Please sign in to comment.