2019-01-11 14:59:35 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-20 18:29:05 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
2019-01-22 12:35:48 +00:00
|
|
|
"go.uber.org/zap"
|
2018-12-20 18:29:05 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/fpath"
|
|
|
|
"storj.io/storj/pkg/certificates"
|
|
|
|
"storj.io/storj/pkg/cfgstruct"
|
2019-01-22 12:35:48 +00:00
|
|
|
"storj.io/storj/pkg/identity"
|
2018-12-20 18:29:05 +00:00
|
|
|
"storj.io/storj/pkg/process"
|
2019-01-02 10:23:25 +00:00
|
|
|
"storj.io/storj/pkg/server"
|
2018-12-20 18:29:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type batchCfg struct {
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
rootCmd = &cobra.Command{
|
|
|
|
Use: "certificates",
|
|
|
|
Short: "Certificate request signing",
|
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = &cobra.Command{
|
|
|
|
Use: "run",
|
|
|
|
Short: "Run a certificate signing server",
|
|
|
|
RunE: cmdRun,
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:35:48 +00:00
|
|
|
config struct {
|
|
|
|
batchCfg
|
2019-01-25 14:54:54 +00:00
|
|
|
CA identity.CASetupConfig
|
|
|
|
Identity identity.SetupConfig
|
|
|
|
Server struct { // workaround server.Config change
|
|
|
|
Identity identity.Config
|
|
|
|
server.Config
|
|
|
|
}
|
2019-01-22 12:35:48 +00:00
|
|
|
Signer certificates.CertServerConfig
|
|
|
|
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"`
|
|
|
|
Overwrite bool `default:"false" help:"if true ca, identity, and authorization db will be overwritten/truncated"`
|
2018-12-20 18:29:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 12:51:06 +00:00
|
|
|
confDir string
|
|
|
|
identityDir string
|
2018-12-20 18:29:05 +00:00
|
|
|
)
|
|
|
|
|
2019-02-06 16:40:55 +00:00
|
|
|
func cmdRun(cmd *cobra.Command, args []string) error {
|
|
|
|
ctx := process.Ctx(cmd)
|
|
|
|
|
|
|
|
identity, err := config.Server.Identity.Load()
|
|
|
|
if err != nil {
|
|
|
|
zap.S().Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.Server.Run(ctx, identity, nil, config.Signer)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-03-12 12:51:06 +00:00
|
|
|
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", fpath.ApplicationDir("storj", "identity", "bootstrap"), "main directory for bootstrap identity credentials")
|
2019-01-22 12:35:48 +00:00
|
|
|
rootCmd.PersistentFlags().StringVar(&identityDir, "identity-dir", defaultIdentityDir, "main directory for storagenode identity credentials")
|
2019-04-19 19:17:30 +01:00
|
|
|
defaults := cfgstruct.DefaultsFlag(rootCmd)
|
2019-01-04 17:23:23 +00:00
|
|
|
|
2019-02-06 16:40:55 +00:00
|
|
|
rootCmd.AddCommand(authCmd)
|
2019-01-04 17:23:23 +00:00
|
|
|
rootCmd.AddCommand(runCmd)
|
2019-02-06 16:40:55 +00:00
|
|
|
rootCmd.AddCommand(setupCmd)
|
|
|
|
rootCmd.AddCommand(signCmd)
|
|
|
|
rootCmd.AddCommand(verifyCmd)
|
2019-02-26 08:55:52 +00:00
|
|
|
rootCmd.AddCommand(claimsCmd)
|
|
|
|
claimsCmd.AddCommand(claimsExportCmd)
|
|
|
|
claimsCmd.AddCommand(claimDeleteCmd)
|
2019-02-06 16:40:55 +00:00
|
|
|
authCmd.AddCommand(authCreateCmd)
|
|
|
|
authCmd.AddCommand(authInfoCmd)
|
|
|
|
authCmd.AddCommand(authExportCmd)
|
2019-01-25 14:54:54 +00:00
|
|
|
|
2019-04-19 19:17:30 +01:00
|
|
|
cfgstruct.Bind(authCreateCmd.Flags(), &config, defaults, cfgstruct.ConfDir(confDir))
|
|
|
|
cfgstruct.Bind(authInfoCmd.Flags(), &config, defaults, cfgstruct.ConfDir(confDir))
|
|
|
|
cfgstruct.Bind(authExportCmd.Flags(), &config, defaults, cfgstruct.ConfDir(confDir))
|
|
|
|
cfgstruct.Bind(runCmd.Flags(), &config, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
|
|
|
cfgstruct.BindSetup(setupCmd.Flags(), &config, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
|
|
|
cfgstruct.Bind(signCmd.Flags(), &signCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
|
|
|
cfgstruct.Bind(verifyCmd.Flags(), &verifyCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
|
|
|
cfgstruct.Bind(claimsExportCmd.Flags(), &claimsExportCfg, defaults, cfgstruct.ConfDir(confDir))
|
|
|
|
cfgstruct.Bind(claimDeleteCmd.Flags(), &claimsDeleteCfg, defaults, cfgstruct.ConfDir(confDir))
|
2018-12-20 18:29:05 +00:00
|
|
|
|
|
|
|
process.Exec(rootCmd)
|
|
|
|
}
|