update license command output to reflect api changes

This commit is contained in:
Drew Bailey
2020-05-05 10:28:58 -04:00
parent 65f09ed119
commit d5f99a06e2
5 changed files with 19 additions and 37 deletions

View File

@@ -232,19 +232,16 @@ type License struct {
}
type LicenseReply struct {
Valid bool
License *License
Warnings []string
License *License
QueryMeta
}
func (op *Operator) LicensePut(license string, q *WriteOptions) (*LicenseReply, *WriteMeta, error) {
var resp LicenseReply
wm, err := op.c.write("/v1/operator/license", license, &resp, q)
func (op *Operator) LicensePut(license string, q *WriteOptions) (*WriteMeta, error) {
wm, err := op.c.write("/v1/operator/license", license, nil, q)
if err != nil {
return nil, nil, err
return nil, err
}
return &resp, wm, nil
return wm, nil
}
func (op *Operator) LicenseGet(q *QueryOptions) (*LicenseReply, *QueryMeta, error) {

View File

@@ -49,29 +49,15 @@ func (l *LicenseCommand) Run(args []string) int {
func OutputLicenseReply(ui cli.Ui, resp *api.LicenseReply) int {
var validity string
if resp.Valid {
validity = "valid"
outputLicenseInfo(ui, resp.License, false, validity)
return 0
} else if resp.License != nil {
now := time.Now()
if resp.License.ExpirationTime.Before(now) {
validity = "expired!"
outputLicenseInfo(ui, resp.License, true, validity)
} else {
validity = "invalid!"
for _, warn := range resp.Warnings {
ui.Output(fmt.Sprintf(" %s", warn))
}
outputLicenseInfo(ui, resp.License, false, validity)
}
now := time.Now()
if resp.License.ExpirationTime.Before(now) {
validity = "expired!"
outputLicenseInfo(ui, resp.License, true, validity)
return 1
} else {
// TODO - remove the expired message here in the future
// once the go-licensing library is updated post 1.1
ui.Output("Nomad is unlicensed or the license has expired")
return 0
}
validity = "valid"
outputLicenseInfo(ui, resp.License, false, validity)
return 0
}
func outputLicenseInfo(ui cli.Ui, lic *api.License, expired bool, validity string) {
@@ -83,6 +69,7 @@ func outputLicenseInfo(ui cli.Ui, lic *api.License, expired bool, validity strin
}
output := []string{
fmt.Sprintf("Product|%s", lic.Product),
fmt.Sprintf("License Status|%s", validity),
fmt.Sprintf("License ID|%s", lic.LicenseID),
fmt.Sprintf("Customer ID|%s", lic.CustomerID),

View File

@@ -27,7 +27,6 @@ func (c *LicenseGetCommand) Synopsis() string {
func (c *LicenseGetCommand) Name() string { return "license get" }
func (c *LicenseGetCommand) Run(args []string) int {
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }

View File

@@ -19,13 +19,11 @@ func TestCommand_LicenseGet_OSSErr(t *testing.T) {
cmd := &LicenseGetCommand{Meta: Meta{Ui: ui}}
code := cmd.Run([]string{"-address=" + url})
require.Equal(t, 1, code)
if srv.Enterprise {
// TODO update assertion once ent licensing implemented
require.Contains(t, ui.ErrorWriter.String(), "404")
require.Equal(t, 0, code)
require.Contains(t, ui.OutputWriter.String(), "License Status = valid")
} else {
require.Equal(t, 1, code)
require.Contains(t, ui.ErrorWriter.String(), "Nomad Enterprise only endpoint")
}
}

View File

@@ -67,13 +67,14 @@ func (c *LicensePutCommand) Run(args []string) int {
return 1
}
resp, _, err := client.Operator().LicensePut(data, nil)
_, err = client.Operator().LicensePut(data, nil)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error putting license: %v", err))
return 1
}
return OutputLicenseReply(c.Ui, resp)
c.Ui.Output("Successfully applied license")
return 0
}
func (c *LicensePutCommand) dataFromArgs(args []string) (string, error) {