2020-04-21 18:55:31 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LicenseGetCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *LicenseGetCommand) Help() string {
|
|
|
|
helpText := `
|
2020-04-22 13:42:25 +00:00
|
|
|
Usage: nomad license get [options]
|
2020-04-21 18:55:31 +00:00
|
|
|
|
|
|
|
Gets a new license in Servers and Clients
|
|
|
|
General Options:
|
|
|
|
|
|
|
|
` + generalOptionsUsage() + `
|
|
|
|
|
|
|
|
Get Options:
|
|
|
|
|
|
|
|
-signed
|
|
|
|
Determines if the returned license should be a signed blob instead of a
|
|
|
|
parsed license.
|
|
|
|
|
|
|
|
`
|
|
|
|
return helpText
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *LicenseGetCommand) Synopsis() string {
|
|
|
|
return "Install a new Nomad Enterprise License"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *LicenseGetCommand) Name() string { return "license get" }
|
|
|
|
|
|
|
|
func (c *LicenseGetCommand) Run(args []string) int {
|
|
|
|
var signed bool
|
|
|
|
|
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
flags.BoolVar(&signed, "signed", false, "Gets the signed license blob instead of a parsed license")
|
|
|
|
|
2020-04-22 13:42:25 +00:00
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error parsing flags: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2020-04-21 18:55:31 +00:00
|
|
|
client, err := c.Meta.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
2020-04-22 13:42:25 +00:00
|
|
|
return 1
|
2020-04-21 18:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if signed {
|
|
|
|
resp, _, err := client.Operator().LicenseGetSigned(nil)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error getting signed license: %v", err))
|
2020-04-22 13:42:25 +00:00
|
|
|
return 1
|
2020-04-21 18:55:31 +00:00
|
|
|
}
|
|
|
|
c.Ui.Output(resp)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, _, err := client.Operator().LicenseGet(nil)
|
|
|
|
if err != nil {
|
2020-04-22 13:42:25 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error getting license: %v", err))
|
|
|
|
return 1
|
2020-04-21 18:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OutputLicenseReply(c.Ui, resp)
|
|
|
|
}
|