2019-01-11 14:59:35 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-09-26 17:11:05 +01:00
|
|
|
"storj.io/storj/certificate/authorization"
|
2019-01-11 14:59:35 +00:00
|
|
|
"storj.io/storj/pkg/process"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/fpath"
|
2019-01-11 14:59:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2019-01-22 12:35:48 +00:00
|
|
|
setupDir, err := filepath.Abs(confDir)
|
2019-01-11 14:59:35 +00:00
|
|
|
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
|
|
|
|
}
|
2019-09-05 15:56:57 +01:00
|
|
|
if !setupCfg.Overwrite && !valid {
|
2019-01-11 14:59:35 +00:00
|
|
|
fmt.Printf("certificate signer configuration already exists (%v). rerun with --overwrite\n", setupDir)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-11 09:36:44 +01:00
|
|
|
authorizationDB, err := authorization.NewDBFromCfg(setupCfg.Config.AuthorizationDB)
|
2019-09-05 16:11:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-01-11 14:59:35 +00:00
|
|
|
}
|
2019-09-05 16:11:21 +01:00
|
|
|
if err := authorizationDB.Close(); err != nil {
|
2019-01-11 14:59:35 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:01:20 +01:00
|
|
|
return process.SaveConfig(cmd, filepath.Join(setupDir, "config.yaml"),
|
|
|
|
process.SaveConfigWithOverrides(map[string]interface{}{
|
2019-09-05 16:11:21 +01:00
|
|
|
"signer.cert-path": setupCfg.Signer.CertPath,
|
|
|
|
"signer.key-path": setupCfg.Signer.KeyPath,
|
2019-09-05 15:56:57 +01:00
|
|
|
"identity.cert-path": setupCfg.Identity.CertPath,
|
|
|
|
"identity.key-path": setupCfg.Identity.KeyPath,
|
2019-08-05 18:01:20 +01:00
|
|
|
}))
|
2019-01-11 14:59:35 +00:00
|
|
|
}
|