create.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package enrollment_key
  2. import (
  3. "strings"
  4. "github.com/gravitl/netmaker/cli/functions"
  5. "github.com/gravitl/netmaker/models"
  6. "github.com/spf13/cobra"
  7. )
  8. var (
  9. expiration int
  10. usesRemaining int
  11. networks string
  12. unlimited bool
  13. tags string
  14. )
  15. var enrollmentKeyCreateCmd = &cobra.Command{
  16. Use: "create",
  17. Args: cobra.NoArgs,
  18. Short: "Create an enrollment key",
  19. Long: `Create an enrollment key`,
  20. Run: func(cmd *cobra.Command, args []string) {
  21. enrollKey := &models.APIEnrollmentKey{
  22. Expiration: int64(expiration),
  23. UsesRemaining: usesRemaining,
  24. Unlimited: unlimited,
  25. }
  26. if networks != "" {
  27. enrollKey.Networks = strings.Split(networks, ",")
  28. }
  29. if tags != "" {
  30. enrollKey.Tags = strings.Split(tags, ",")
  31. }
  32. functions.PrettyPrint(functions.CreateEnrollmentKey(enrollKey))
  33. },
  34. }
  35. func init() {
  36. enrollmentKeyCreateCmd.Flags().IntVar(&expiration, "expiration", 0, "Expiration time of the key in UNIX timestamp format")
  37. enrollmentKeyCreateCmd.Flags().IntVar(&usesRemaining, "uses", 0, "Number of times this key can be used")
  38. enrollmentKeyCreateCmd.Flags().StringVar(&networks, "networks", "", "Comma-separated list of networks which the enrollment key can access")
  39. enrollmentKeyCreateCmd.Flags().BoolVar(&unlimited, "unlimited", false, "Should the key have unlimited uses ?")
  40. enrollmentKeyCreateCmd.Flags().StringVar(&tags, "tags", "", "Comma-separated list of any additional tags")
  41. rootCmd.AddCommand(enrollmentKeyCreateCmd)
  42. }