Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add client-id subcommand to yggctl #259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @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
Loading