-
Notifications
You must be signed in to change notification settings - Fork 402
/
main.go
123 lines (101 loc) · 4.07 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"github.com/spf13/cobra"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/common/fpath"
"storj.io/private/cfgstruct"
"storj.io/private/process"
"storj.io/storj/certificate"
"storj.io/storj/certificate/authorization"
"storj.io/storj/pkg/revocation"
_ "storj.io/storj/private/version" // This attaches version information during release builds.
)
var (
rootCmd = &cobra.Command{
Use: "certificates",
Short: "Certificate request signing",
}
runCmd = &cobra.Command{
Use: "run",
Short: "Run a certificate signing server",
RunE: cmdRun,
}
runCfg certificate.Config
setupCfg struct {
Overwrite bool `help:"if true ca, identity, and authorization db will be overwritten/truncated" default:"false"`
certificate.Config
}
authCfg struct {
All bool `help:"print the all authorizations for auth info/export subcommands" default:"false"`
Out string `help:"output file path for auth export subcommand; if \"-\", will use STDOUT" default:"-"`
ShowTokens bool `help:"if true, token strings will be printed for auth info command" default:"false"`
EmailsPath string `help:"optional path to a list of emails, delimited by <delimiter>, for batch processing"`
Delimiter string `help:"delimiter to split emails loaded from <emails-path> on (e.g. comma, new-line)" default:"\n"`
certificate.Config
}
claimsExportCfg struct {
Raw bool `default:"false" help:"if true, the raw data structures will be printed"`
certificate.Config
}
claimsDeleteCfg certificate.Config
confDir string
identityDir string
)
func cmdRun(cmd *cobra.Command, args []string) error {
ctx, _ := process.Ctx(cmd)
identity, err := runCfg.Identity.Load()
if err != nil {
return err
}
signer, err := runCfg.Signer.Load()
if err != nil {
return err
}
authorizationDB, err := authorization.OpenDBFromCfg(ctx, runCfg.AuthorizationDB)
if err != nil {
return errs.New("error opening authorizations database: %+v", err)
}
revocationDB, err := revocation.OpenDBFromCfg(ctx, runCfg.Server.Config)
if err != nil {
return errs.New("error creating revocation database: %+v", err)
}
defer func() {
err = errs.Combine(err, revocationDB.Close())
}()
peer, err := certificate.New(zap.L(), identity, signer, authorizationDB, revocationDB, &runCfg)
if err != nil {
return err
}
return peer.Run(ctx)
}
func main() {
defaultConfDir := fpath.ApplicationDir("storj", "cert-signing")
defaultIdentityDir := fpath.ApplicationDir("storj", "identity", "certificates")
cfgstruct.SetupFlag(zap.L(), rootCmd, &confDir, "config-dir", defaultConfDir, "main directory for certificates configuration")
cfgstruct.SetupFlag(zap.L(), rootCmd, &identityDir, "identity-dir", defaultIdentityDir, "main directory for identity credentials")
defaults := cfgstruct.DefaultsFlag(rootCmd)
rootCmd.AddCommand(authCmd)
rootCmd.AddCommand(runCmd)
rootCmd.AddCommand(setupCmd)
rootCmd.AddCommand(signCmd)
rootCmd.AddCommand(verifyCmd)
rootCmd.AddCommand(claimsCmd)
claimsCmd.AddCommand(claimsExportCmd)
claimsCmd.AddCommand(claimDeleteCmd)
authCmd.AddCommand(authCreateCmd)
authCmd.AddCommand(authInfoCmd)
authCmd.AddCommand(authExportCmd)
process.Bind(authCreateCmd, &authCfg, defaults, cfgstruct.ConfDir(confDir))
process.Bind(authInfoCmd, &authCfg, defaults, cfgstruct.ConfDir(confDir))
process.Bind(authExportCmd, &authCfg, defaults, cfgstruct.ConfDir(confDir))
process.Bind(runCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
process.Bind(setupCmd, &setupCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir), cfgstruct.SetupMode())
process.Bind(signCmd, &signCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
process.Bind(verifyCmd, &verifyCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
process.Bind(claimsExportCmd, &claimsExportCfg, defaults, cfgstruct.ConfDir(confDir))
process.Bind(claimDeleteCmd, &claimsDeleteCfg, defaults, cfgstruct.ConfDir(confDir))
process.Exec(rootCmd)
}