github.com/aminovpavel/nomad@v0.11.8/command/license.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 8 "github.com/hashicorp/nomad/api" 9 "github.com/mitchellh/cli" 10 ) 11 12 var _ cli.Command = &LicenseCommand{} 13 14 type LicenseCommand struct { 15 Meta 16 } 17 18 func (l *LicenseCommand) Help() string { 19 helpText := ` 20 Usage: nomad license <subcommand> [options] [args] 21 22 This command has subcommands for managing the Nomad Enterprise license. 23 For more detailed examples see: 24 https://www.nomadproject.io/docs/commands/license/ 25 26 Install a new license from a file: 27 $ nomad license put <path> 28 29 Install a new license from stdin: 30 $ nomad license put - 31 32 Retrieve the current license: 33 34 $ nomad license get 35 36 ` 37 return strings.TrimSpace(helpText) 38 } 39 40 func (l *LicenseCommand) Synopsis() string { 41 return "Interact with Nomad Enterprise License" 42 } 43 44 func (l *LicenseCommand) Name() string { return "license" } 45 46 func (l *LicenseCommand) Run(args []string) int { 47 return cli.RunResultHelp 48 } 49 50 func OutputLicenseReply(ui cli.Ui, resp *api.LicenseReply) int { 51 var validity string 52 now := time.Now() 53 if resp.License.ExpirationTime.Before(now) { 54 validity = "expired!" 55 outputLicenseInfo(ui, resp.License, true, validity) 56 return 1 57 } 58 validity = "valid" 59 outputLicenseInfo(ui, resp.License, false, validity) 60 return 0 61 } 62 63 func outputLicenseInfo(ui cli.Ui, lic *api.License, expired bool, validity string) { 64 expStr := "" 65 if expired { 66 expStr = fmt.Sprintf("Expired At|%s", lic.ExpirationTime.String()) 67 } else { 68 expStr = fmt.Sprintf("Expires At|%s", lic.ExpirationTime.String()) 69 } 70 71 output := []string{ 72 fmt.Sprintf("Product|%s", lic.Product), 73 fmt.Sprintf("License Status|%s", validity), 74 fmt.Sprintf("License ID|%s", lic.LicenseID), 75 fmt.Sprintf("Customer ID|%s", lic.CustomerID), 76 expStr, 77 fmt.Sprintf("License ID|%s", lic.LicenseID), 78 fmt.Sprintf("Customer ID|%s", lic.CustomerID), 79 fmt.Sprintf("Terminates At|%s", lic.TerminationTime.String()), 80 fmt.Sprintf("Datacenter|%s", lic.InstallationID), 81 } 82 ui.Output(formatKV(output)) 83 84 if len(lic.Modules) > 0 { 85 ui.Output("Modules:") 86 for _, mod := range lic.Modules { 87 ui.Output(fmt.Sprintf("\t%s", mod)) 88 } 89 } 90 if len(lic.Features) > 0 { 91 ui.Output("Licensed Features:") 92 for _, f := range lic.Features { 93 ui.Output(fmt.Sprintf("\t%s", f)) 94 } 95 } 96 }