-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateways_token.go
53 lines (43 loc) · 1.22 KB
/
gateways_token.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
// 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"
"strings"
"github.com/TheThingsNetwork/api"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var gatewaysTokenCmd = &cobra.Command{
Use: "token [GatewayID]",
Hidden: true,
Short: "Get the token for a gateway.",
Long: `gateways token gets a signed token for the gateway.`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 1, 1)
gatewayID := strings.ToLower(args[0])
if err := api.NotEmptyAndValidID(gatewayID, "Gateway ID"); err != nil {
ctx.Fatal(err.Error())
}
ctx = ctx.WithField("id", gatewayID)
account := util.GetAccount(ctx)
token, err := account.GetGatewayToken(gatewayID)
if err != nil {
ctx.WithError(err).Fatal("Could not get gateway token")
}
if token.AccessToken == "" {
ctx.Fatal("Gateway token was empty")
}
ctx.Info("Got gateway token")
fmt.Println()
fmt.Println(token.AccessToken)
fmt.Println()
if !token.Expiry.IsZero() {
fmt.Printf("Expires %s\n", token.Expiry)
fmt.Println()
}
},
}
func init() {
gatewaysCmd.AddCommand(gatewaysTokenCmd)
}