root.go 3.17 KB
Newer Older
1
// Package cmd handles flags and commands management.
ElyKar's avatar
ElyKar committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
package cmd

import (
	"dfss"
	dapi "dfss/dfssd/api"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

// RootCmd is the main command for the dfssp application
var RootCmd = &cobra.Command{
	Use:   "dfssp",
	Short: "Platform for the DFSS protocol",
	Long: "Platform v " + dfss.Version + ` for the
Distributed Fair Signing System project

Users and Contracts manager`,
	Run: func(cmd *cobra.Command, args []string) {
		_ = cmd.Help()
	},
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
23
		dapi.Configure(viper.GetBool("verbose"), viper.GetString("demo") != "", viper.GetString("demo"), "platform")
ElyKar's avatar
ElyKar committed
24 25 26 27 28 29 30 31 32 33 34
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {
		dapi.DClose()
	},
}

func init() {
	// Add flags to dfssp
	RootCmd.PersistentFlags().BoolP("verbose", "v", false, "print verbose messages")
	RootCmd.PersistentFlags().StringP("demo", "d", "", "demonstrator address and port, let empty for no debug")
	RootCmd.PersistentFlags().String("path", ".", "path to get the platform's private key and root certificate")
35 36 37 38 39 40 41 42 43 44 45 46 47 48

	initCmd.Flags().String("cn", "dfssp", "common name for the root certificate")
	initCmd.Flags().IntP("validity", "r", 365, "validity duration for the root certificate (days)")
	initCmd.Flags().String("country", "FR", "country for the root certificate")
	initCmd.Flags().String("org", "DFSS", "organization for the root certificate")
	initCmd.Flags().String("unit", "INSA Rennes", "organizational unit for the root certificate")
	initCmd.Flags().IntP("key", "k", 2048, "encoding size for the private key of the platform")

	ttpCmd.Flags().String("cn", "ttp", "common name for the ttp certificate")
	ttpCmd.Flags().IntP("validity", "c", 365, "validity duration for the ttp certificate (days)")
	ttpCmd.Flags().String("country", "FR", "country for the ttp certificate")
	ttpCmd.Flags().String("org", "DFSS", "organization for the ttp certificate")
	ttpCmd.Flags().String("unit", "INSA Rennes", "organizational unit for the ttp certificate")
	ttpCmd.Flags().IntP("key", "k", 2048, "encoding size for the private key of the ttp")
49 50
	ttpCmd.Flags().StringP("ttps", "t", "ttps", "file containing available TTPs list")
	ttpCmd.Flags().StringP("addr", "a", "localhost:9098", "address of the ttp to be transmitted to signers")
51 52 53 54 55

	startCmd.Flags().IntP("validity", "c", 365, "validity duration for the child certificates (days)")
	startCmd.Flags().StringP("address", "a", "0.0.0.0", "address to bind for listening")
	startCmd.Flags().StringP("port", "p", "9000", "port to bind for listening")
	startCmd.Flags().String("db", "mongodb://localhost/dfss", "server url in standard MongoDB format for accessing database")
56
	startCmd.Flags().StringP("ttps", "t", "", "file containing available TTPs list, disabled by default")
ElyKar's avatar
ElyKar committed
57 58 59 60 61 62 63 64 65 66

	// Bind viper to flags
	_ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
	_ = viper.BindPFlag("demo", RootCmd.PersistentFlags().Lookup("demo"))
	_ = viper.BindPFlag("path", RootCmd.PersistentFlags().Lookup("path"))

	viper.SetDefault("pkey_filename", "dfssp_pkey.pem")
	viper.SetDefault("ca_filename", "dfssp_rootCA.pem")

	// Register subcommands here
67
	RootCmd.AddCommand(dfss.VersionCmd, ttpCmd, initCmd, startCmd)
ElyKar's avatar
ElyKar committed
68
}