Skip to content
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
36 changes: 28 additions & 8 deletions cmd/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"connectrpc.com/connect"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/frontier/pkg/file"
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
Expand Down Expand Up @@ -100,7 +99,7 @@ func createGroupCommand(cliConfig *Config) *cli.Command {
}

func editGroupCommand(cliConfig *Config) *cli.Command {
var filePath string
var filePath, header string

cmd := &cli.Command{
Use: "edit",
Expand Down Expand Up @@ -132,10 +131,14 @@ func editGroupCommand(cliConfig *Config) *cli.Command {
}

groupID := args[0]
_, err = client.UpdateGroup(cmd.Context(), connect.NewRequest(&frontierv1beta1.UpdateGroupRequest{
req, err := newRequest(&frontierv1beta1.UpdateGroupRequest{
Id: groupID,
Body: &reqBody,
}))
}, header)
if err != nil {
return err
}
_, err = client.UpdateGroup(cmd.Context(), req)
if err != nil {
return err
}
Expand All @@ -148,12 +151,15 @@ func editGroupCommand(cliConfig *Config) *cli.Command {

cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the group body file")
cmd.MarkFlagRequired("file")
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}

func viewGroupCommand(cliConfig *Config) *cli.Command {
var metadata bool
var header string

cmd := &cli.Command{
Use: "view",
Expand All @@ -176,10 +182,14 @@ func viewGroupCommand(cliConfig *Config) *cli.Command {

orgID := args[0]
groupID := args[1]
res, err := client.GetGroup(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetGroupRequest{
req, err := newRequest(&frontierv1beta1.GetGroupRequest{
Id: groupID,
OrgId: orgID,
}))
}, header)
if err != nil {
return err
}
res, err := client.GetGroup(cmd.Context(), req)
if err != nil {
return err
}
Expand Down Expand Up @@ -220,11 +230,14 @@ func viewGroupCommand(cliConfig *Config) *cli.Command {
}

cmd.Flags().BoolVarP(&metadata, "metadata", "m", false, "Set this flag to see metadata")
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}

func listGroupCommand(cliConfig *Config) *cli.Command {
var header string
cmd := &cli.Command{
Use: "list",
Short: "List all groups",
Expand All @@ -244,9 +257,13 @@ func listGroupCommand(cliConfig *Config) *cli.Command {
return err
}

res, err := client.ListOrganizationGroups(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationGroupsRequest{
req, err := newRequest(&frontierv1beta1.ListOrganizationGroupsRequest{
OrgId: args[0],
}))
}, header)
if err != nil {
return err
}
res, err := client.ListOrganizationGroups(cmd.Context(), req)
if err != nil {
return err
}
Expand Down Expand Up @@ -277,5 +294,8 @@ func listGroupCommand(cliConfig *Config) *cli.Command {
},
}

cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}
2 changes: 1 addition & 1 deletion cmd/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestClientGroup(t *testing.T) {
name: "`group` edit with host flag should throw error missing required flag",
want: "",
subCommands: []string{"edit", "123", "-h", "test"},
err: errors.New("required flag(s) \"file\" not set"),
err: errors.New("required flag(s) \"file\", \"header\" not set"),
},
{
name: "`group` view without host should throw error host not found",
Expand Down
23 changes: 19 additions & 4 deletions cmd/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"connectrpc.com/connect"
"github.com/MakeNowJust/heredoc"
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
"github.com/raystack/salt/cli/printer"
Expand Down Expand Up @@ -38,6 +37,7 @@ func NamespaceCommand(cliConfig *Config) *cli.Command {
}

func viewNamespaceCommand(cliConfig *Config) *cli.Command {
var header string
cmd := &cli.Command{
Use: "view",
Short: "View a namespace",
Expand All @@ -58,9 +58,13 @@ func viewNamespaceCommand(cliConfig *Config) *cli.Command {
}

namespaceID := args[0]
res, err := client.GetNamespace(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetNamespaceRequest{
req, err := newRequest(&frontierv1beta1.GetNamespaceRequest{
Id: namespaceID,
}))
}, header)
if err != nil {
return err
}
res, err := client.GetNamespace(cmd.Context(), req)
if err != nil {
return err
}
Expand All @@ -84,10 +88,14 @@ func viewNamespaceCommand(cliConfig *Config) *cli.Command {
},
}

cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}

func listNamespaceCommand(cliConfig *Config) *cli.Command {
var header string
cmd := &cli.Command{
Use: "list",
Short: "List all namespaces",
Expand All @@ -107,7 +115,11 @@ func listNamespaceCommand(cliConfig *Config) *cli.Command {
return err
}

res, err := client.ListNamespaces(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListNamespacesRequest{}))
req, err := newRequest(&frontierv1beta1.ListNamespacesRequest{}, header)
if err != nil {
return err
}
res, err := client.ListNamespaces(cmd.Context(), req)
if err != nil {
return err
}
Expand All @@ -134,5 +146,8 @@ func listNamespaceCommand(cliConfig *Config) *cli.Command {
},
}

cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}
46 changes: 37 additions & 9 deletions cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"connectrpc.com/connect"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/frontier/pkg/file"
frontierv1beta1 "github.com/raystack/frontier/proto/v1beta1"
Expand Down Expand Up @@ -101,7 +100,7 @@ func createOrganizationCommand(cliConfig *Config) *cli.Command {
}

func editOrganizationCommand(cliConfig *Config) *cli.Command {
var filePath string
var filePath, header string

cmd := &cli.Command{
Use: "edit",
Expand Down Expand Up @@ -133,10 +132,14 @@ func editOrganizationCommand(cliConfig *Config) *cli.Command {
}

organizationID := args[0]
_, err = client.UpdateOrganization(cmd.Context(), connect.NewRequest(&frontierv1beta1.UpdateOrganizationRequest{
req, err := newRequest(&frontierv1beta1.UpdateOrganizationRequest{
Id: organizationID,
Body: &reqBody,
}))
}, header)
if err != nil {
return err
}
_, err = client.UpdateOrganization(cmd.Context(), req)
if err != nil {
return err
}
Expand All @@ -149,12 +152,15 @@ func editOrganizationCommand(cliConfig *Config) *cli.Command {

cmd.Flags().StringVarP(&filePath, "file", "f", "", "Path to the organization body file")
cmd.MarkFlagRequired("file")
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}

func viewOrganizationCommand(cliConfig *Config) *cli.Command {
var metadata bool
var header string

cmd := &cli.Command{
Use: "view",
Expand All @@ -176,9 +182,13 @@ func viewOrganizationCommand(cliConfig *Config) *cli.Command {
}

organizationID := args[0]
res, err := client.GetOrganization(cmd.Context(), connect.NewRequest(&frontierv1beta1.GetOrganizationRequest{
req, err := newRequest(&frontierv1beta1.GetOrganizationRequest{
Id: organizationID,
}))
}, header)
if err != nil {
return err
}
res, err := client.GetOrganization(cmd.Context(), req)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,11 +228,14 @@ func viewOrganizationCommand(cliConfig *Config) *cli.Command {
}

cmd.Flags().BoolVarP(&metadata, "metadata", "m", false, "Set this flag to see metadata")
cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}

func listOrganizationCommand(cliConfig *Config) *cli.Command {
var header string
cmd := &cli.Command{
Use: "list",
Short: "List all organizations",
Expand All @@ -242,7 +255,11 @@ func listOrganizationCommand(cliConfig *Config) *cli.Command {
return err
}

res, err := client.ListOrganizations(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationsRequest{}))
req, err := newRequest(&frontierv1beta1.ListOrganizationsRequest{}, header)
if err != nil {
return err
}
res, err := client.ListOrganizations(cmd.Context(), req)
if err != nil {
return err
}
Expand Down Expand Up @@ -272,10 +289,14 @@ func listOrganizationCommand(cliConfig *Config) *cli.Command {
},
}

cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}

func admlistOrganizationCommand(cliConfig *Config) *cli.Command {
var header string
cmd := &cli.Command{
Use: "admlist",
Short: "list admins of an organization",
Expand All @@ -296,9 +317,13 @@ func admlistOrganizationCommand(cliConfig *Config) *cli.Command {
}

organizationID := args[0]
res, err := client.ListOrganizationAdmins(cmd.Context(), connect.NewRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
req, err := newRequest(&frontierv1beta1.ListOrganizationAdminsRequest{
Id: organizationID,
}))
}, header)
if err != nil {
return err
}
res, err := client.ListOrganizationAdmins(cmd.Context(), req)
if err != nil {
return err
}
Expand All @@ -324,5 +349,8 @@ func admlistOrganizationCommand(cliConfig *Config) *cli.Command {
},
}

cmd.Flags().StringVarP(&header, "header", "H", "", "Header <key>:<value>")
cmd.MarkFlagRequired("header")

return cmd
}
2 changes: 1 addition & 1 deletion cmd/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestClientOrganization(t *testing.T) {
name: "`organization` edit with host flag should throw error missing required flag",
want: "",
subCommands: []string{"edit", "123", "-h", "test"},
err: errors.New("required flag(s) \"file\" not set"),
err: errors.New("required flag(s) \"file\", \"header\" not set"),
},
{
name: "`organization` view without host should throw error host not found",
Expand Down
Loading