diff --git a/cli/auth_account_command.go b/cli/auth_account_command.go index 65da22c6..e9de71eb 100644 --- a/cli/auth_account_command.go +++ b/cli/auth_account_command.go @@ -25,6 +25,7 @@ import ( "github.com/dustin/go-humanize" "github.com/fatih/color" "github.com/nats-io/nats-server/v2/server" + "github.com/nats-io/natscli/columns" ab "github.com/synadia-io/jwt-auth-builder.go" ) @@ -785,8 +786,11 @@ func (c *authAccountCommand) fShowAccount(w io.Writer, operator ab.Operator, acc func (c *authAccountCommand) showAccount(operator ab.Operator, acct ab.Account) (string, error) { limits := acct.Limits() js := limits.JetStream() + serviceExports := len(acct.Exports().Services().List()) + streamExports := len(acct.Exports().Streams().List()) cols := newColumns("Account %s (%s)", acct.Name(), acct.Subject()) + cols.AddSectionTitle("Configuration") cols.AddRow("Name", acct.Name()) cols.AddRow("Issuer", acct.Issuer()) @@ -797,6 +801,10 @@ func (c *authAccountCommand) showAccount(operator ab.Operator, acct ab.Account) cols.AddRow("JetStream", js.IsJetStreamEnabled()) cols.AddRowIf("Expiry", time.Unix(acct.Expiry(), 0), acct.Expiry() > 0) cols.AddRow("Users", len(acct.Users().List())) + cols.AddRow("Revocations", len(acct.Revocations().List())) + cols.AddRow("Service Exports", serviceExports) + cols.AddRow("Stream Exports", streamExports) + cols.AddSectionTitle("Limits") cols.AddRow("Bearer Tokens Allowed", !limits.DisallowBearerTokens()) cols.AddRowUnlimited("Subscriptions", limits.MaxSubscriptions(), -1) @@ -809,6 +817,51 @@ func (c *authAccountCommand) showAccount(operator ab.Operator, acct ab.Account) cols.AddRowUnlimited("Imports", limits.MaxImports(), -1) cols.AddRowUnlimited("Exports", limits.MaxExports(), -1) + if serviceExports > 0 || streamExports > 0 { + renderExport := func(cols *columns.Writer, export ab.Export) { + revocations := len(export.Revocations().List()) + cols.AddRowIfNotEmpty("Name", export.Name()) + cols.AddRowIfNotEmpty("Description", export.Description()) + cols.AddRowIfNotEmpty("Information", export.InfoURL()) + cols.AddRowIf("Account Token Position", export.AccountTokenPosition(), export.AccountTokenPosition() > 0) + cols.AddRowIf("Token Required", export.TokenRequired(), export.TokenRequired()) + cols.AddRowIf("Revocation", f(revocations), revocations > 0) + } + + cols.AddSectionTitle("Exports") + cols.Indent(2) + if serviceExports > 0 { + cols.AddSectionTitle("Service Exports") + for _, export := range acct.Exports().Services().List() { + cols.AddSectionTitle(export.Subject()) + cols.Indent(4) + + renderExport(cols, export) + if export.Tracing() != nil { + if export.Tracing().SamplingRate > 0 { + cols.AddRow("Tracing", fmt.Sprintf("%s sampling %d%%", export.Tracing().Subject, export.Tracing().SamplingRate)) + } else { + cols.AddRow("Tracing", export.Tracing().Subject) + } + } + cols.Indent(2) + } + } + + if streamExports > 0 { + cols.AddSectionTitle("Stream Exports") + for _, export := range acct.Exports().Streams().List() { + cols.AddSectionTitle(export.Subject()) + cols.Indent(4) + + renderExport(cols, export) + cols.Indent(2) + } + } + + cols.Indent(0) + } + if js.IsJetStreamEnabled() { cols.Indent(2) cols.AddSectionTitle("JetStream Limits") diff --git a/cli/context_command.go b/cli/context_command.go index 3a7c14e8..fe0d9da1 100644 --- a/cli/context_command.go +++ b/cli/context_command.go @@ -50,7 +50,7 @@ func configureCtxCommand(app commandHost) { context := app.Command("context", "Manage nats configuration contexts").Alias("ctx") addCheat("contexts", context) - save := context.Command("save", "Update or create a context").Alias("add").Alias("create").Action(c.createCommand) + save := context.Command("add", "Update or create a context").Alias("create").Alias("save").Action(c.createCommand) save.Arg("name", "The context name to act on").Required().StringVar(&c.name) save.Flag("description", "Set a friendly description for this context").StringVar(&c.description) save.Flag("select", "Select the saved context as the default one").UnNegatableBoolVar(&c.activate) diff --git a/go.mod b/go.mod index 158db2b1..327ffda1 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/prometheus/client_golang v1.18.0 github.com/prometheus/common v0.46.0 github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 - github.com/synadia-io/jwt-auth-builder.go v0.0.0-20240116162838-d0188a7c69ae + github.com/synadia-io/jwt-auth-builder.go v0.0.0-20240124210942-2c5fcc303e3b github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f golang.org/x/crypto v0.18.0 golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 diff --git a/go.sum b/go.sum index bcced10b..ea66b17b 100644 --- a/go.sum +++ b/go.sum @@ -112,8 +112,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/synadia-io/jwt-auth-builder.go v0.0.0-20240116162838-d0188a7c69ae h1:7WTvG7u7DgKSS5dpwzl2/vNrc8Bpgj2unGz+6F4rowc= -github.com/synadia-io/jwt-auth-builder.go v0.0.0-20240116162838-d0188a7c69ae/go.mod h1:xOFg06RDzcuXiex7madWNvDLM3GmJVCxrs0V2ncBLmU= +github.com/synadia-io/jwt-auth-builder.go v0.0.0-20240124210942-2c5fcc303e3b h1:eseL27MM2cWFOlMNEVW75RkhM4HP/j1c4FdVFGri/q8= +github.com/synadia-io/jwt-auth-builder.go v0.0.0-20240124210942-2c5fcc303e3b/go.mod h1:xOFg06RDzcuXiex7madWNvDLM3GmJVCxrs0V2ncBLmU= github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f h1:SGznmvCovewbaSgBsHgdThtWsLj5aCLX/3ZXMLd1UD0= github.com/tylertreat/hdrhistogram-writer v0.0.0-20210816161836-2e440612a39f/go.mod h1:IY84XkhrEJTdHYLNy/zObs8mXuUAp9I65VyarbPSCCY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=