Skip to content

Commit

Permalink
CLI: Support overriding the audience in sudo runtime (#5308)
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller authored Jul 18, 2024
1 parent 60ef776 commit e0dc200
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cli/cmd/sudo/runtime/delete_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

func DeleteInstanceCmd(ch *cmdutil.Helper) *cobra.Command {
var audience string

cmd := &cobra.Command{
Use: "delete-instance <host> <instance_id>",
Args: cobra.ExactArgs(2),
Expand All @@ -20,14 +22,17 @@ func DeleteInstanceCmd(ch *cmdutil.Helper) *cobra.Command {
// Parse args
host := args[0]
instanceID := args[1]
if audience == "" {
audience = host
}

// Obtain a manager token for the host
client, err := ch.Client()
if err != nil {
return err
}
tokenRes, err := client.SudoIssueRuntimeManagerToken(cmd.Context(), &adminv1.SudoIssueRuntimeManagerTokenRequest{
Host: host,
Host: audience,
})
if err != nil {
return err
Expand All @@ -50,5 +55,7 @@ func DeleteInstanceCmd(ch *cmdutil.Helper) *cobra.Command {
},
}

cmd.Flags().StringVar(&audience, "audience", "", "Override JWT audience if it differs from the host")

return cmd
}
7 changes: 6 additions & 1 deletion cli/cmd/sudo/runtime/list_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func ListInstancesCmd(ch *cmdutil.Helper) *cobra.Command {
var audience string
var pageSize uint32
var pageToken string

Expand All @@ -22,14 +23,17 @@ func ListInstancesCmd(ch *cmdutil.Helper) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
// Parse args
host := args[0]
if audience == "" {
audience = host
}

// Obtain a manager token for the host
client, err := ch.Client()
if err != nil {
return err
}
tokenRes, err := client.SudoIssueRuntimeManagerToken(cmd.Context(), &adminv1.SudoIssueRuntimeManagerTokenRequest{
Host: host,
Host: audience,
})
if err != nil {
return err
Expand Down Expand Up @@ -66,6 +70,7 @@ func ListInstancesCmd(ch *cmdutil.Helper) *cobra.Command {
},
}

cmd.Flags().StringVar(&audience, "audience", "", "Override JWT audience if it differs from the host")
cmd.Flags().Uint32Var(&pageSize, "page-size", 100, "Number of instances per page")
cmd.Flags().StringVar(&pageToken, "page-token", "", "Pagination token")

Expand Down

0 comments on commit e0dc200

Please sign in to comment.