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"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/fpath"
|
|
|
|
"storj.io/storj/pkg/process"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-05 15:56:57 +01:00
|
|
|
if setupCfg.Overwrite {
|
|
|
|
setupCfg.Signer.Overwrite = true
|
2019-01-11 14:59:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 15:56:57 +01:00
|
|
|
if _, err := setupCfg.Signer.NewAuthDB(); 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 15:56:57 +01:00
|
|
|
"ca.cert-path": setupCfg.Signer.CA.CertPath,
|
|
|
|
"ca.key-path": setupCfg.Signer.CA.KeyPath,
|
|
|
|
"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
|
|
|
}
|