Commit aed14c50 authored by Loïck Bonniot's avatar Loïck Bonniot

Improve viper and cobra integration

- Add sub-commands flags
- Factorize version commands
- Fix import format
- Fix GUI
parent 96ca0646
Pipeline #827 passed with stage
......@@ -15,8 +15,9 @@ install: nocache
install_all: install
git stash
rm -rf gui
rm -rf dfssd/cmd
rm -rf dfssd/gui
rm -f dfssd/cmd/gui.go
rm dfssd/main.go
go install ./...
git reset --hard
......
......@@ -4,9 +4,8 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"dfss/dfssc/user"
"github.com/spf13/cobra"
)
var authCmd = &cobra.Command{
......@@ -22,7 +21,7 @@ var authCmd = &cobra.Command{
err := user.Authenticate(mail, token)
if err != nil {
fmt.Println("An error occurred : ", err.Error())
os.Exit(3)
os.Exit(1)
}
},
}
......@@ -5,9 +5,8 @@ import (
"os"
"path/filepath"
"github.com/spf13/cobra"
"dfss/dfssc/sign"
"github.com/spf13/cobra"
)
var fetchCmd = &cobra.Command{
......
......@@ -4,10 +4,9 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"dfss/dfssc/common"
"dfss/dfssc/user"
"github.com/spf13/cobra"
)
// export the certificate and private key of the user
......@@ -15,6 +14,12 @@ var exportCmd = &cobra.Command{
Use: "export <c>",
Short: "export certificate and private key of the user to file c",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
_ = cmd.Usage()
os.Exit(1)
return
}
confFile := args[0]
fmt.Println("Export user configuration")
var keyPassphrase, confPassphrase string
......@@ -47,6 +52,12 @@ var importCmd = &cobra.Command{
Use: "import <c>",
Short: "import private key and certificate of the user from file c",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
_ = cmd.Usage()
os.Exit(1)
return
}
confFile := args[0]
var keyPassphrase, confPassphrase string
err := readPassphrases(&keyPassphrase, &confPassphrase, false)
......
......@@ -4,9 +4,8 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"dfss/dfssc/sign"
"github.com/spf13/cobra"
)
var newCmd = &cobra.Command{
......
......@@ -10,7 +10,6 @@ import (
"strings"
"dfss/dfssc/user"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)
......
......@@ -4,7 +4,6 @@ import (
"dfss"
dapi "dfss/dfssd/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
......@@ -50,6 +49,6 @@ func init() {
_ = viper.BindPFlag("platform_addrport", RootCmd.PersistentFlags().Lookup("host"))
// Bind subcommands to root
RootCmd.AddCommand(versionCmd, registerCmd, authCmd, newCmd, showCmd, fetchCmd, importCmd, exportCmd, signCmd)
RootCmd.AddCommand(dfss.VersionCmd, registerCmd, authCmd, newCmd, showCmd, fetchCmd, importCmd, exportCmd, signCmd)
}
......@@ -8,7 +8,6 @@ import (
"dfss/dfssc/common"
"dfss/dfssp/contract"
"github.com/spf13/cobra"
)
......@@ -31,6 +30,11 @@ var showCmd = &cobra.Command{
}
func showContract(cmd *cobra.Command, args []string) {
if len(args) != 1 {
_ = cmd.Usage()
return
}
filename := args[0]
c := getContract(filename)
if c == nil {
......
......@@ -4,15 +4,19 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"dfss/dfssc/sign"
"github.com/spf13/cobra"
)
var signCmd = &cobra.Command{
Use: "sign <c>",
Short: "sign contract from file c",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
_ = cmd.Usage()
os.Exit(1)
}
filename := args[0]
fmt.Println("You are going to sign the following contract:")
showContract(cmd, args)
......
package cmd
import (
"dfss"
"fmt"
"runtime"
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print dfss protocol version",
Long: "Print dfss protocol version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
},
}
package main
import (
"fmt"
"os"
"dfss/dfssc/cmd"
......@@ -9,7 +8,6 @@ import (
func main() {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
......@@ -5,7 +5,6 @@ import (
"dfss/dfssd/gui"
"dfss/dfssd/server"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/visualfc/goqt/ui"
......@@ -28,7 +27,3 @@ var guiCmd = &cobra.Command{
})
},
}
func init() {
RootCmd.AddCommand(guiCmd)
}
package cmd
import (
"dfss/dfssd/api"
"dfss/dfssd/server"
"fmt"
"os"
"strconv"
"dfss/dfssd/api"
"dfss/dfssd/server"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
......
......@@ -15,18 +15,16 @@ var RootCmd = &cobra.Command{
Distributed Fair Signing System project
Debug tool to trace remote transmissions`,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
Run: guiCmd.Run,
}
func init() {
// Add flag to the command
RootCmd.PersistentFlags().IntP("port", "p", 3000, "port to use for listening transmissions")
RootCmd.PersistentFlags().IntP("port", "p", 9099, "port to use for listening transmissions")
// Bind the flag to viper
_ = viper.BindPFlag("port", RootCmd.PersistentFlags().Lookup("port"))
// Register subcommands
RootCmd.AddCommand(versionCmd, noguiCmd)
RootCmd.AddCommand(dfss.VersionCmd, noguiCmd, guiCmd)
}
package cmd
import (
"dfss"
"fmt"
"runtime"
"github.com/spf13/cobra"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "print version of dfss protocol",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("DFSS v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
},
}
package main
import (
"fmt"
"os"
"dfss/dfssd/cmd"
......@@ -9,7 +8,6 @@ import (
func main() {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
......@@ -38,11 +38,11 @@ func Initialize(v *viper.Viper, ca *x509.Certificate, rKey *rsa.PrivateKey) erro
if ca == nil {
// Generate the root certificate, using the private key.
cert, err = auth.GetSelfSignedCertificate(v.GetInt("root_validity"), auth.GenerateUID(), v.GetString("country"), v.GetString("organization"), v.GetString("unit"), v.GetString("cn"), key)
cert, err = auth.GetSelfSignedCertificate(v.GetInt("validity"), auth.GenerateUID(), v.GetString("country"), v.GetString("organization"), v.GetString("unit"), v.GetString("cn"), key)
} else {
csr, _ := auth.GetCertificateRequest(v.GetString("country"), v.GetString("organization"), v.GetString("unit"), v.GetString("cn"), key)
request, _ := auth.PEMToCertificateRequest(csr)
cert, err = auth.GetCertificate(v.GetInt("cert_validity"), auth.GenerateUID(), request, ca, rKey)
cert, err = auth.GetCertificate(v.GetInt("validity"), auth.GenerateUID(), request, ca, rKey)
// Override default path values
certPath = filepath.Join(path, "cert.pem")
keyPath = filepath.Join(path, "key.pem")
......
......@@ -35,7 +35,7 @@ func TestInitialize(t *testing.T) {
keyPath := filepath.Join(path, PkeyFileName)
certPath := filepath.Join(path, RootCAFileName)
v := common.MockViper("key_size", 1024, "root_validity", 365, "country", "country", "organization", "organization", "unit", "unit", "cn", "cn", "path", path)
v := common.MockViper("key_size", 1024, "validity", 365, "country", "country", "organization", "organization", "unit", "unit", "cn", "cn", "path", path)
err := Initialize(v, nil, nil)
if err != nil {
......@@ -59,7 +59,7 @@ func Example() {
certPath := filepath.Join(path, RootCAFileName)
// Generate root certificate and key
v := common.MockViper("key_size", 1024, "root_validity", 365, "country", "UK", "organization", "DFSS", "unit", "unit", "cn", "ROOT", "path", path)
v := common.MockViper("key_size", 1024, "validity", 365, "country", "UK", "organization", "DFSS", "unit", "unit", "cn", "ROOT", "path", path)
err := Initialize(v, nil, nil)
if err != nil {
fmt.Println(err)
......@@ -78,7 +78,7 @@ func Example() {
// Generate child certificate and key
childPath := filepath.Join(path, "child")
v = common.MockViper("key_size", 1024, "cert_validity", 10, "country", "FR", "organization", "DFSS", "unit", "unit", "cn", "CHILD", "path", childPath)
v = common.MockViper("key_size", 1024, "validity", 10, "country", "FR", "organization", "DFSS", "unit", "unit", "cn", "CHILD", "path", childPath)
err = Initialize(v, pid.RootCA, pid.Pkey)
if err != nil {
fmt.Println(err)
......@@ -106,7 +106,7 @@ func CheckFile(path, name string) {
func TestStart(t *testing.T) {
path, _ := ioutil.TempDir("", "")
v := common.MockViper("key_size", 1024, "root_validity", 365, "country", "country", "organization", "organization", "unit", "unit", "cn", "cn", "path", path)
v := common.MockViper("key_size", 1024, "validity", 365, "country", "country", "organization", "organization", "unit", "unit", "cn", "cn", "path", path)
_ = Initialize(v, nil, nil)
pid, err := Start(path)
......
......@@ -7,15 +7,23 @@ import (
"dfss/dfssc/common"
dapi "dfss/dfssd/api"
"dfss/dfssp/authority"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var initCmd = &cobra.Command{
Use: "init [cn, country, key, org, path, unit, root-validity]",
Use: "init",
Short: "create and save the platform's private key and root certificate",
Run: func(cmd *cobra.Command, args []string) {
err := authority.Initialize(common.SubViper("key_size", "root_validity", "country", "organization", "unit", "cn", "path"), nil, nil)
_ = viper.BindPFlag("cn", cmd.Flags().Lookup("cn"))
_ = viper.BindPFlag("validity", cmd.Flags().Lookup("validity"))
_ = viper.BindPFlag("country", cmd.Flags().Lookup("country"))
_ = viper.BindPFlag("organization", cmd.Flags().Lookup("org"))
_ = viper.BindPFlag("unit", cmd.Flags().Lookup("unit"))
_ = viper.BindPFlag("key_size", cmd.Flags().Lookup("key"))
err := authority.Initialize(common.SubViper("key_size", "validity", "country", "organization", "unit", "cn", "path"), nil, nil)
if err != nil {
fmt.Fprintln(os.Stderr, "An error occured during the initialization operation:", err)
os.Exit(1)
......
......@@ -3,7 +3,6 @@ package cmd
import (
"dfss"
dapi "dfss/dfssd/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
......@@ -31,37 +30,35 @@ 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().StringP("address", "a", "0.0.0.0", "address to bind for listening")
RootCmd.PersistentFlags().StringP("port", "p", "9000", "port to bind for listening")
RootCmd.PersistentFlags().String("path", ".", "path to get the platform's private key and root certificate")
RootCmd.PersistentFlags().String("country", "France", "country for the root certificate")
RootCmd.PersistentFlags().String("org", "DFSS", "Organization for the root certificate")
RootCmd.PersistentFlags().String("unit", "INSA Rennes", "Organizational unit for the rot certificate")
RootCmd.PersistentFlags().String("cn", "dfssp", "Common name for the root certificate")
RootCmd.PersistentFlags().IntP("key", "k", 512, "Encoding size for the private key")
RootCmd.PersistentFlags().IntP("root-validity", "r", 365, "Validity duration for the root certificate (days)")
RootCmd.PersistentFlags().IntP("cert-validity", "c", 365, "Validity duration for the child certificates (days)")
RootCmd.PersistentFlags().String("db", "mongodb://localhost/dfss", "server url in standard MongoDB format for accessing database")
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")
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")
// Bind viper to flags
_ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
_ = viper.BindPFlag("demo", RootCmd.PersistentFlags().Lookup("demo"))
_ = viper.BindPFlag("address", RootCmd.PersistentFlags().Lookup("address"))
_ = viper.BindPFlag("port", RootCmd.PersistentFlags().Lookup("port"))
_ = viper.BindPFlag("path", RootCmd.PersistentFlags().Lookup("path"))
_ = viper.BindPFlag("country", RootCmd.PersistentFlags().Lookup("country"))
_ = viper.BindPFlag("organization", RootCmd.PersistentFlags().Lookup("org"))
_ = viper.BindPFlag("unit", RootCmd.PersistentFlags().Lookup("unit"))
_ = viper.BindPFlag("cn", RootCmd.PersistentFlags().Lookup("cn"))
_ = viper.BindPFlag("key_size", RootCmd.PersistentFlags().Lookup("key"))
_ = viper.BindPFlag("root_validity", RootCmd.PersistentFlags().Lookup("root-validity"))
_ = viper.BindPFlag("cert_validity", RootCmd.PersistentFlags().Lookup("cert-validity"))
_ = viper.BindPFlag("dbURI", RootCmd.PersistentFlags().Lookup("db"))
viper.SetDefault("pkey_filename", "dfssp_pkey.pem")
viper.SetDefault("ca_filename", "dfssp_rootCA.pem")
// Register subcommands here
RootCmd.AddCommand(versionCmd, ttpCmd, initCmd, startCmd)
RootCmd.AddCommand(dfss.VersionCmd, ttpCmd, initCmd, startCmd)
}
......@@ -7,15 +7,20 @@ import (
dapi "dfss/dfssd/api"
"dfss/dfssp/server"
"dfss/net"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var startCmd = &cobra.Command{
Use: "start [path, db, address, port, cert-validity]",
Use: "start",
Short: "start the platform after loading its private key and root certificate",
Run: func(cmd *cobra.Command, args []string) {
_ = viper.BindPFlag("dbURI", cmd.Flags().Lookup("db"))
_ = viper.BindPFlag("address", cmd.Flags().Lookup("address"))
_ = viper.BindPFlag("port", cmd.Flags().Lookup("port"))
_ = viper.BindPFlag("validity", cmd.Flags().Lookup("validity"))
address := viper.GetString("address")
port := viper.GetString("port")
......
......@@ -8,27 +8,36 @@ import (
"dfss/dfssc/common"
dapi "dfss/dfssd/api"
"dfss/dfssp/authority"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var ttpCmd = &cobra.Command{
Use: "ttp [cn, country, key, org, path, unit, cert-validity]",
Use: "ttp",
Short: "create and save the TTP's private key and certificate",
Run: func(cmd *cobra.Command, args []string) {
_ = viper.BindPFlag("cn", cmd.Flags().Lookup("cn"))
_ = viper.BindPFlag("validity", cmd.Flags().Lookup("validity"))
_ = viper.BindPFlag("country", cmd.Flags().Lookup("country"))
_ = viper.BindPFlag("organization", cmd.Flags().Lookup("org"))
_ = viper.BindPFlag("unit", cmd.Flags().Lookup("unit"))
_ = viper.BindPFlag("key_size", cmd.Flags().Lookup("key"))
path := viper.GetString("path")
pid, err := authority.Start(path)
if err != nil {
fmt.Fprintln(os.Stderr, "Bad root CA or key; please use the `init` command before the `ttp` one.\n", err)
os.Exit(1)
}
ttpPath := filepath.Join(path, "ttp")
v := common.SubViper("key_size", "root_validity", "country", "organization", "unit", "cn")
v := common.SubViper("key_size", "validity", "country", "organization", "unit", "cn")
v.Set("path", ttpPath)
err = authority.Initialize(v, pid.RootCA, pid.Pkey)
if err != nil {
fmt.Fprintln(os.Stderr, "An error occured during TTP credentials generation:", err)
os.Exit(1)
}
dapi.DLog("Private key and certificate generated for TTP")
},
......
package cmd
import (
"dfss"
"fmt"
"runtime"
"github.com/spf13/cobra"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "version of the dfss protocol",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("DFSS v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
},
}
......@@ -45,7 +45,7 @@ func TestMain(m *testing.M) {
keyPath := filepath.Join(os.Getenv("GOPATH"), "src", "dfss", "dfssp", "testdata")
viper.Set("path", keyPath)
viper.Set("dbURI", dbURI)
viper.Set("root_validity", 365)
viper.Set("validity", 365)
viper.Set("verbose", true)
srv := server.GetServer()
......
package main
import (
"fmt"
"os"
"dfss/dfssp/cmd"
......@@ -9,7 +8,6 @@ import (
func main() {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
......@@ -135,7 +135,7 @@ func checkAuthRequest(in *api.AuthRequest) error {
return errors.New("Invalid token length")
}
if viper.GetInt("cert_validity") < 1 {
if viper.GetInt("validity") < 1 {
return errors.New("Invalid validity duration")
}
......@@ -162,7 +162,7 @@ func generateUserCert(csr string, parent *x509.Certificate, key *rsa.PrivateKey)
return nil, nil, err
}
cert, err := auth.GetCertificate(viper.GetInt("cert_validity"), auth.GenerateUID(), x509csr, parent, key)
cert, err := auth.GetCertificate(viper.GetInt("validity"), auth.GenerateUID(), x509csr, parent, key)
if err != nil {
return nil, nil, err
}
......@@ -224,7 +224,7 @@ func Auth(pid *authority.PlatformID, manager *mgdb.MongoManager, in *api.AuthReq
user.Certificate = string(cert)
user.CertHash = certHash
user.Expiration = time.Now().AddDate(0, 0, viper.GetInt("cert_validity"))
user.Expiration = time.Now().AddDate(0, 0, viper.GetInt("validity"))
// Updating the database
ok, err := manager.Get("users").UpdateByID(user)
......
......@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"testing"
"time"
"dfss/auth"
"dfss/dfssp/api"
......@@ -15,8 +16,6 @@ import (
"dfss/dfssp/server"
"dfss/mgdb"
"dfss/net"
"time"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
......@@ -73,16 +72,11 @@ func TestMain(m *testing.M) {
// Valid server
viper.Set("path", keyPath)
viper.Set("dbURI", dbURI)
viper.Set("root_validity", 365)
viper.Set("cert_validity", 365)
viper.Set("validity", 365)
viper.Set("verbose", true)
srv := server.GetServer()
go func() { _ = net.Listen(ValidServ, srv) }()
// Server using invalid certificate duration
// srv2 := server.GetServer(keyPath, dbURI, -1, true)
// go func() { _ = net.Listen(InvalidServ, srv2) }()
// Run
err = collection.Drop()
code := m.Run()
......
package cmd
import (
"dfss"
"fmt"
"dfss"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
......@@ -32,9 +32,10 @@ func init() {
RootCmd.PersistentFlags().String("cert", "cert.pem", "path to the ttp's certificate")
RootCmd.PersistentFlags().String("key", "key.pem", "path to the ttp's private key")
RootCmd.PersistentFlags().StringP("demo", "d", "", "demonstrator address and port, empty will disable it")
RootCmd.PersistentFlags().StringP("address", "a", "0.0.0.0", "address to bind for listening")
RootCmd.PersistentFlags().String("db", "mongodb://localhost/dfss", "server url in standard MongoDB format to access the database")
RootCmd.PersistentFlags().IntP("port", "p", 9020, "port to bind for listening")
startCmd.Flags().StringP("address", "a", "0.0.0.0", "address to bind for listening")
startCmd.Flags().String("db", "mongodb://localhost/dfss", "server url in standard MongoDB format to access the database")
startCmd.Flags().IntP("port", "p", 9020, "port to bind for listening")
// Store flag values into viper
_ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
......@@ -42,9 +43,10 @@ func init() {
_ = viper.BindPFlag("file_cert", RootCmd.PersistentFlags().Lookup("cert"))
_ = viper.BindPFlag("file_key", RootCmd.PersistentFlags().Lookup("key"))
_ = viper.BindPFlag("demo", RootCmd.PersistentFlags().Lookup("demo"))
_ = viper.BindPFlag("port", RootCmd.PersistentFlags().Lookup("port"))
_ = viper.BindPFlag("address", RootCmd.PersistentFlags().Lookup("address"))
_ = viper.BindPFlag("dbURI", RootCmd.PersistentFlags().Lookup("db"))
_ = viper.BindPFlag("port", startCmd.Flags().Lookup("port"))
_ = viper.BindPFlag("address", startCmd.Flags().Lookup("address"))
_ = viper.BindPFlag("dbURI", startCmd.Flags().Lookup("db"))
if err := viper.BindEnv("password", "DFSS_TTP_PASSWORD"); err != nil {
fmt.Println("Warning: The DFSS_TTP_PASSWORD environment variable is not set, assuming the private key is decrypted")
......@@ -52,6 +54,6 @@ func init() {
}
// Register Sub Commands
RootCmd.AddCommand(versionCmd, startCmd)
RootCmd.AddCommand(dfss.VersionCmd, startCmd)
}
......@@ -8,7 +8,6 @@ import (
dapi "dfss/dfssd/api"
"dfss/dfsst/server"
"dfss/net"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
......
package cmd
import (
"dfss"
"fmt"
"runtime"
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print dfss protocol version",
Long: "Print dfss protocol version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
},
}
package main
import (
"fmt"
"os"
"dfss/dfsst/cmd"
......@@ -9,7 +8,6 @@ import (
func main() {
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
......@@ -25,10 +25,7 @@ func Load() {
path := GetHomeDir()
viper.AddConfigPath(GetHomeDir())
viper.SetConfigName(viper.GetString("filename_config"))
err := viper.ReadInConfig()
if err != nil {
return
}
viper.ReadInConfig()
// Alias for platform
viper.RegisterAlias("platform_addrport", "platform")
......@@ -38,11 +35,12 @@ func Load() {
viper.Set("file_ca", filepath.Join(path, viper.GetString("filename_ca")))
viper.Set("file_cert", filepath.Join(path, viper.GetString("filename_cert")))
viper.Set("file_key", filepath.Join(path, viper.GetString("filename_key")))
viper.Set("file_config", filepath.Join(path, viper.GetString("filename_config")))
viper.Set("file_config", filepath.Join(path, viper.GetString("filename_config")) + ".json")
// Fill virtual-only fields
viper.Set("registered", isFileValid(viper.GetString("file_key")))
viper.Set("authenticated", isFileValid(viper.GetString("file_cert")))
return
}
......
......@@ -7,7 +7,6 @@ import (
"dfss/gui/contractform"
"dfss/gui/signform"
"dfss/gui/userform"
"github.com/spf13/viper"
"github.com/visualfc/goqt/ui"
)
......@@ -27,7 +26,7 @@ func init() {
viper.Set("filename_ca", "ca.pem")
viper.Set("filename_cert", "cert.pem")
viper.Set("filename_key", "key.pem")
viper.Set("filename_config", "config.json")
viper.Set("filename_config", "config")
}