From 9f973ed0adf5595e43a1a180f890a8ba33dca807 Mon Sep 17 00:00:00 2001 From: Jason Jerome Date: Mon, 9 Sep 2024 22:41:17 -0400 Subject: [PATCH] feat: add client-id subcommand to yggctl This patch adds a 'client-id' subcommand to yggctl which retrieves and prints to stdout the active client ID of a yggd instance. This attempts to resolve issue #243 Signed-off-by: Jason Jerome --- cmd/yggctl/actions.go | 17 +++++++++++++++++ cmd/yggctl/main.go | 11 +++++++++++ cmd/yggd/client.go | 5 +++++ dbus/com.redhat.Yggdrasil1.xml | 10 ++++++++++ 4 files changed, 43 insertions(+) diff --git a/cmd/yggctl/actions.go b/cmd/yggctl/actions.go index ab95ae6f..b283f925 100644 --- a/cmd/yggctl/actions.go +++ b/cmd/yggctl/actions.go @@ -173,6 +173,23 @@ func messageJournalAction(ctx *cli.Context) error { return nil } +func clientIDAction(ctx *cli.Context) error { + conn, err := connectBus() + if err != nil { + return cli.Exit(fmt.Errorf("cannot connect to bus: %w", err), 1) + } + + obj := conn.Object("com.redhat.Yggdrasil1", "/com/redhat/Yggdrasil1") + var clientID string + if err := obj.Call("com.redhat.Yggdrasil1.GetClientID", dbus.Flags(0)).Store(&clientID); err != nil { + return cli.Exit(fmt.Errorf("cannot retrieve client id: %v", err), 1) + } + + fmt.Println(clientID) + + return nil +} + func workersAction(c *cli.Context) error { conn, err := connectBus() if err != nil { diff --git a/cmd/yggctl/main.go b/cmd/yggctl/main.go index fb582b54..ca959591 100644 --- a/cmd/yggctl/main.go +++ b/cmd/yggctl/main.go @@ -30,6 +30,17 @@ func main() { } app.Commands = []*cli.Command{ + { + + Name: "client-id", + Usage: "Retrieve the current client id", + UsageText: "yggctl client-id", + Description: `The client-id command retrieves the current client id of the yggdrasil instance`, + Aliases: []string{}, + Flags: []cli.Flag{}, + Action: clientIDAction, + + }, { Name: "generate", Usage: `Generate messages for publishing to client "in" topics`, diff --git a/cmd/yggd/client.go b/cmd/yggd/client.go index eac46ba2..4c1e0e18 100644 --- a/cmd/yggd/client.go +++ b/cmd/yggd/client.go @@ -201,6 +201,11 @@ func (c *Client) ListWorkers() (map[string]map[string]string, *dbus.Error) { return c.dispatcher.FlattenDispatchers(), nil } + +func (c *Client) GetClientID() (string, *dbus.Error) { + return config.DefaultConfig.ClientID, nil +} + // MessageJournal implements the com.redhat.Yggdrasil1.MessageJournal method. func (c *Client) MessageJournal( messageID string, diff --git a/dbus/com.redhat.Yggdrasil1.xml b/dbus/com.redhat.Yggdrasil1.xml index 85517001..a53b69fd 100644 --- a/dbus/com.redhat.Yggdrasil1.xml +++ b/dbus/com.redhat.Yggdrasil1.xml @@ -8,6 +8,16 @@ programmatic interaction with the yggdrasil system service. --> + + + + +