-
Notifications
You must be signed in to change notification settings - Fork 0
/
applications_info.go
89 lines (72 loc) · 1.9 KB
/
applications_info.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
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
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var applicationsInfoCmd = &cobra.Command{
Use: "info [AppID]",
Short: "Get information about an application",
Long: `ttnctl applications info can be used to info applications.`,
Example: `$ ttnctl applications info
INFO Found application
AppID: test
Name: Test application
EUIs:
- 0000000000000000
Access Keys:
- Name: default key
Key: FZYr01cUhdhY1KBiMghUl+/gXyqXhrF6y+1ww7+DzHg=
Rights: messages:up:r, messages:down:w
Collaborators:
- Name: yourname
Rights: settings, delete, collaborators
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 0, 1)
account := util.GetAccount(ctx)
var appID string
if len(args) == 1 {
appID = args[0]
} else {
appID = util.GetAppID(ctx)
}
app, err := account.FindApplication(appID)
if err != nil {
ctx.WithError(err).Fatal("Could not find application")
}
ctx.Info("Found application")
fmt.Println()
fmt.Printf("AppID: %s\n", app.ID)
fmt.Printf("Name: %s\n", app.Name)
fmt.Println()
fmt.Println("EUIs:")
for _, eui := range app.EUIs {
fmt.Printf(" - %s\n", eui)
}
fmt.Println()
fmt.Println("Access Keys:")
for _, key := range app.AccessKeys {
fmt.Printf(" - Name: %s\n", key.Name)
fmt.Printf(" Key: %s\n", key.Key)
fmt.Print(" Rights: ")
for i, right := range key.Rights {
if i != 0 {
fmt.Print(", ")
}
fmt.Print(right)
}
fmt.Println()
}
if len(app.Collaborators) > 0 {
fmt.Println()
fmt.Println("Collaborators:")
printCollaborators(app.Collaborators)
}
},
}
func init() {
applicationsCmd.AddCommand(applicationsInfoCmd)
}