Skip to content

Commit

Permalink
Remove auth oper generate
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Aug 8, 2024
1 parent 0b3ab3c commit 5b90580
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 183 deletions.
2 changes: 1 addition & 1 deletion AUTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Permissions:

## Configuring NATS Server

TODO: Full resolver generate
Using `nats server generate` create a configuration file which will pre-load the important JWTs.

```
$ nats-server --config nats-server.conf
Expand Down
62 changes: 0 additions & 62 deletions cli/auth_operator_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package cli

import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
Expand All @@ -23,10 +22,7 @@ import (
"net/url"
"os"
"sort"
"text/template"

"github.com/choria-io/scaffold/forms"
"github.com/ghodss/yaml"
au "github.com/nats-io/natscli/internal/auth"
iu "github.com/nats-io/natscli/internal/util"

Expand All @@ -51,7 +47,6 @@ type authOperatorCommand struct {
pubKey string
outputFile string
encKey string
jetstream bool
tags []string
rmTags []string
}
Expand Down Expand Up @@ -88,11 +83,6 @@ func configureAuthOperatorCommand(auth commandHost) {
sel := op.Command("select", "Selects the default operator").Action(c.selectAction)
sel.Arg("name", "Operator to select").StringVar(&c.operatorName)

scaffold := op.Command("generate", "Guided creation of a Operator managed NATS Server").Alias("scaffold").Alias("gen").Action(c.generateAction)
scaffold.Arg("name", "Operator to act on").StringVar(&c.operatorName)
scaffold.Flag("output", "Location to store the configuration").Short('O').StringVar(&c.outputFile)
scaffold.Flag("jetstream", "Enables JetStream").BoolVar(&c.jetstream)

backup := op.Command("backup", "Creates a backup of an operator").Action(c.backupAction)
backup.Arg("name", "Operator to act on").Required().StringVar(&c.operatorName)
backup.Arg("output", "File to write backup to").Required().StringVar(&c.outputFile)
Expand All @@ -117,58 +107,6 @@ func configureAuthOperatorCommand(auth commandHost) {
skrm.Flag("force", "Remove without prompting").Short('f').UnNegatableBoolVar(&c.force)
}

func (c *authOperatorCommand) generateAction(_ *fisk.ParseContext) error {
_, oper, err := au.SelectOperator(c.operatorName, true, false)
if err != nil {
return err
}

var f forms.Form
err = yaml.Unmarshal(au.ResolverForm, &f)
if err != nil {
return err
}

res, err := forms.ProcessForm(f, map[string]any{
"jetstream": c.jetstream,
"operator": oper,
})
if err != nil {
return err
}

t, err := template.New("nats-server.conf").Parse(au.ResolverTemplate)
if err != nil {
return err
}

res["operator"] = oper
res["system"], _ = oper.Accounts().Get("SYSTEM")

buff := bytes.NewBuffer([]byte{})
err = t.Execute(buff, res)
if err != nil {
return err
}

fmt.Println()

if c.outputFile == "" {
fmt.Println("Generated Server Config")
fmt.Println()
fmt.Println(buff.String())
return nil
}

err = os.WriteFile(c.outputFile, buff.Bytes(), 0600)
if err != nil {
return err
}
fmt.Printf("Generated server configuration written to %s\n", c.outputFile)

return nil
}

func (c *authOperatorCommand) selectAction(_ *fisk.ParseContext) error {
_, oper, err := au.SelectOperator(c.operatorName, true, false)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/server_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type serverGenerateCmd struct {
func configureServerGenerateCommand(srv *fisk.CmdClause) {
c := &serverGenerateCmd{}

gen := srv.Command("generate", `Generate server configurations`).Hidden().Alias("gen").Action(c.generateAction)
gen := srv.Command("generate", `Generate server configurations`).Alias("gen").Action(c.generateAction)
gen.Arg("target", "Write the output to a specific location").Required().StringVar(&c.target)
gen.Flag("source", "Fetch the configuration bundle from a file or URL").StringVar(&c.source)
}
Expand Down
6 changes: 0 additions & 6 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ import (
"github.com/synadia-io/jwt-auth-builder.go/providers/nsc"
)

//go:embed resolver_form.yaml
var ResolverForm []byte

//go:embed resolver_template.txt
var ResolverTemplate string

type listWithNames interface {
Name() string
}
Expand Down
74 changes: 0 additions & 74 deletions internal/auth/resolver_form.yaml

This file was deleted.

39 changes: 0 additions & 39 deletions internal/auth/resolver_template.txt

This file was deleted.

0 comments on commit 5b90580

Please sign in to comment.