2018-08-27 23:23:48 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/cfgstruct"
|
2018-08-28 16:00:18 +01:00
|
|
|
"storj.io/storj/pkg/provider"
|
2018-08-27 23:23:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
idCmd = &cobra.Command{
|
2018-08-28 16:00:18 +01:00
|
|
|
Use: "id",
|
2018-08-27 23:23:48 +01:00
|
|
|
Short: "Manage identities",
|
|
|
|
}
|
|
|
|
|
|
|
|
newIDCmd = &cobra.Command{
|
|
|
|
Use: "new",
|
|
|
|
Short: "Creates a new identity from an existing certificate authority",
|
|
|
|
RunE: cmdNewID,
|
|
|
|
}
|
|
|
|
|
|
|
|
newIDCfg struct {
|
|
|
|
CA provider.FullCAConfig
|
|
|
|
Identity provider.IdentitySetupConfig
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(idCmd)
|
|
|
|
idCmd.AddCommand(newIDCmd)
|
|
|
|
cfgstruct.Bind(newIDCmd.Flags(), &newIDCfg, cfgstruct.ConfDir(defaultConfDir))
|
|
|
|
}
|
|
|
|
|
|
|
|
func cmdNewID(cmd *cobra.Command, args []string) (err error) {
|
|
|
|
ca, err := newIDCfg.CA.Load()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s := newIDCfg.Identity.Stat()
|
|
|
|
if s == provider.NoCertNoKey || newIDCfg.Identity.Overwrite {
|
|
|
|
_, err := newIDCfg.Identity.Create(ca)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return provider.ErrSetup.New("identity file(s) exist: %s", s)
|
|
|
|
}
|