summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cli/main.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
new file mode 100644
index 0000000..5cfd5e0
--- /dev/null
+++ b/cmd/cli/main.go
@@ -0,0 +1,59 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "os"
+ "time"
+
+ "github.com/lestrrat-go/jwx/v2/jwa"
+ "github.com/lestrrat-go/jwx/v2/jwt"
+ "github.com/urfave/cli/v2"
+ "go.neonxp.dev/djson/internal/config"
+)
+
+func main() {
+ app := &cli.App{
+ Name: "djson cli tool",
+ Commands: []*cli.Command{
+ {
+ Name: "token",
+ Action: func(ctx *cli.Context) error {
+ cfg, err := config.Parse(ctx.String("config"))
+ if err != nil {
+ return err
+ }
+
+ t := jwt.New()
+ t.Set(jwt.SubjectKey, `djson`)
+ t.Set(jwt.IssuedAtKey, time.Now())
+ t.Set("allowed", []string{
+ "a/b/c",
+ "d/e/f",
+ })
+ signed, err := jwt.Sign(t, jwt.WithKey(
+ jwa.KeyAlgorithmFrom(cfg.JWT.Algorithm),
+ cfg.JWT.PrivateKey,
+ ))
+ if err != nil {
+ return err
+ }
+ fmt.Println(string(signed))
+ return nil
+ },
+ },
+ },
+ Action: cli.ShowAppHelp,
+ Flags: []cli.Flag{
+ &cli.StringFlag{
+ Name: "config",
+ Usage: "Path to config file",
+ Value: "/etc/djson/config.json",
+ },
+ },
+ }
+
+ if err := app.Run(os.Args); err != nil {
+ log.Fatal(err)
+ }
+}