ref: 79803b98b551ad1d924594263038bc901f684233 cisco/csc/cmd/admin/user/get.go -rw-r--r-- 3.3 KiB View raw
                                                                                
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package adminuser

import (
	"cisco/csc/cmd/admin"
	"cisco/sdk"
	"fmt"
	"github.com/spf13/cobra"
)

var AdminUserGetRootCmd = &cobra.Command{
	Use:   "get",
	Short: "Get an user",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		userinfo, err := cisco.GetUserInfoAdmin(args[0])
		var storage uint = 0

		if err != nil {
			fmt.Printf("Error: %s\n", err.Error())
			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)

		fmt.Printf("Quotas:\n")
		if err != nil {
			fmt.Printf("    Error: %s\n", err)
		} else {
			for _, instance := range userinfo.Instances {
				storage += instance.Size
			}

			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))
		for _, token := range userinfo.Tokens {
			fmt.Printf("    Token created at %s:\n", token.Created)
			fmt.Printf("        Key         : %s\n", token.Key)
			fmt.Printf("        Secret      : %s\n", token.Secret)
			fmt.Printf("        Description : %s\n", token.Description)
		}

		fmt.Printf("Instances (%d):\n", len(userinfo.Instances))
		for _, instance := range userinfo.Instances {
			fmt.Printf("    %s:\n", instance.Uuid)
			fmt.Printf("        Name         : %s\n", instance.Name)
			fmt.Printf("        Size         : %dGB\n", instance.Size)
			fmt.Printf("        OS           : %s\n", instance.OS)
			fmt.Printf("        Type         : %s\n", instance.Type)
			fmt.Printf("        Created      : %s\n", instance.Created)
		}

		fmt.Printf("SSH Keys (%d):\n", len(userinfo.Keys))
		for _, key := range userinfo.Keys {
			fmt.Printf("    Key %s:\n", key.Fingerprint)
			fmt.Printf("        Created : %s\n", key.Created)
			fmt.Printf("        Key     : %s\n", key.Key)
		}

		fmt.Printf("IPv4s (%d):\n", len(userinfo.Ipv4s))
		for _, ipv4 := range userinfo.Ipv4s {
			fmt.Printf("    IP created %s at:\n", ipv4.Created)
			fmt.Printf("        IP       : %s\n", ipv4.IP)
			fmt.Printf("        Instance : %s\n", ipv4.Instance)
		}

		fmt.Printf("Invites (%d):\n", len(userinfo.Invites))
		for _, invite := range userinfo.Invites {
			fmt.Printf("    Invite created at %s:\n", invite.Created)
			fmt.Printf("        Email   : %s\n", invite.Email)
			fmt.Printf("        Claimed : %t\n", invite.Claimed)
		}
	},
}

func init() {
	admin.AdminUserRootCmd.AddCommand(AdminUserGetRootCmd)
}