Skip to content

[gpctl] add users unblock command #19320

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

Merged
merged 2 commits into from
Jan 12, 2024
Merged
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
23 changes: 1 addition & 22 deletions dev/gpctl/cmd/users-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"context"

"github.com/spf13/cobra"

"github.com/gitpod-io/gitpod/common-go/log"
protocol "github.com/gitpod-io/gitpod/gitpod-protocol"
)

// usersBlockCmd represents the describe command
Expand All @@ -21,25 +18,7 @@ var usersBlockCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

client, err := newLegacyAPIConn()
if err != nil {
log.WithError(err).Fatal("cannot connect")
}
defer client.Close()

for _, uid := range args {
err = client.AdminBlockUser(ctx, &protocol.AdminBlockUserRequest{
UserID: uid,
IsBlocked: true,
})
if err != nil {
log.WithError(err).Error("cannot block user")
} else {
log.WithField("uid", uid).Info("user blocked")
}
}

blockUser(ctx, args, true)
},
}

Expand Down
27 changes: 27 additions & 0 deletions dev/gpctl/cmd/users-unblock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.

package cmd

import (
"context"

"github.com/spf13/cobra"
)

// usersUnblockCmd represents the describe command
var usersUnblockCmd = &cobra.Command{
Use: "unblock <userID> ... <userID>",
Short: "unblocks a user",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
blockUser(ctx, args, false)
},
}

func init() {
usersCmd.AddCommand(usersUnblockCmd)
}
25 changes: 25 additions & 0 deletions dev/gpctl/cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/gitpod-io/gitpod/common-go/log"
api "github.com/gitpod-io/gitpod/gitpod-protocol"
protocol "github.com/gitpod-io/gitpod/gitpod-protocol"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -56,3 +58,26 @@ func newLegacyAPIConn() (*api.APIoverJSONRPC, error) {

return conn, nil
}

func blockUser(ctx context.Context, args []string, block bool) {
client, err := newLegacyAPIConn()
if err != nil {
log.WithError(err).Fatal("cannot connect")
}
defer client.Close()

for _, uid := range args {
err = client.AdminBlockUser(ctx, &protocol.AdminBlockUserRequest{
UserID: uid,
IsBlocked: block,
})
if err != nil {
log.WithField("uid", uid).WithField("block", block).Errorf("AdminBlockUser failed with: %v", err)
return
} else {
log.WithField("uid", uid).WithField("block", block).Info("AdminBlockUser")
return
}
}
log.Fatal("no args")
}