1e080e371c0d283c335a163550171bc1eff736ad — Louis Solofrizzo a month ago 2a41fb6
csc: Fix infite quota display on admin user get

Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>
1 files changed, 27 insertions(+), 6 deletions(-)

M csc/cmd/admin/user/get.go
M csc/cmd/admin/user/get.go => csc/cmd/admin/user/get.go +27 -6
@@ 20,13 20,14 @@ return
  		}
  
+ 		quota, err := cisco.GetQuota(userinfo.User.Role)
+ 
  		fmt.Printf("User Infos:\n")
  		fmt.Printf("    Username   : %s\n", userinfo.User.Username)
  		fmt.Printf("    Email      : %s\n", userinfo.User.Email)
  		fmt.Printf("    Role       : %s\n", userinfo.User.Role)
  		fmt.Printf("    Created at : %s\n", userinfo.User.Created)
  
- 		quota, err := cisco.GetQuota(userinfo.User.Role)
  		fmt.Printf("Quotas:\n")
  		if err != nil {
  			fmt.Printf("    Error: %s\n", err)


@@ 34,10 35,30 @@ for _, instance := range userinfo.Instances {
  				storage += instance.Size
  			}
- 			fmt.Printf("    Instances : (%d/%d)\n", len(userinfo.Instances), quota.Instances)
- 			fmt.Printf("    IPV4      : (%d/%d)\n", len(userinfo.Ipv4s), quota.Ipv4)
- 			fmt.Printf("    Storage   : (%d/%d)\n", storage, quota.Storage)
- 			fmt.Printf("    Invites   : (%d/%d)\n", len(userinfo.Invites), quota.Invites)
+ 
+ 			if quota.Instances == -1 {
+ 				fmt.Printf("    Instances : %d / Infinite\n", len(userinfo.Instances))
+ 			} else {
+ 				fmt.Printf("    Instances : %d / %d\n", len(userinfo.Instances), quota.Instances)
+ 			}
+ 
+ 			if quota.Ipv4 == -1 {
+ 				fmt.Printf("    IPV4      : %d / Infinite\n", len(userinfo.Ipv4s))
+ 			} else {
+ 				fmt.Printf("    IPV4      : %d / %d\n", len(userinfo.Ipv4s), quota.Ipv4)
+ 			}
+ 
+ 			if quota.Storage == -1 {
+ 				fmt.Printf("    Storage   : %d / Infinite\n", storage)
+ 			} else {
+ 				fmt.Printf("    Storage   : %d / %dGb\n", storage, quota.Storage)
+ 			}
+ 
+ 			if quota.Invites == -1 {
+ 				fmt.Printf("    Invites   : %d / Infinite\n", len(userinfo.Invites))
+ 			} else {
+ 				fmt.Printf("    Invites   : %d / %d\n", len(userinfo.Invites), quota.Invites)
+ 			}
  		}
  
  		fmt.Printf("Tokens (%d):\n", len(userinfo.Tokens))


@@ 52,7 73,7 @@ for _, instance := range userinfo.Instances {
  			fmt.Printf("    %s:\n", instance.Uuid)
  			fmt.Printf("        Name         : %s\n", instance.Name)
- 			fmt.Printf("        Size         : %d\n", instance.Size)
+ 			fmt.Printf("        Size         : %dGb\n", instance.Size)
  			fmt.Printf("        OS           : %s\n", instance.OS)
  			fmt.Printf("        Architecture : %s\n", instance.Architecture)
  			fmt.Printf("        Type         : %s\n", instance.Type)