Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
add genkeypair command (#21)
Browse files Browse the repository at this point in the history
* add genkeypair command
  • Loading branch information
rajatjindal authored Feb 15, 2018
1 parent e54c72f commit 6a9ebc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions cmd/genKeypair.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"fmt"
"github.com/golang/glog"
"github.com/proofpoint/kubernetes-ldap/token"
"github.com/spf13/cobra"
"os"
)

// genKeypairCmd represents the genKeypair command
var genKeypairCmd = &cobra.Command{
Use: "gen-keypair",
Short: "generate a new keypair for signing/verifying the token",
Run: func(cmd *cobra.Command, args []string) {
os.MkdirAll(keypairDir, 0700)

if err := token.GenerateKeypair(keypairDir); err != nil {
glog.Fatalf("Error generating key pair: %v", err)
}
fmt.Printf("Generated keypair in %s\n", keypairDir)
},
}

func init() {
RootCmd.AddCommand(genKeypairCmd)
}
5 changes: 3 additions & 2 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func init() {
"",
"config file (default is $HOME/.kubernetes-ldap.yaml)")

RootCmd.PersistentFlags().StringVar(&keypairDir, "keypair-dir", "keypair", "directory that contains keypair for signing/verifying tokens.")

RootCmd.Flags().StringVar(&ldapHost, "ldap-host", "", "(Required Host or IP of the LDAP server )")
RootCmd.Flags().UintVar(&ldapPort, "ldap-port", 389, "LDAP server port")

Expand All @@ -109,8 +111,7 @@ func init() {
RootCmd.Flags().BoolVar(&ldapUseInsecure, "use-insecure", false, "Disable LDAP TLS")

RootCmd.Flags().DurationVar(&tokenTtl, "token-ttl", 24*time.Hour, "TTL for the token")
RootCmd.Flags().StringVar(&keypairDir, "keypair-dir", "keypair", "directory that contains keypair for signing/verifying tokens. Defaults to 'keypair'")
RootCmd.Flags().BoolVar(&genKeypair, "gen-keypair", false, "generate new keypair")
RootCmd.Flags().BoolVar(&genKeypair, "gen-keypair", false, "generate new keypair while starting server")

viper.BindPFlags(RootCmd.Flags())
flag.CommandLine.Parse([]string{})
Expand Down

0 comments on commit 6a9ebc7

Please sign in to comment.