func (c *Component) initKeyPair() error { priv, err := security.LoadKeypair(c.Config.KeyDir) if err != nil { return err } c.privateKey = priv pubPEM, _ := security.PublicPEM(priv) c.Identity.PublicKey = string(pubPEM) return nil }
"github.com/spf13/cobra" "github.com/spf13/viper" ) var discoveryAuthorizeCmd = &cobra.Command{ Hidden: true, Use: "authorize [router/broker/handler] [id]", Short: "Generate a token that components should use to announce themselves", Long: `ttn discovery authorize generates a token that components should use to announce themselves`, Run: func(cmd *cobra.Command, args []string) { if len(args) != 2 { cmd.UsageFunc()(cmd) return } privKey, err := security.LoadKeypair(viper.GetString("key-dir")) if err != nil { ctx.WithError(err).Fatal("Could not load security keys") } ttl, err := cmd.Flags().GetInt("valid") if err != nil { ctx.WithError(err).Fatal("Could not read TTL") } issuer, err := cmd.Flags().GetString("issuer") if err != nil { ctx.WithError(err).Fatal("Could not read issuer ID") } var claims claims.ComponentClaims