-
Notifications
You must be signed in to change notification settings - Fork 402
/
setup.go
62 lines (52 loc) · 1.39 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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/storj/certificate/authorization"
"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 {
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.NewDBFromCfg(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,
}))
}