-
Notifications
You must be signed in to change notification settings - Fork 111
/
get.go
64 lines (54 loc) · 1.58 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package quota
import (
"fmt"
"github.com/rilldata/rill/cli/pkg/cmdutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/spf13/cobra"
)
func GetCmd(ch *cmdutil.Helper) *cobra.Command {
var org, email string
getCmd := &cobra.Command{
Use: "get",
Args: cobra.NoArgs,
Short: "Get quota for user or org",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
client, err := ch.Client()
if err != nil {
return err
}
if org != "" {
res, err := client.GetOrganization(ctx, &adminv1.GetOrganizationRequest{
Name: org,
})
if err != nil {
return err
}
orgQuotas := res.Organization.Quotas
fmt.Printf("Organization Name: %s\n", org)
fmt.Printf("Projects: %d\n", orgQuotas.Projects)
fmt.Printf("Deployments: %d\n", orgQuotas.Deployments)
fmt.Printf("Slots total: %d\n", orgQuotas.SlotsTotal)
fmt.Printf("Slots per deployment: %d\n", orgQuotas.SlotsPerDeployment)
fmt.Printf("Outstanding invites: %d\n", orgQuotas.OutstandingInvites)
} else if email != "" {
res, err := client.GetUser(ctx, &adminv1.GetUserRequest{
Email: email,
})
if err != nil {
return err
}
userQuotas := res.User.Quotas
fmt.Printf("User: %s\n", email)
fmt.Printf("Projects: %d\n", userQuotas.SingleuserOrgs)
} else {
return fmt.Errorf("Please set --org or --user")
}
return nil
},
}
getCmd.Flags().SortFlags = false
getCmd.Flags().StringVar(&org, "org", "", "Organization Name")
getCmd.Flags().StringVar(&email, "user", "", "User Email")
return getCmd
}