diff --git a/cmd/yggctl/actions.go b/cmd/yggctl/actions.go index ab95ae6f..42136e2b 100644 --- a/cmd/yggctl/actions.go +++ b/cmd/yggctl/actions.go @@ -173,6 +173,32 @@ func messageJournalAction(ctx *cli.Context) error { return nil } +// clientIDAction connects to the Yggdrasil1 dbus interface +// and attempts to retrieve the active yggd client id +// and display the client id to stdout. +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 active client id from the Yggdrasil1 dbus interface: %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..ee0eaff4 100644 --- a/cmd/yggctl/main.go +++ b/cmd/yggctl/main.go @@ -30,6 +30,16 @@ 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..38ad9f97 100644 --- a/cmd/yggd/client.go +++ b/cmd/yggd/client.go @@ -201,6 +201,10 @@ 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. --> + + + + +