-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjarvice.go
123 lines (108 loc) · 3.75 KB
/
jarvice.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"errors"
"fmt"
jarvice "jarvice.io/jarvice-hpc/core"
logger "jarvice.io/jarvice-hpc/logger"
)
type JarviceConfigFlags struct {
Help bool `short:"h" long:"help" description:"Show this help message"`
}
type JarviceCommand struct {
Config JarviceConfigFlags `group:"Configuration Options"`
Login JarviceLoginCommand `command:"login"`
Vault JarviceVaultCommand `command:"vault"`
Cluster JarviceClusterCommand `command:"cluster"`
Live JarviceLiveCommand `command:"live"`
}
type JarviceLoginCommand struct {
Config JarviceConfigFlags `group:"Configuration Options" hidden:"true"`
Vault string `short:"v" long:"vault" description:"JARVICE vault" default:"ephemeral"`
Insecure bool `short:"k" long:"insecure" description:"proceed if server configuration is considered insecure"`
Args struct {
Endpoint string `postitional-arg-name:"endpoint" description:"JARVICE API endpoint"`
Cluster string `positional-arg-name:"cluster" description:"JARVICE cluster"`
Username string `positional-arg-name:"username "description:"JARVICE username"`
Apikey string `positinal-arg-name:"apikey" description:"JARVICE apikey"`
} `positional-args:"true" required:"4"`
}
type JarviceVaultCommand struct {
Config JarviceConfigFlags `group:"Configuration Options" hidden:"true"`
Vault string `short:"v" long:"vault" description:"JARVICE vault" default:"ephemeral"`
}
type JarviceClusterCommand struct {
Config JarviceConfigFlags `group:"Configuration Options" hidden:"true"`
List bool `short:"l" long:"list" description:"list available JARVICE configurations"`
Args struct {
Cluster string `positional-arg-name:"cluster" description:"JARVICE cluster"`
} `positional-args:"true"`
}
type JarviceLiveCommand struct {
Config JarviceConfigFlags `group:"Configuration Options" hidden:"true"`
Args struct {
Cluster string `positional-arg-name:"cluster" description:"JARVICE cluster"`
} `positional-args:"true" required:"1"`
}
var jarviceCommand JarviceCommand
func (x *JarviceCommand) Execute(args []string) error {
if x.Config.Help {
return jarvice.CreateHelpErr()
}
return nil
}
func (x *JarviceLoginCommand) Execute(args []string) error {
if x.Config.Help {
return jarvice.CreateHelpErr()
}
logger.InfoPrintf("processing HPC login")
return jarvice.HpcLogin(x.Args.Endpoint, x.Insecure, x.Args.Cluster,
x.Args.Username, x.Args.Apikey, x.Vault)
}
func (x *JarviceVaultCommand) Execute(args []string) error {
if x.Config.Help {
return jarvice.CreateHelpErr()
}
logger.InfoPrintf("processing HPC vault")
return jarvice.HpcVault(x.Vault)
}
func (x *JarviceClusterCommand) Execute(args []string) error {
if x.Config.Help {
return jarvice.CreateHelpErr()
}
logger.InfoPrintf("setup JarviceXE config")
config, _ := jarvice.ReadJarviceConfig()
if x.List {
if len(config) == 0 {
return errors.New("No clusters found. Setup config using: jarvice login")
}
for key, _ := range config {
fmt.Println(key)
}
return nil
}
if len(x.Args.Cluster) == 0 {
return errors.New("Cluster argument missing")
}
if _, ok := config[x.Args.Cluster]; ok {
return jarvice.WriteJarviceConfigTarget(x.Args.Cluster)
} else {
return errors.New(x.Args.Cluster + " configuration does not exits." +
" Setup config using: jarvice login")
}
}
func (x *JarviceLiveCommand) Execute(args []string) error {
if x.Config.Help {
return jarvice.CreateHelpErr()
}
logger.InfoPrintf("Validating cluster configuration")
if err := jarvice.HpcLive(x.Args.Cluster); err != nil {
return fmt.Errorf("live: %w", err)
}
return nil
}
func init() {
parser.AddCommand("jarvice",
"JARVICE configuration",
"The jarvice creates the configuration file to use with the JARVICE API",
&jarviceCommand)
}