mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 21:14:18 +02:00
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
/*
|
|
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"
|
|
"strconv"
|
|
|
|
"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: %w", esErrorString(err))
|
|
}
|
|
|
|
slog.Debug("license show", "license", res)
|
|
|
|
table := printer.NewTableEmpty(conf).WithHeaders("license setting", "value")
|
|
|
|
lic := res.License
|
|
|
|
var (
|
|
maxnodes = "infinite"
|
|
maxunits = "infinite"
|
|
expire = "never"
|
|
)
|
|
|
|
if lic.MaxNodes != nil {
|
|
maxnodes = strconv.FormatInt(*lic.MaxNodes, 10)
|
|
}
|
|
|
|
if lic.ExpiryDate != nil {
|
|
expire = lic.ExpiryDate.(string)
|
|
}
|
|
|
|
if lic.MaxResourceUnits != nil {
|
|
maxunits = strconv.Itoa(*lic.MaxResourceUnits)
|
|
}
|
|
|
|
table.Entries = [][]any{
|
|
{"UID", lic.Uid},
|
|
{"Issued to", lic.IssuedTo},
|
|
{"Expires", expire},
|
|
{"Issued", lic.IssueDate},
|
|
{"Max nodes", maxnodes},
|
|
{"Max resource units", maxunits},
|
|
{"Type", lic.Type.Name},
|
|
{"Status", lic.Status.Name},
|
|
}
|
|
|
|
return table.Print()
|
|
}
|