diff --git a/api/operator.go b/api/operator.go index 5d4254442..88727608c 100644 --- a/api/operator.go +++ b/api/operator.go @@ -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) { diff --git a/command/license.go b/command/license.go index 101191469..b13ccea62 100644 --- a/command/license.go +++ b/command/license.go @@ -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), diff --git a/command/license_get.go b/command/license_get.go index e46d56b46..bf326462c 100644 --- a/command/license_get.go +++ b/command/license_get.go @@ -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()) } diff --git a/command/license_get_test.go b/command/license_get_test.go index 90ff468a2..1fb8e08b3 100644 --- a/command/license_get_test.go +++ b/command/license_get_test.go @@ -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") } - } diff --git a/command/license_put.go b/command/license_put.go index f7148ab17..5b5b80d69 100644 --- a/command/license_put.go +++ b/command/license_put.go @@ -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) {