Skip to content

[gpctl] Add users block command #16715

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 1 commit into from
Mar 10, 2023
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
2 changes: 2 additions & 0 deletions dev/gpctl/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages:
deps:
- components/common-go:lib
- components/content-service-api/go:lib
- components/gitpod-protocol/go:lib
- components/image-builder-api/go:lib
- components/registry-facade-api/go:lib
- components/ws-daemon-api/go:lib
Expand All @@ -25,6 +26,7 @@ packages:
deps:
- components/common-go:lib
- components/content-service-api/go:lib
- components/gitpod-protocol/go:lib
- components/image-builder-api/go:lib
- components/registry-facade-api/go:lib
- components/ws-daemon-api/go:lib
Expand Down
48 changes: 48 additions & 0 deletions dev/gpctl/cmd/users-block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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"

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

// usersBlockCmd represents the describe command
var usersBlockCmd = &cobra.Command{
Use: "block <userID> ... <userID>",
Short: "blocks a user",
Args: cobra.MinimumNArgs(1),
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")
}
}

},
}

func init() {
usersCmd.AddCommand(usersBlockCmd)
}
58 changes: 58 additions & 0 deletions dev/gpctl/cmd/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2022 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 (
"fmt"
"os"

"github.com/gitpod-io/gitpod/common-go/log"
api "github.com/gitpod-io/gitpod/gitpod-protocol"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var usersCmd = &cobra.Command{
Use: "users",
Short: "Interact with Public API services",
}

var usersCmdOpts struct {
address string
insecure bool
token string
}

func init() {
rootCmd.AddCommand(usersCmd)

usersCmd.PersistentFlags().StringVar(&usersCmdOpts.address, "address", "wss://gitpod.io/api/v1", "Address of the API endpoint. Must be in the form <host>:<port>.")
usersCmd.PersistentFlags().BoolVar(&usersCmdOpts.insecure, "insecure", false, "Disable TLS when making requests against the API. For testing purposes only.")
usersCmd.PersistentFlags().StringVar(&usersCmdOpts.token, "token", os.Getenv("GPCTL_API_TOKEN"), "Authentication token to interact with the API")
}

func newLegacyAPIConn() (*api.APIoverJSONRPC, error) {
if usersCmdOpts.address == "" {
return nil, fmt.Errorf("empty connection address")
}

if usersCmdOpts.token == "" {
return nil, fmt.Errorf("empty connection token. Use --token or GPCTL_API_TOKEN to provide one.")
}

conn, err := api.ConnectToServer(usersCmdOpts.address, api.ConnectToServerOpts{
Token: usersCmdOpts.token,
Log: logrus.NewEntry(log.Log.Logger),
ExtraHeaders: map[string]string{
"User-Agent": "gitpod/gpctl",
"X-Client-Version": "0",
},
})
if err != nil {
return nil, fmt.Errorf("cannot connect to server at %s: %w", usersCmdOpts.address, err)
}

return conn, nil
}
14 changes: 12 additions & 2 deletions dev/gpctl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ require (
k8s.io/client-go v0.24.4
)

require github.com/gitpod-io/gitpod/gitpod-protocol v0.0.0-00010101000000-000000000000

require (
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
Expand All @@ -42,10 +45,12 @@ require (
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
Expand All @@ -68,6 +73,7 @@ require (
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/net v0.5.0 // indirect
Expand All @@ -93,11 +99,13 @@ require (

replace github.com/gitpod-io/gitpod/common-go => ../../components/common-go // leeway

replace github.com/gitpod-io/gitpod/components/public-api/go => ../../components/public-api/go // leeway

replace github.com/gitpod-io/gitpod/content-service/api => ../../components/content-service-api/go // leeway

replace github.com/gitpod-io/gitpod/image-builder/api => ../../components/image-builder-api/go // leeway
replace github.com/gitpod-io/gitpod/gitpod-protocol => ../../components/gitpod-protocol/go // leeway

replace github.com/gitpod-io/gitpod/components/public-api/go => ../../components/public-api/go // leeway
replace github.com/gitpod-io/gitpod/image-builder/api => ../../components/image-builder-api/go // leeway

replace github.com/gitpod-io/gitpod/registry-facade/api => ../../components/registry-facade-api/go // leeway

Expand All @@ -107,6 +115,8 @@ replace github.com/gitpod-io/gitpod/ws-manager-bridge/api => ../../components/ws

replace github.com/gitpod-io/gitpod/ws-manager/api => ../../components/ws-manager-api/go // leeway

replace github.com/google/addlicense => ../addlicense // leeway

replace k8s.io/api => k8s.io/api v0.24.4 // leeway indirect from components/common-go:lib

replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.24.4 // leeway indirect from components/common-go:lib
Expand Down
10 changes: 10 additions & 0 deletions dev/gpctl/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.