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 <[email protected]>
  • Loading branch information
DuckBoss committed Nov 11, 2024
1 parent 59ca7c8 commit 90b7818
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/yggctl/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
propertyName := "com.redhat.Yggdrasil1.ClientID"
result, err := obj.GetProperty(propertyName)
if err != nil {
return fmt.Errorf(
"cannot get property 'com.redhat.Yggdrasil1.ClientID': %v", err)
}
clientID, ok := result.Value().(map[string]string)
if !ok {
return cli.Exit(fmt.Errorf("cannot convert %T to map[string]string", result.Value()), 1)
}

fmt.Println(clientID)

return nil
}

func workersAction(c *cli.Context) error {
conn, err := connectBus()
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions cmd/yggctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
4 changes: 4 additions & 0 deletions cmd/yggd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions data/dbus/yggd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<!-- Only members of the @worker_user@ group can send messages to
Dispatcher1 destination. -->
<allow send_destination="com.redhat.Yggdrasil1.Dispatcher1" />

<!-- Only @worker_user@ can send messages to the Properties interface. -->
<allow send_destination="com.redhat.Yggdrasil1"
send_interface="org.freedesktop.DBus.Properties" />
</policy>

<policy context="default">
Expand Down
7 changes: 7 additions & 0 deletions dbus/com.redhat.Yggdrasil1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
programmatic interaction with the yggdrasil system service.
-->
<interface name="com.redhat.Yggdrasil1">
<!--
ClientID:
The value of the current client id on the active interface.
-->
<property name="ClientID" type="s" access="read" />

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

0 comments on commit 90b7818

Please sign in to comment.