cmd/satellite: Remove billing 'check-paid-tier' command
Now that the command has been run on all production satellites (US1, AP1, EU1), we should not need it again. Change-Id: I25a4ffb03a7172445d90a04ec539be36c4eb2c8e
This commit is contained in:
parent
a14bfdd51c
commit
eb11899acb
@ -5,7 +5,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -14,7 +13,6 @@ import (
|
||||
"github.com/zeebo/errs"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/private/process"
|
||||
@ -142,120 +140,6 @@ func generateStripeCustomers(ctx context.Context) (err error) {
|
||||
})
|
||||
}
|
||||
|
||||
// checkPaidTier ensures that all customers with a credit card are in the paid tier.
|
||||
func checkPaidTier(ctx context.Context) (err error) {
|
||||
usageLimitsConfig := runCfg.Console.UsageLimits
|
||||
|
||||
fmt.Println("This command will do the following:\nFor every user who has added a credit card and is not already in the paid tier:")
|
||||
fmt.Printf("Move this user to the paid tier and change their current project limits to:\n\tStorage: %s\n\tBandwidth: %s\n", usageLimitsConfig.Storage.Paid.String(), usageLimitsConfig.Bandwidth.Paid.String())
|
||||
fmt.Printf("Do you really want to run this command? (confirm with 'yes') ")
|
||||
|
||||
var confirm string
|
||||
n, err := fmt.Scanln(&confirm)
|
||||
if err != nil {
|
||||
if n != 0 {
|
||||
return err
|
||||
}
|
||||
// fmt.Scanln cannot handle empty input
|
||||
confirm = "n"
|
||||
}
|
||||
|
||||
if strings.ToLower(confirm) != "yes" {
|
||||
fmt.Println("Aborted - no users or projects have been modified")
|
||||
return nil
|
||||
}
|
||||
|
||||
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, db satellite.DB) error {
|
||||
customers := db.StripeCoinPayments().Customers()
|
||||
creditCards := payments.Accounts().CreditCards()
|
||||
users := db.Console().Users()
|
||||
projects := db.Console().Projects()
|
||||
|
||||
usersUpgraded := 0
|
||||
projectsUpgraded := 0
|
||||
failedUsers := make(map[uuid.UUID]bool)
|
||||
morePages := true
|
||||
nextOffset := int64(0)
|
||||
listingLimit := 100
|
||||
end := time.Now()
|
||||
for morePages {
|
||||
if err = ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
customersPage, err := customers.List(ctx, nextOffset, listingLimit, end)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
morePages = customersPage.Next
|
||||
nextOffset = customersPage.NextOffset
|
||||
|
||||
for _, c := range customersPage.Customers {
|
||||
user, err := users.Get(ctx, c.UserID)
|
||||
if err != nil {
|
||||
fmt.Printf("Couldn't find user in DB; skipping: %v\n", err)
|
||||
continue
|
||||
}
|
||||
if user.PaidTier {
|
||||
// already in paid tier; go to next customer
|
||||
continue
|
||||
}
|
||||
cards, err := creditCards.List(ctx, user.ID)
|
||||
if err != nil {
|
||||
fmt.Printf("Couldn't list user's credit cards in Stripe; skipping: %v\n", err)
|
||||
continue
|
||||
}
|
||||
if len(cards) == 0 {
|
||||
// no card added, so no paid tier; go to next customer
|
||||
continue
|
||||
}
|
||||
|
||||
// convert user to paid tier
|
||||
err = users.UpdatePaidTier(ctx, user.ID, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usersUpgraded++
|
||||
|
||||
// increase limits of existing projects to paid tier
|
||||
userProjects, err := projects.GetOwn(ctx, user.ID)
|
||||
if err != nil {
|
||||
failedUsers[user.ID] = true
|
||||
fmt.Printf("Error getting user's projects; skipping: %v\n", err)
|
||||
continue
|
||||
}
|
||||
for _, project := range userProjects {
|
||||
if project.StorageLimit == nil || *project.StorageLimit < usageLimitsConfig.Storage.Paid {
|
||||
project.StorageLimit = new(memory.Size)
|
||||
*project.StorageLimit = usageLimitsConfig.Storage.Paid
|
||||
}
|
||||
if project.BandwidthLimit == nil || *project.BandwidthLimit < usageLimitsConfig.Bandwidth.Paid {
|
||||
project.BandwidthLimit = new(memory.Size)
|
||||
*project.BandwidthLimit = usageLimitsConfig.Bandwidth.Paid
|
||||
}
|
||||
err = projects.Update(ctx, &project)
|
||||
if err != nil {
|
||||
failedUsers[user.ID] = true
|
||||
fmt.Printf("Error updating user's project; skipping: %v\n", err)
|
||||
continue
|
||||
}
|
||||
projectsUpgraded++
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Printf("Finished. Upgraded %d users and %d projects.\n", usersUpgraded, projectsUpgraded)
|
||||
|
||||
if len(failedUsers) > 0 {
|
||||
fmt.Println("Failed to upgrade some users' projects to paid tier:")
|
||||
for id := range failedUsers {
|
||||
fmt.Println(id.String())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func cmdApplyFreeTierCoupons(cmd *cobra.Command, args []string) (err error) {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
|
||||
|
@ -231,12 +231,6 @@ var (
|
||||
Long: "Ensures that we have a stripe customer for every satellite user.",
|
||||
RunE: cmdStripeCustomer,
|
||||
}
|
||||
checkPaidTierCmd = &cobra.Command{
|
||||
Use: "check-paid-tier",
|
||||
Short: "Ensures that all customers with a credit card are in the paid tier.",
|
||||
Long: "Ensures that all customers with a credit card are in the paid tier.",
|
||||
RunE: cmdCheckPaidTier,
|
||||
}
|
||||
consistencyCmd = &cobra.Command{
|
||||
Use: "consistency",
|
||||
Short: "Readdress DB consistency issues",
|
||||
@ -332,7 +326,6 @@ func init() {
|
||||
billingCmd.AddCommand(createCustomerInvoicesCmd)
|
||||
billingCmd.AddCommand(finalizeCustomerInvoicesCmd)
|
||||
billingCmd.AddCommand(stripeCustomerCmd)
|
||||
billingCmd.AddCommand(checkPaidTierCmd)
|
||||
consistencyCmd.AddCommand(consistencyGECleanupCmd)
|
||||
process.Bind(runCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(runMigrationCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
@ -357,7 +350,6 @@ func init() {
|
||||
process.Bind(createCustomerInvoicesCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(finalizeCustomerInvoicesCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(stripeCustomerCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(checkPaidTierCmd, &runCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
process.Bind(consistencyGECleanupCmd, &consistencyGECleanupCfg, defaults, cfgstruct.ConfDir(confDir), cfgstruct.IdentityDir(identityDir))
|
||||
|
||||
if err := consistencyGECleanupCmd.MarkFlagRequired("before"); err != nil {
|
||||
@ -759,12 +751,6 @@ func cmdStripeCustomer(cmd *cobra.Command, args []string) (err error) {
|
||||
return generateStripeCustomers(ctx)
|
||||
}
|
||||
|
||||
func cmdCheckPaidTier(cmd *cobra.Command, args []string) (err error) {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
|
||||
return checkPaidTier(ctx)
|
||||
}
|
||||
|
||||
func cmdConsistencyGECleanup(cmd *cobra.Command, args []string) error {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user