-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add detele/list stack user access roles
- Loading branch information
David Ragot
committed
Dec 18, 2023
1 parent
a3e1043
commit 70a83b2
Showing
8 changed files
with
202 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
components/fctl/cmd/cloud/organizations/stacks/upsert_stack_access_roles.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package roles | ||
|
||
import ( | ||
"github.com/formancehq/fctl/membershipclient" | ||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DeletedUserAccessStore struct { | ||
Stack *membershipclient.Stack `json:"stack"` | ||
Status string `json:"status"` | ||
} | ||
type StackDeleteController struct { | ||
store *DeletedUserAccessStore | ||
} | ||
|
||
var _ fctl.Controller[*DeletedUserAccessStore] = (*StackDeleteController)(nil) | ||
|
||
func NewDefaultDeletedUserAccessStore() *DeletedUserAccessStore { | ||
return &DeletedUserAccessStore{ | ||
Stack: &membershipclient.Stack{}, | ||
Status: "", | ||
} | ||
} | ||
|
||
func NewStackDeleteController() *StackDeleteController { | ||
return &StackDeleteController{ | ||
store: NewDefaultDeletedUserAccessStore(), | ||
} | ||
} | ||
|
||
func NewDeleteCommand() *cobra.Command { | ||
const ( | ||
stackNameFlag = "name" | ||
) | ||
return fctl.NewMembershipCommand("delete <stack-id> <user-id>", | ||
fctl.WithConfirmFlag(), | ||
fctl.WithShortDescription("Delete user access from a stack within an organization"), | ||
fctl.WithAliases("del", "d"), | ||
fctl.WithArgs(cobra.ExactArgs(2)), | ||
fctl.WithController[*DeletedUserAccessStore](NewStackDeleteController()), | ||
) | ||
} | ||
func (c *StackDeleteController) GetStore() *DeletedUserAccessStore { | ||
return c.store | ||
} | ||
|
||
func (c *StackDeleteController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) { | ||
cfg, err := fctl.GetConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiClient, err := fctl.NewMembershipClient(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := apiClient.DefaultApi.DeleteStackUserAccess(cmd.Context(), organizationID, args[0], args[1]).Execute() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.StatusCode > 300 { | ||
return nil, err | ||
} | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *StackDeleteController) Render(cmd *cobra.Command, args []string) error { | ||
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Stack user access deleted.") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...tl/cmd/cloud/organizations/stacks/root.go → components/fctl/cmd/stack/roles/root.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
package stacks | ||
package roles | ||
|
||
import ( | ||
fctl "github.com/formancehq/fctl/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
return fctl.NewMembershipCommand("stacks", | ||
return fctl.NewMembershipCommand("roles", | ||
fctl.WithAliases("s"), | ||
fctl.WithShortDescription("Stack users management within an organization"), | ||
fctl.WithChildCommands( | ||
NewUpsertStackAccessRolesCommand(), | ||
NewListStackAccessRolesCommand(), | ||
NewUpsertCommand(), | ||
NewListCommand(), | ||
NewDeleteCommand(), | ||
), | ||
) | ||
} |
Oops, something went wrong.