main.go 2.55 KB
Newer Older
Loïck Bonniot's avatar
Loïck Bonniot committed
1
2
3
4
5
6
7
package main

import (
	"dfss"
	"flag"
	"fmt"
	"runtime"
8
9

	dapi "dfss/dfssd/api"
Loïck Bonniot's avatar
Loïck Bonniot committed
10
11
12
)

var (
13
	verbose   bool
14
	demo      string
15
16
17
18
19
	fca       string // Path to the CA
	fcert     string // Path to the certificate
	fkey      string // Path to the private key
	addrPort  string // Address and port of the platform
	localPort int    // Port to open for P2P communication
Loïck Bonniot's avatar
Loïck Bonniot committed
20
21
22
23
24
)

func init() {

	flag.BoolVar(&verbose, "v", false, "Print verbose messages")
25
26
	flag.StringVar(&fca, "ca", "ca.pem", "Path to the root certificate")
	flag.StringVar(&fcert, "cert", "cert.pem", "Path to the user certificate")
Loïck Bonniot's avatar
Loïck Bonniot committed
27
28
	flag.StringVar(&fkey, "key", "key.pem", "Path to the private key")
	flag.StringVar(&addrPort, "host", "localhost:9000", "Host of the DFSS platform")
29
	flag.StringVar(&demo, "d", "", "Demonstrator address and port (empty string disables debug)")
30
	flag.IntVar(&localPort, "port", 9005, "Port to use for P2P communication between clients")
Loïck Bonniot's avatar
Loïck Bonniot committed
31
32
33
34
35
36

	flag.Usage = func() {
		fmt.Println("DFSS client command line v" + dfss.Version)
		fmt.Println("A tool to sign multiparty contracts")

		fmt.Println("\nUsage:")
37
		fmt.Println("  dfssc [flags] command")
Loïck Bonniot's avatar
Loïck Bonniot committed
38
39

		fmt.Println("\nThe commands are:")
40
41
42
43
44
		fmt.Println("  help       print this help")
		fmt.Println("  version    print dfss client version")
		fmt.Println("  register   register a new client")
		fmt.Println("  auth       authenticate a new client")
		fmt.Println("  new        create a new contract")
Loïck Bonniot's avatar
Loïck Bonniot committed
45
		fmt.Println("  fetch      get a contract hosted on the platform")
46
47
48
		fmt.Println("  show <c>   print contract information from file c")
		fmt.Println("  export <c> export certificate and private key of the user to file c")
		fmt.Println("  import <c> import private key and certificate from file c")
49
		fmt.Println("  sign <c>   sign contract from file c")
Loïck Bonniot's avatar
Loïck Bonniot committed
50
51
52
53
54
55
56
57

		fmt.Println("\nFlags:")
		flag.PrintDefaults()

		fmt.Println()
	}
}

Loïck Bonniot's avatar
Loïck Bonniot committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
type command struct {
	nbArgs int
	fn     func([]string)
}

var commands = map[string]command{
	"version": command{0, func([]string) {
		fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
	}},
	"register": command{0, registerUser},
	"auth":     command{0, authUser},
	"new":      command{0, newContract},
	"fetch":    command{0, fetchContract},
	"show":     command{1, showContract},
	"export":   command{1, exportConf},
	"import":   command{1, importConf},
	"sign":     command{1, signContract},
}

Loïck Bonniot's avatar
Loïck Bonniot committed
77
78
func main() {
	flag.Parse()
Loïck Bonniot's avatar
Loïck Bonniot committed
79
	arg := flag.Arg(0)
80
81
	dapi.Configure(demo != "", demo, "client")

Loïck Bonniot's avatar
Loïck Bonniot committed
82
	c, ok := commands[arg]
83

Loïck Bonniot's avatar
Loïck Bonniot committed
84
	if !ok || flag.NArg()-1 < c.nbArgs {
Loïck Bonniot's avatar
Loïck Bonniot committed
85
		flag.Usage()
Loïck Bonniot's avatar
Loïck Bonniot committed
86
		return
Loïck Bonniot's avatar
Loïck Bonniot committed
87
	}
Loïck Bonniot's avatar
Loïck Bonniot committed
88
89
90
91

	args := flag.Args()
	args = append(args, "")
	c.fn(args[1:])
Loïck Bonniot's avatar
Loïck Bonniot committed
92
}