Skip to content

Commit

Permalink
Render account exports
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Jan 26, 2024
1 parent fed0fa4 commit d9b7a2d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
53 changes: 53 additions & 0 deletions cli/auth_account_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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))

Check failure on line 842 in cli/auth_account_command.go

View workflow job for this annotation

GitHub Actions / test (1.20)

fmt.Sprintf format % is missing verb at end of string

Check failure on line 842 in cli/auth_account_command.go

View workflow job for this annotation

GitHub Actions / test (1.21)

fmt.Sprintf format % is missing verb at end of string

Check failure on line 842 in cli/auth_account_command.go

View workflow job for this annotation

GitHub Actions / test (1.20)

fmt.Sprintf format % is missing verb at end of string

Check failure on line 842 in cli/auth_account_command.go

View workflow job for this annotation

GitHub Actions / test (1.21)

fmt.Sprintf format % is missing verb at end of string
} 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")
Expand Down
2 changes: 1 addition & 1 deletion cli/context_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit d9b7a2d

Please sign in to comment.