storj/cmd/certificates/setup.go
Egon Elbre 096445bc1c certificate/authorization: add ctx to OpenDB
Database opening usually dial and hence we should pass ctx to them.

Change-Id: I1362783568f66383c46f07be7549327bb1aaa39e
2020-10-29 09:46:23 +02:00

65 lines
1.4 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"storj.io/common/fpath"
"storj.io/private/process"
"storj.io/storj/certificate/authorization"
)
var (
setupCmd = &cobra.Command{
Use: "setup",
Short: "Setup a certificate signing server",
RunE: cmdSetup,
Annotations: map[string]string{"type": "setup"},
}
)
func cmdSetup(cmd *cobra.Command, args []string) error {
ctx, _ := process.Ctx(cmd)
setupDir, err := filepath.Abs(confDir)
if err != nil {
return err
}
err = os.MkdirAll(setupDir, 0700)
if err != nil {
return err
}
valid, err := fpath.IsValidSetupDir(setupDir)
if err != nil {
return err
}
if !setupCfg.Overwrite && !valid {
fmt.Printf("certificate signer configuration already exists (%v). rerun with --overwrite\n", setupDir)
return nil
}
authorizationDB, err := authorization.OpenDBFromCfg(ctx, setupCfg.Config.AuthorizationDB)
if err != nil {
return err
}
if err := authorizationDB.Close(); err != nil {
return err
}
return process.SaveConfig(cmd, filepath.Join(setupDir, "config.yaml"),
process.SaveConfigWithOverrides(map[string]interface{}{
"signer.cert-path": setupCfg.Signer.CertPath,
"signer.key-path": setupCfg.Signer.KeyPath,
"identity.cert-path": setupCfg.Identity.CertPath,
"identity.key-path": setupCfg.Identity.KeyPath,
}))
}