Skip to content

Commit

Permalink
Added flag to edit leaf node connections (#77)
Browse files Browse the repository at this point in the history
Fixed Operator describer to display standard JWT claims, including issuer.
  • Loading branch information
aricart authored Apr 30, 2019
1 parent ef26cbb commit d27b952
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
16 changes: 12 additions & 4 deletions cmd/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func (a *AccountDescriber) Describe() string {
table.AddRow("Max Connections", "Unlimited")
}

if lim.LeafNodeConn == 0 {
table.AddRow("Max Leaf Node Connections", "Not Allowed")
} else if lim.LeafNodeConn > 0 {
table.AddRow("Max Leaf Node Connections", fmt.Sprintf("%d", lim.LeafNodeConn))
} else {
table.AddRow("Max Leaf Node Connections", "Unlimited")
}

if lim.Data > -1 {
table.AddRow("Max Data", fmt.Sprintf("%s (%d bytes)", humanize.Bytes(uint64(lim.Data)), lim.Data))
} else {
Expand Down Expand Up @@ -246,6 +254,9 @@ func AddStandardClaimInfo(table *tablewriter.Table, claims jwt.Claims) {
issuer = uc.IssuerAccount
}
}
if _, ok := claims.(*jwt.OperatorClaims); ok {
label = "Operator ID"
}

cd := claims.Claims()
if cd.Name != "" {
Expand Down Expand Up @@ -436,10 +447,7 @@ func (o *OperatorDescriber) Describe() string {
table := tablewriter.CreateTable()
table.UTF8Box()
table.AddTitle("Operator Details")
table.AddRow("Name", o.Name)
table.AddRow("Operator ID", ShortCodes(o.Subject))
table.AddRow("Issued", RenderDate(o.IssuedAt))
table.AddRow("Expires", RenderDate(o.Expires))
AddStandardClaimInfo(table, &o.OperatorClaims)

if len(o.Identities) > 0 {
table.AddSeparator()
Expand Down
13 changes: 12 additions & 1 deletion cmd/editaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func createEditAccount() *cobra.Command {
cmd.Flags().StringSliceVarP(&params.tags, "tag", "", nil, "add tags for user - comma separated list or option can be specified multiple times")
cmd.Flags().StringSliceVarP(&params.rmTags, "rm-tag", "", nil, "remove tag - comma separated list or option can be specified multiple times")
cmd.Flags().Int64VarP(&params.conns.NumberValue, "conns", "", -1, "set maximum active connections for the account (-1 is unlimited)")
cmd.Flags().Int64VarP(&params.leafConns.NumberValue, "leaf-conns", "", 0, "set maximum active leaf node connections for the account (-1 is unlimited)")
cmd.Flags().StringVarP(&params.data.Value, "data", "", "-1", "set maximum data in bytes for the account (-1 is unlimited)")
cmd.Flags().Int64VarP(&params.exports.NumberValue, "exports", "", -1, "set maximum number of exports for the account (-1 is unlimited)")
cmd.Flags().Int64VarP(&params.imports.NumberValue, "imports", "", -1, "set maximum number of imports for the account (-1 is unlimited)")
Expand All @@ -90,6 +91,7 @@ type EditAccountParams struct {
claim *jwt.AccountClaims
token string
conns NumberParams
leafConns NumberParams
exports NumberParams
exportsWc bool
imports NumberParams
Expand All @@ -106,7 +108,7 @@ func (p *EditAccountParams) SetDefaults(ctx ActionCtx) error {
}
p.SignerParams.SetDefaults(nkeys.PrefixByteOperator, true, ctx)

if !InteractiveFlag && ctx.NothingToDo("start", "expiry", "tag", "rm-tag", "conns", "exports", "imports", "subscriptions", "payload", "data", "wildcard-exports", "sk", "rm-sk") {
if !InteractiveFlag && ctx.NothingToDo("start", "expiry", "tag", "rm-tag", "conns", "leaf-conns", "exports", "imports", "subscriptions", "payload", "data", "wildcard-exports", "sk", "rm-sk") {
ctx.CurrentCmd().SilenceUsage = false
return fmt.Errorf("specify an edit option")
}
Expand Down Expand Up @@ -137,6 +139,10 @@ func (p *EditAccountParams) Load(ctx ActionCtx) error {
p.conns.NumberValue = p.claim.Limits.Conn
}

if !ctx.CurrentCmd().Flags().Changed("leaf-conns") {
p.leafConns.NumberValue = p.claim.Limits.LeafNodeConn
}

if !ctx.CurrentCmd().Flags().Changed("data") {
p.data.Value = fmt.Sprintf("%d", p.claim.Limits.Data)
}
Expand Down Expand Up @@ -170,6 +176,10 @@ func (p *EditAccountParams) PostInteractive(ctx ActionCtx) error {
return err
}

if err = p.leafConns.Edit("max leaf node connections (-1 unlimited)"); err != nil {
return err
}

if err = p.data.Edit("max data (-1 unlimited)"); err != nil {
return err
}
Expand Down Expand Up @@ -227,6 +237,7 @@ func (p *EditAccountParams) Run(ctx ActionCtx) error {
}

p.claim.Limits.Conn = p.conns.NumberValue
p.claim.Limits.LeafNodeConn = p.leafConns.NumberValue
p.claim.Limits.Data, err = p.data.NumberValue()
if err != nil {
return fmt.Errorf("error parsing %s: %s", "data", p.data.Value)
Expand Down
5 changes: 3 additions & 2 deletions cmd/editaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,22 @@ func Test_EditAccountLimits(t *testing.T) {

ts.AddAccount(t, "A")
_, _, err := ExecuteCmd(createEditAccount(), "--conns", "5", "--data", "10M", "--exports", "15",
"--imports", "20", "--payload", "1K", "--subscriptions", "30")
"--imports", "20", "--payload", "1K", "--subscriptions", "30", "--leaf-conns", "31")
require.NoError(t, err)

ac, err := ts.Store.ReadAccountClaim("A")
require.NoError(t, err)
require.NotNil(t, ac)
require.Equal(t, int64(5), ac.Limits.Conn)
require.Equal(t, int64(31), ac.Limits.LeafNodeConn)
require.Equal(t, int64(1000*1000*10), ac.Limits.Data)
require.Equal(t, int64(15), ac.Limits.Exports)
require.Equal(t, int64(20), ac.Limits.Imports)
require.Equal(t, int64(1000), ac.Limits.Payload)
require.Equal(t, int64(30), ac.Limits.Subs)
}

func Test_EditACcountSigningKeys(t *testing.T) {
func Test_EditAccountSigningKeys(t *testing.T) {
ts := NewTestStore(t, "edit account")
defer ts.Done(t)

Expand Down

0 comments on commit d27b952

Please sign in to comment.