-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
69 lines (54 loc) · 1.78 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"flag"
)
type cliParameters struct {
StartServer *bool
AddClient *bool
RevokeClient *bool
ClientID *string
ClientSecret *string
RedirectURI *string
ConfigPath *string
}
func showDefaults() {
flag.PrintDefaults()
}
func handleCLIParameters(params *cliParameters) (err error) {
params.StartServer = flag.Bool("start-server", false, "Starts the webserver if set.")
params.AddClient = flag.Bool("add-client", false, "Add the specified ClientId and Secret.")
params.RevokeClient = flag.Bool("revoke-client", false, "Revokes the ClientId.")
params.ClientID = flag.String("client-id", "", "The new ClientId to be added or revoked.")
params.ClientSecret = flag.String("client-secret", "", "The new ClientSecret.")
params.RedirectURI = flag.String("redirect-uri", "", "The RedirectUri.")
params.ConfigPath = flag.String("config", "", "Path to config file in ini format.")
flag.Parse()
// Validate CLI values
if !(*params.StartServer) && !(*params.AddClient) && !(*params.RevokeClient) {
err = errors.New("You need to specify StartServer, AddClient or RevokeClient")
}
if *params.ConfigPath == "" {
err = errors.New("No config Path given")
}
if *(params.StartServer) && *(params.AddClient) || *(params.StartServer) && *(params.RevokeClient) {
err = errors.New("You can not add/revoke a client and start the server")
}
if *(params.AddClient) && *(params.RevokeClient) {
err = errors.New("Can not revoke and add at the same time")
}
if *(params.AddClient) {
if *(params.ClientID) == "" {
err = errors.New("Invalid ClientId")
}
if *(params.ClientSecret) == "" {
err = errors.New("Invalid ClientSecret")
}
}
if *(params.RevokeClient) {
if *(params.ClientID) == "" {
err = errors.New("Invalid ClientId")
}
}
return err
}