mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-02 13:04:11 +08:00
add enrollment key to nmctl
This commit is contained in:
47
cli/cmd/enrollment_key/create.go
Normal file
47
cli/cmd/enrollment_key/create.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package enrollment_key
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gravitl/netmaker/cli/functions"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
expiration int
|
||||
usesRemaining int
|
||||
networks string
|
||||
unlimited bool
|
||||
tags string
|
||||
)
|
||||
|
||||
var enrollmentKeyCreateCmd = &cobra.Command{
|
||||
Use: "create [--args]",
|
||||
Args: cobra.NoArgs,
|
||||
Short: "Create an enrollment key",
|
||||
Long: `Create an enrollment key`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
enrollKey := &models.APIEnrollmentKey{
|
||||
Expiration: int64(expiration),
|
||||
UsesRemaining: usesRemaining,
|
||||
Unlimited: unlimited,
|
||||
}
|
||||
if networks != "" {
|
||||
enrollKey.Networks = strings.Split(networks, ",")
|
||||
}
|
||||
if tags != "" {
|
||||
enrollKey.Tags = strings.Split(tags, ",")
|
||||
}
|
||||
functions.PrettyPrint(functions.CreateEnrollmentKey(enrollKey))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
enrollmentKeyCreateCmd.Flags().IntVar(&expiration, "expiration", 0, "Expiration time of the key in UNIX timestamp format")
|
||||
enrollmentKeyCreateCmd.Flags().IntVar(&usesRemaining, "uses", 0, "Number of times this key can be used")
|
||||
enrollmentKeyCreateCmd.Flags().StringVar(&networks, "networks", "", "Comma-separated list of networks which the enrollment key can access")
|
||||
enrollmentKeyCreateCmd.Flags().BoolVar(&unlimited, "unlimited", false, "Should the key have unlimited uses ?")
|
||||
enrollmentKeyCreateCmd.Flags().StringVar(&tags, "tags", "", "Comma-separated list of any additional tags")
|
||||
rootCmd.AddCommand(enrollmentKeyCreateCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user