Skip to content

Commit

Permalink
Merge pull request #29 from benfdking/better_documentation
Browse files Browse the repository at this point in the history
Add better documenation and clear up
  • Loading branch information
benfdking authored Jun 8, 2020
2 parents fc9752c + b08396c commit cb7ffbc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
7 changes: 5 additions & 2 deletions cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ var defaultsCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cs := defaultjwt.GetDefaultClaims()
if explain {
w := newTabWriter()
fmt.Fprintf(w, "%s\t%s\t%s\n", "Key", "Value", "Description")
for _, c := range cs {
fmt.Printf("key: %s\tvalue: %s\tdescription: %s\n", c.Key, c.Value, c.Description)
fmt.Fprintf(w, "%s\t%s\t%s\n", c.Key, c.Value, c.Description)
}
w.Flush()
} else {
m := make(map[string]string, len(cs))
for _, c := range cs {
Expand All @@ -38,5 +41,5 @@ var defaultsCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(defaultsCmd)

defaultsCmd.Flags().BoolVarP(&explain, "explain", "e", false, "outputs a table explaining the default values")
defaultsCmd.Flags().BoolVarP(&explain, "explain", "e", false, "Explain default values")
}
6 changes: 3 additions & 3 deletions cmd/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ var jwtCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(jwtCmd)

jwtCmd.Flags().StringToStringVarP(&claims, "claims", "c", map[string]string{}, "claims to be added to the jwt")
jwtCmd.Flags().StringToStringVarP(&claims, "claims", "c", map[string]string{}, "Claims for JWT")
jwtCmd.Flags().StringVarP(&key, "key", "k", "a", "[abc] jwt key to use")
jwtCmd.Flags().BoolVarP(&addDefaults, "defaults", "d", true, "adds default oidc parameters, true by default")
jwtCmd.Flags().StringVarP(&filePath, "file", "f", "", "json file to read claims from")
jwtCmd.Flags().BoolVarP(&addDefaults, "defaults", "d", true, "Add default claims")
jwtCmd.Flags().StringVarP(&filePath, "file", "f", "", "Add claims from JSON file")
}
27 changes: 7 additions & 20 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ import (
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list [abc]",
Short: "List the default keys, optionally specifying one only returns one",
Args: func(cmd *cobra.Command, args []string) error {
switch {
case len(args) > 1:
return fmt.Errorf("can only provide no or 1 argument, not %d arguments", len(args))
case len(args) == 1:
if !url.IsVersion(args[0]) {
return fmt.Errorf("can only be one of the aviable keys: %s", url.ReturnVersions())
}
return nil
default:
return nil
}
},
Short: "List the default keys, optionally specifying one only returns one jwks url",
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
jwksURL, _, err := url.ReturnJWKSAndPrivatePEMURL(args[0])
Expand All @@ -33,22 +21,21 @@ var listCmd = &cobra.Command{
}
fmt.Println(jwksURL)
} else {
w := newTabWriter()
fmt.Fprintf(w, "%s\t%s\t%s\n", "Key", "JWKS URL", "Private PEM URL")
const alphabet = "abc"
for _, c := range alphabet {
jwksURL, _, err := url.ReturnJWKSAndPrivatePEMURL(string(c))
jwks, pem, err := url.ReturnJWKSAndPrivatePEMURL(string(c))
if err != nil {
log.Fatal(err)
}
fmt.Printf("key %c, jwks url: "+jwksURL+"\n", c)
fmt.Fprintf(w, "%s\t%s\t%s\n", string(c), jwks, pem)
}
w.Flush()
}
},
}

func init() {
rootCmd.AddCommand(listCmd)

// TODO ADD Showing pem url
//var showPemURL bool
//listCmd.Flags().BoolVarP(&showPemURL, "pem", "p", false, "Show URL For Private key")
}
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"text/tabwriter"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -31,6 +32,10 @@ func init() {
rootCmd.AddCommand(versionCmd)
}

func newTabWriter() *tabwriter.Writer {
return tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', tabwriter.TabIndent)
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(version, commit, date string) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/defaultjwt/defaultClaims.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ type DefaultClaims struct {
Description string
}

// GetDefaultClaims returns a list of default claims
//
// default claims have been taken from rfc 7519
// GetDefaultClaims returns a list of default claims. Default claims have been taken from rfc 7519
func GetDefaultClaims() []DefaultClaims {
return []DefaultClaims{
{
Expand Down

0 comments on commit cb7ffbc

Please sign in to comment.