Skip to content

Commit

Permalink
feat: add client-id subcommand to yggctl
Browse files Browse the repository at this point in the history
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 <jajerome@redhat.com>
  • Loading branch information
DuckBoss committed Sep 10, 2024
1 parent 59ca7c8 commit 9f973ed
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/yggctl/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions cmd/yggctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
5 changes: 5 additions & 0 deletions cmd/yggd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions dbus/com.redhat.Yggdrasil1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
programmatic interaction with the yggdrasil system service.
-->
<interface name="com.redhat.Yggdrasil1">
<!--
GetClientID:
@id: The current client id on the interface.
Returns the current client id on the interface.
-->
<method name="GetClientID">
<arg type="s" name="id" direction="out" />
</method>

<!--
Dispatch:
@directive: worker identifier for which the data is destined.
Expand Down

0 comments on commit 9f973ed

Please sign in to comment.