create.go 771 B

1234567891011121314151617181920212223242526272829303132333435
  1. package keys
  2. import (
  3. "log"
  4. "strconv"
  5. "github.com/gravitl/netmaker/cli/functions"
  6. "github.com/gravitl/netmaker/models"
  7. "github.com/spf13/cobra"
  8. )
  9. var keyName string
  10. var keysCreateCmd = &cobra.Command{
  11. Use: "create [NETWORK NAME] [NUM USES]",
  12. Args: cobra.ExactArgs(2),
  13. Short: "Create an access key",
  14. Long: `Create an access key`,
  15. Run: func(cmd *cobra.Command, args []string) {
  16. keyUses, err := strconv.ParseInt(args[1], 10, 64)
  17. if err != nil {
  18. log.Fatal(err)
  19. }
  20. key := &models.AccessKey{Uses: int(keyUses)}
  21. if keyName != "" {
  22. key.Name = keyName
  23. }
  24. functions.PrettyPrint(functions.CreateKey(args[0], key))
  25. },
  26. }
  27. func init() {
  28. keysCreateCmd.Flags().StringVar(&keyName, "name", "", "Name of the key")
  29. rootCmd.AddCommand(keysCreateCmd)
  30. }