Example #1
0
// GetAppID returns the AppID that must be set in the command options or config
func GetAppID(ctx log.Interface) string {
	appID := viper.GetString("app-id")
	if appID == "" {
		appData := readData(appFilename)
		id, ok := appData[idKey].(string)
		if !ok {
			ctx.Fatal("Invalid appID in config file.")
		}
		appID = id
	}

	if appID == "" {
		ctx.Fatal("Missing AppID. You should select an application to use with \"ttnctl applications select\"")
	}
	return appID
}
Example #2
0
func getStoredToken(ctx log.Interface) *oauth2.Token {
	tokenCache := GetTokenCache()
	data, err := tokenCache.Get(tokenName())
	if err != nil {
		ctx.WithError(err).Fatal("Could not read stored token")
	}
	if data == nil {
		ctx.Fatal("No account information found. Please login with ttnctl user login [access code]")
	}

	token := &oauth2.Token{}
	err = json.Unmarshal(data, token)
	if err != nil {
		ctx.Fatal("Account information invalid. Please login with ttnctl user login [access code]")
	}
	return token
}
Example #3
0
// GetAppEUI returns the AppEUI that must be set in the command options or config
func GetAppEUI(ctx log.Interface) types.AppEUI {
	appEUIString := viper.GetString("app-eui")
	if appEUIString == "" {
		appData := readData(appFilename)
		eui, ok := appData[euiKey].(string)
		if !ok {
			ctx.Fatal("Invalid AppEUI in config file")
		}
		appEUIString = eui
	}

	if appEUIString == "" {
		ctx.Fatal("Missing AppEUI. You should select an application to use with \"ttnctl applications select\"")
	}

	eui, err := types.ParseAppEUI(appEUIString)
	if err != nil {
		ctx.WithError(err).Fatal("Invalid AppEUI")
	}
	return eui
}