mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 05:04:18 +02:00
add 'license show', add printer.NewTableEmpty() along .WithHeaders() (#69)
This commit is contained in:
@@ -550,6 +550,8 @@ index - manage indicies
|
|||||||
create - create a new index template
|
create - create a new index template
|
||||||
update - update a new index template
|
update - update a new index template
|
||||||
delete - delete an index template
|
delete - delete an index template
|
||||||
|
license - manage cluster license
|
||||||
|
show - show details about the cluster license
|
||||||
node - manage nodes
|
node - manage nodes
|
||||||
list - list nodes
|
list - list nodes
|
||||||
show - show details about a node
|
show - show details about a node
|
||||||
@@ -571,7 +573,7 @@ task - manage tasks
|
|||||||
version - show esctl version information
|
version - show esctl version information
|
||||||
debug - developer only
|
debug - developer only
|
||||||
help-jsonpath - show jsonpath help
|
help-jsonpath - show jsonpath help
|
||||||
help-command-overview - show overview of all available commands
|
help-usage - show overview of all available commands
|
||||||
```
|
```
|
||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|||||||
49
cmd/license.go
Normal file
49
cmd/license.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2026 Thomas von Dein
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
|
"codeberg.org/scip/esctl/pkg/es"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func License(conf *cfg.Config) *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "license",
|
||||||
|
Usage: "manage cluster license",
|
||||||
|
|
||||||
|
Commands: []*cli.Command{
|
||||||
|
LicenseShow(conf),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LicenseShow(conf *cfg.Config) *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "show",
|
||||||
|
Aliases: []string{"sh"},
|
||||||
|
Usage: "show details about the cluster license",
|
||||||
|
|
||||||
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
return es.LicenseShow(conf)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -108,6 +108,7 @@ func Main() int {
|
|||||||
Doc(conf),
|
Doc(conf),
|
||||||
Ilm(conf),
|
Ilm(conf),
|
||||||
Index(conf),
|
Index(conf),
|
||||||
|
License(conf),
|
||||||
Node(conf),
|
Node(conf),
|
||||||
Roles(conf),
|
Roles(conf),
|
||||||
Search(conf),
|
Search(conf),
|
||||||
|
|||||||
59
pkg/es/license.go
Normal file
59
pkg/es/license.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
Copyright © 2026 Thomas von Dein
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package es
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
|
"codeberg.org/scip/esctl/pkg/printer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LicenseShow(conf *cfg.Config) error {
|
||||||
|
res, err := conf.DefaultCluster.ES().License.Get().
|
||||||
|
Do(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get license: %s", esErrorString(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Debug("license show", "license", res)
|
||||||
|
|
||||||
|
table := printer.NewTableEmpty(conf).WithHeaders("license setting", "value")
|
||||||
|
|
||||||
|
lic := res.License
|
||||||
|
|
||||||
|
var maxnodes = "infinite"
|
||||||
|
|
||||||
|
if lic.MaxNodes != nil {
|
||||||
|
maxnodes = fmt.Sprintf("%d", *lic.MaxNodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
table.Entries = [][]string{
|
||||||
|
{"UID", lic.Uid},
|
||||||
|
{"Issued to", lic.IssuedTo},
|
||||||
|
{"Expires", lic.ExpiryDate.(string)},
|
||||||
|
{"Issued", lic.IssueDate.(string)},
|
||||||
|
{"Max nodes", maxnodes},
|
||||||
|
{"Max resource units", fmt.Sprintf("%d", *lic.MaxResourceUnits)},
|
||||||
|
{"Type", lic.Type.Name},
|
||||||
|
{"Status", lic.Status.Name},
|
||||||
|
}
|
||||||
|
|
||||||
|
return table.Print()
|
||||||
|
}
|
||||||
@@ -53,6 +53,24 @@ func NewTable(conf *cfg.Config, columns, rows int) *Table {
|
|||||||
return &table
|
return &table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewTableEmpty(conf *cfg.Config) *Table {
|
||||||
|
table := Table{Mode: conf.Output, maxwidth: cfg.GetTermWidth()}
|
||||||
|
table.alignInts = conf.AlignInts
|
||||||
|
return &table
|
||||||
|
}
|
||||||
|
|
||||||
|
func (table *Table) WithHeaders(headers ...string) *Table {
|
||||||
|
count := len(headers)
|
||||||
|
|
||||||
|
table.Entries = [][]string{}
|
||||||
|
table.lenHeaders = make([]int, count)
|
||||||
|
table.Headers = make([]string, count)
|
||||||
|
|
||||||
|
table.Addheaders(headers...)
|
||||||
|
|
||||||
|
return table
|
||||||
|
}
|
||||||
|
|
||||||
func (data *Table) Print() error {
|
func (data *Table) Print() error {
|
||||||
switch data.Mode {
|
switch data.Mode {
|
||||||
case "markdown", "md":
|
case "markdown", "md":
|
||||||
|
|||||||
Reference in New Issue
Block a user