[cli] By default, update sub to high storage & expiry
This commit is contained in:
parent
0d38346722
commit
b164b0df21
3 changed files with 21 additions and 4 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/ente-io/cli/pkg/model"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _adminCmd = &cobra.Command{
|
||||
|
@ -57,6 +58,7 @@ var _updateFreeUserStorage = &cobra.Command{
|
|||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
recoverWithLog()
|
||||
var flags = &model.AdminActionForUser{}
|
||||
noLimit := false
|
||||
cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||
if f.Name == "admin-user" {
|
||||
flags.AdminEmail = f.Value.String()
|
||||
|
@ -64,8 +66,11 @@ var _updateFreeUserStorage = &cobra.Command{
|
|||
if f.Name == "user" {
|
||||
flags.UserEmail = f.Value.String()
|
||||
}
|
||||
if f.Name == "no-limit" {
|
||||
noLimit = strings.ToLower(f.Value.String()) == "true"
|
||||
}
|
||||
})
|
||||
return ctrl.UpdateFreeStorage(context.Background(), *flags)
|
||||
return ctrl.UpdateFreeStorage(context.Background(), *flags, noLimit)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -79,5 +84,7 @@ func init() {
|
|||
_disable2faCmd.Flags().StringP("user", "u", "", "The email of the user to disable 2FA for. (required)")
|
||||
_updateFreeUserStorage.Flags().StringP("admin-user", "a", "", "The email of the admin user. (required)")
|
||||
_updateFreeUserStorage.Flags().StringP("user", "u", "", "The email of the user to update subscription for. (required)")
|
||||
// add a flag with no value --no-limit
|
||||
_updateFreeUserStorage.Flags().String("no-limit", "True", "Set the storage limit to 100TB unlimited with 100 year expiry")
|
||||
_adminCmd.AddCommand(_userDetailsCmd, _disable2faCmd, _updateFreeUserStorage)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# - $ENTE_CLI_CONFIG_PATH/config.yaml
|
||||
|
||||
endpoint:
|
||||
api: "https://api.ente.io"
|
||||
api: "http://localhost:8080"
|
||||
|
||||
log:
|
||||
http: false # log http requests and responses
|
||||
http: false # log status code & time taken by requests
|
||||
|
|
|
@ -24,7 +24,7 @@ func (c *ClICtrl) GetUserId(ctx context.Context, params model.AdminActionForUser
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *ClICtrl) UpdateFreeStorage(ctx context.Context, params model.AdminActionForUser) error {
|
||||
func (c *ClICtrl) UpdateFreeStorage(ctx context.Context, params model.AdminActionForUser, noLimit bool) error {
|
||||
accountCtx, err := c.buildAdminContext(ctx, params.AdminEmail)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -33,6 +33,16 @@ func (c *ClICtrl) UpdateFreeStorage(ctx context.Context, params model.AdminActio
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if noLimit {
|
||||
// set storage to 100TB and expiry to + 100 years
|
||||
err := c.Client.UpdateFreePlanSub(accountCtx, userDetails, 100*1024*1024*1024*1024, time.Now().AddDate(100, 0, 0).UnixMicro())
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Successfully updated storage and expiry date for user")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
storageSize, err := internal.GetStorageSize("Enter a storage size (e.g.'5MB', '10GB', '2Tb'): ")
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %v", err)
|
||||
|
|
Loading…
Reference in a new issue