mirror of
https://github.com/photoprism/photoprism.git
synced 2025-09-26 21:01:58 +08:00
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
reg "github.com/photoprism/photoprism/internal/service/cluster/registry"
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
|
"github.com/photoprism/photoprism/pkg/txt/report"
|
|
)
|
|
|
|
// ClusterNodesShowCommand shows node details.
|
|
var ClusterNodesShowCommand = &cli.Command{
|
|
Name: "show",
|
|
Usage: "Shows node details (Portal-only)",
|
|
ArgsUsage: "<id|name>",
|
|
Flags: append(report.CliFlags, JsonFlag),
|
|
Action: clusterNodesShowAction,
|
|
}
|
|
|
|
func clusterNodesShowAction(ctx *cli.Context) error {
|
|
return CallWithDependencies(ctx, func(conf *config.Config) error {
|
|
if !conf.IsPortal() {
|
|
return cli.Exit(fmt.Errorf("node show is only available on a Portal node"), 2)
|
|
}
|
|
|
|
key := ctx.Args().First()
|
|
if key == "" {
|
|
return cli.Exit(fmt.Errorf("node id or name is required"), 2)
|
|
}
|
|
|
|
r, err := reg.NewFileRegistry(conf)
|
|
if err != nil {
|
|
return cli.Exit(err, 1)
|
|
}
|
|
|
|
// Resolve by id first, then by normalized name.
|
|
n, getErr := r.Get(key)
|
|
if getErr != nil {
|
|
name := clean.TypeLowerDash(key)
|
|
if name == "" {
|
|
return cli.Exit(fmt.Errorf("invalid node identifier"), 2)
|
|
}
|
|
n, getErr = r.FindByName(name)
|
|
}
|
|
if getErr != nil || n == nil {
|
|
return cli.Exit(fmt.Errorf("node not found"), 3)
|
|
}
|
|
|
|
opts := reg.NodeOpts{IncludeInternalURL: true, IncludeDBMeta: true}
|
|
dto := reg.BuildClusterNode(*n, opts)
|
|
|
|
if ctx.Bool("json") {
|
|
b, _ := json.Marshal(dto)
|
|
fmt.Println(string(b))
|
|
return nil
|
|
}
|
|
|
|
cols := []string{"ID", "Name", "Type", "Internal URL", "DB Name", "DB User", "DB Last Rotated", "Created At", "Updated At"}
|
|
var dbName, dbUser, dbRot string
|
|
if dto.DB != nil {
|
|
dbName, dbUser, dbRot = dto.DB.Name, dto.DB.User, dto.DB.DBLastRotatedAt
|
|
}
|
|
rows := [][]string{{dto.ID, dto.Name, dto.Type, dto.InternalURL, dbName, dbUser, dbRot, dto.CreatedAt, dto.UpdatedAt}}
|
|
out, err := report.RenderFormat(rows, cols, report.CliFormat(ctx))
|
|
fmt.Printf("\n%s\n", out)
|
|
if err != nil {
|
|
return cli.Exit(err, 1)
|
|
}
|
|
return nil
|
|
})
|
|
}
|